Browse Source

SplitPane. Fix SplitterHandleAlignment

pull/417/head
Igor Demin 4 years ago
parent
commit
bc90bb7074
  1. 12
      components/SplitPane/common/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneDSL.kt
  2. 4
      components/SplitPane/common/src/commonMain/kotlin/org/jetbrains/compose/splitpane/Splitter.kt
  3. 8
      components/SplitPane/common/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitPane.kt

12
components/SplitPane/common/src/commonMain/kotlin/org/jetbrains/compose/splitpane/SplitPaneDSL.kt

@ -67,16 +67,16 @@ interface SplitterScope {
* Size of handle will have no effect on split pane parts (first and second) sizes.
*
* @param alignment alignment of handle according to [visiblePart] could be:
* * [SplitterHandleAlign.BEFORE] if you place handle before [visiblePart],
* * [SplitterHandleAlign.ABOVE] if you place handle above [visiblePart] (will be centered)
* * and [SplitterHandleAlign.AFTER] if you place handle after [visiblePart].
* * [SplitterHandleAlignment.BEFORE] if you place handle before [visiblePart],
* * [SplitterHandleAlignment.ABOVE] if you place handle above [visiblePart] (will be centered)
* * and [SplitterHandleAlignment.AFTER] if you place handle after [visiblePart].
*
* @param content composable item content provider. Uses [HandleScope] to allow mark any provided composable part
* as handle.
* [content] will be placed only if [SplitPaneState.moveEnabled] is true
*/
fun handle(
alignment: SplitterHandleAlign = SplitterHandleAlign.ABOVE,
alignment: SplitterHandleAlignment = SplitterHandleAlignment.ABOVE,
content: @Composable HandleScope.() -> Unit
)
}
@ -105,7 +105,7 @@ internal class SplitterScopeImpl(
}
override fun handle(
alignment: SplitterHandleAlign,
alignment: SplitterHandleAlignment,
content: @Composable HandleScope.() -> Unit
) {
containerScope.handle = { HandleScopeImpl(containerScope).content() }
@ -134,7 +134,7 @@ internal class SplitPaneScopeImpl(
internal lateinit var visiblePart: ComposableSlot
internal lateinit var handle: ComposableSlot
internal var alignment: SplitterHandleAlign = SplitterHandleAlign.ABOVE
internal var alignment: SplitterHandleAlignment = SplitterHandleAlignment.ABOVE
internal val splitter
get() =
if (this::visiblePart.isInitialized && this::handle.isInitialized) {

4
components/SplitPane/common/src/commonMain/kotlin/org/jetbrains/compose/splitpane/Splitter.kt

@ -3,7 +3,7 @@ package org.jetbrains.compose.splitpane
import androidx.compose.runtime.Composable
@ExperimentalSplitPaneApi
enum class SplitterHandleAlign {
enum class SplitterHandleAlignment {
BEFORE,
ABOVE,
AFTER
@ -13,5 +13,5 @@ enum class SplitterHandleAlign {
internal data class Splitter(
val measuredPart: @Composable () -> Unit,
val handlePart: @Composable () -> Unit = measuredPart,
val align: SplitterHandleAlign = SplitterHandleAlign.ABOVE
val alignment: SplitterHandleAlignment = SplitterHandleAlignment.ABOVE
)

8
components/SplitPane/common/src/desktopMain/kotlin/org/jetbrains/compose/splitpane/DesktopSplitPane.kt

@ -113,10 +113,10 @@ internal actual fun SplitPane(
val handlePlaceable = measurables[3].measure(constraints)
val handleSize = handlePlaceable.valueByDirection(isHorizontal)
// TODO support RTL
val handlePosition = when (splitter.align) {
SplitterHandleAlign.BEFORE -> constrainedPosition - handleSize
SplitterHandleAlign.ABOVE -> constrainedPosition + (splitterSize - handleSize) / 2
SplitterHandleAlign.AFTER -> constrainedPosition + splitterSize + handleSize
val handlePosition = when (splitter.alignment) {
SplitterHandleAlignment.BEFORE -> constrainedPosition + splitterSize - handleSize
SplitterHandleAlignment.ABOVE -> constrainedPosition + (splitterSize - handleSize) / 2
SplitterHandleAlignment.AFTER -> constrainedPosition
}
layout(constraints.maxWidth, constraints.maxHeight) {

Loading…
Cancel
Save