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. * 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: * @param alignment alignment of handle according to [visiblePart] could be:
* * [SplitterHandleAlign.BEFORE] if you place handle before [visiblePart], * * [SplitterHandleAlignment.BEFORE] if you place handle before [visiblePart],
* * [SplitterHandleAlign.ABOVE] if you place handle above [visiblePart] (will be centered) * * [SplitterHandleAlignment.ABOVE] if you place handle above [visiblePart] (will be centered)
* * and [SplitterHandleAlign.AFTER] if you place handle after [visiblePart]. * * and [SplitterHandleAlignment.AFTER] if you place handle after [visiblePart].
* *
* @param content composable item content provider. Uses [HandleScope] to allow mark any provided composable part * @param content composable item content provider. Uses [HandleScope] to allow mark any provided composable part
* as handle. * as handle.
* [content] will be placed only if [SplitPaneState.moveEnabled] is true * [content] will be placed only if [SplitPaneState.moveEnabled] is true
*/ */
fun handle( fun handle(
alignment: SplitterHandleAlign = SplitterHandleAlign.ABOVE, alignment: SplitterHandleAlignment = SplitterHandleAlignment.ABOVE,
content: @Composable HandleScope.() -> Unit content: @Composable HandleScope.() -> Unit
) )
} }
@ -105,7 +105,7 @@ internal class SplitterScopeImpl(
} }
override fun handle( override fun handle(
alignment: SplitterHandleAlign, alignment: SplitterHandleAlignment,
content: @Composable HandleScope.() -> Unit content: @Composable HandleScope.() -> Unit
) { ) {
containerScope.handle = { HandleScopeImpl(containerScope).content() } containerScope.handle = { HandleScopeImpl(containerScope).content() }
@ -134,7 +134,7 @@ internal class SplitPaneScopeImpl(
internal lateinit var visiblePart: ComposableSlot internal lateinit var visiblePart: ComposableSlot
internal lateinit var handle: ComposableSlot internal lateinit var handle: ComposableSlot
internal var alignment: SplitterHandleAlign = SplitterHandleAlign.ABOVE internal var alignment: SplitterHandleAlignment = SplitterHandleAlignment.ABOVE
internal val splitter internal val splitter
get() = get() =
if (this::visiblePart.isInitialized && this::handle.isInitialized) { 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 import androidx.compose.runtime.Composable
@ExperimentalSplitPaneApi @ExperimentalSplitPaneApi
enum class SplitterHandleAlign { enum class SplitterHandleAlignment {
BEFORE, BEFORE,
ABOVE, ABOVE,
AFTER AFTER
@ -13,5 +13,5 @@ enum class SplitterHandleAlign {
internal data class Splitter( internal data class Splitter(
val measuredPart: @Composable () -> Unit, val measuredPart: @Composable () -> Unit,
val handlePart: @Composable () -> Unit = measuredPart, 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 handlePlaceable = measurables[3].measure(constraints)
val handleSize = handlePlaceable.valueByDirection(isHorizontal) val handleSize = handlePlaceable.valueByDirection(isHorizontal)
// TODO support RTL // TODO support RTL
val handlePosition = when (splitter.align) { val handlePosition = when (splitter.alignment) {
SplitterHandleAlign.BEFORE -> constrainedPosition - handleSize SplitterHandleAlignment.BEFORE -> constrainedPosition + splitterSize - handleSize
SplitterHandleAlign.ABOVE -> constrainedPosition + (splitterSize - handleSize) / 2 SplitterHandleAlignment.ABOVE -> constrainedPosition + (splitterSize - handleSize) / 2
SplitterHandleAlign.AFTER -> constrainedPosition + splitterSize + handleSize SplitterHandleAlignment.AFTER -> constrainedPosition
} }
layout(constraints.maxWidth, constraints.maxHeight) { layout(constraints.maxWidth, constraints.maxHeight) {

Loading…
Cancel
Save