Skip to content

Commit

Permalink
split = verb, gap = noun (splitting creates a gap)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Aug 5, 2022
1 parent a2f952c commit 26d1a55
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 51 deletions.
14 changes: 7 additions & 7 deletions adaptive/api/current.api
Expand Up @@ -2,18 +2,18 @@
package com.google.accompanist.adaptive {

public final class SplitResult {
ctor public SplitResult(boolean isHorizontalSplit, androidx.compose.ui.geometry.Rect splitArea);
method public androidx.compose.ui.geometry.Rect getSplitArea();
ctor public SplitResult(boolean isHorizontalSplit, androidx.compose.ui.geometry.Rect gapBounds);
method public androidx.compose.ui.geometry.Rect getGapBounds();
method public boolean isHorizontalSplit();
property public final androidx.compose.ui.geometry.Rect gapBounds;
property public final boolean isHorizontalSplit;
property public final androidx.compose.ui.geometry.Rect splitArea;
}

public final class TwoPaneKt {
method public static com.google.accompanist.adaptive.TwoPaneStrategy FixedOffsetHorizontalTwoPaneStrategy(float splitOffset, boolean offsetFromStart, optional float splitWidth);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FixedOffsetVerticalTwoPaneStrategy(float splitOffset, boolean offsetFromTop, optional float splitHeight);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FractionHorizontalTwoPaneStrategy(float splitFraction, optional float splitWidth);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FractionVerticalTwoPaneStrategy(float splitFraction, optional float splitHeight);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FixedOffsetHorizontalTwoPaneStrategy(float splitOffset, boolean offsetFromStart, optional float gapWidth);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FixedOffsetVerticalTwoPaneStrategy(float splitOffset, boolean offsetFromTop, optional float gapHeight);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FractionHorizontalTwoPaneStrategy(float splitFraction, optional float gapWidth);
method public static com.google.accompanist.adaptive.TwoPaneStrategy FractionVerticalTwoPaneStrategy(float splitFraction, optional float gapHeight);
method public static com.google.accompanist.adaptive.TwoPaneStrategy HorizontalTwoPaneStrategy(com.google.accompanist.adaptive.TwoPaneStrategy fallbackStrategy, com.google.accompanist.adaptive.WindowGeometry windowGeometry);
method @androidx.compose.runtime.Composable public static void TwoPane(kotlin.jvm.functions.Function0<kotlin.Unit> first, kotlin.jvm.functions.Function0<kotlin.Unit> second, com.google.accompanist.adaptive.TwoPaneStrategy strategy, optional androidx.compose.ui.Modifier modifier);
method public static com.google.accompanist.adaptive.TwoPaneStrategy TwoPaneStrategy(com.google.accompanist.adaptive.TwoPaneStrategy fallbackStrategy, com.google.accompanist.adaptive.WindowGeometry windowGeometry);
Expand Down
68 changes: 34 additions & 34 deletions adaptive/src/main/java/com/google/accompanist/adaptive/TwoPane.kt
Expand Up @@ -95,32 +95,32 @@ fun TwoPane(
)

val isHorizontalSplit = splitResult.isHorizontalSplit
val splitArea = splitResult.splitArea
val gapBounds = splitResult.gapBounds

val splitLeft = constraints.constrainWidth(splitArea.left.roundToInt())
val splitRight = constraints.constrainWidth(splitArea.right.roundToInt())
val splitTop = constraints.constrainHeight(splitArea.top.roundToInt())
val splitBottom = constraints.constrainHeight(splitArea.bottom.roundToInt())
val gapLeft = constraints.constrainWidth(gapBounds.left.roundToInt())
val gapRight = constraints.constrainWidth(gapBounds.right.roundToInt())
val gapTop = constraints.constrainHeight(gapBounds.top.roundToInt())
val gapBottom = constraints.constrainHeight(gapBounds.bottom.roundToInt())
val firstConstraints =
if (isHorizontalSplit) {
val width = when (layoutDirection) {
LayoutDirection.Ltr -> splitLeft
LayoutDirection.Rtl -> constraints.maxWidth - splitRight
LayoutDirection.Ltr -> gapLeft
LayoutDirection.Rtl -> constraints.maxWidth - gapRight
}

constraints.copy(minWidth = width, maxWidth = width)
} else {
constraints.copy(minHeight = splitTop, maxHeight = splitTop)
constraints.copy(minHeight = gapTop, maxHeight = gapTop)
}
val secondConstraints =
if (isHorizontalSplit) {
val width = when (layoutDirection) {
LayoutDirection.Ltr -> constraints.maxWidth - splitRight
LayoutDirection.Rtl -> splitLeft
LayoutDirection.Ltr -> constraints.maxWidth - gapRight
LayoutDirection.Rtl -> gapLeft
}
constraints.copy(minWidth = width, maxWidth = width)
} else {
val height = constraints.maxHeight - splitBottom
val height = constraints.maxHeight - gapBottom
constraints.copy(minHeight = height, maxHeight = height)
}
val firstPlaceable = firstMeasurable.measure(constraints.constrain(firstConstraints))
Expand Down Expand Up @@ -176,13 +176,13 @@ class SplitResult(
val isHorizontalSplit: Boolean,

/**
* The area that is nether a `start` pane or an `end` pane, but a separation between those two.
* In case width or height is 0 - it means that the area itself is a 0 width/height, but the
* The bounds that are nether a `start` pane or an `end` pane, but a separation between those
* two. In case width or height is 0 - it means that the gap itself is a 0 width/height, but the
* place within the layout is still defined.
*
* The [splitArea] should be defined in local bounds to the [TwoPane].
* The [gapBounds] should be defined in local bounds to the [TwoPane].
*/
val splitArea: Rect,
val gapBounds: Rect,
)

/**
Expand Down Expand Up @@ -225,7 +225,7 @@ public fun HorizontalTwoPaneStrategy(
val foldBounds = verticalFold.bounds.toComposeRect()
SplitResult(
isHorizontalSplit = true,
splitArea = Rect(
gapBounds = Rect(
layoutCoordinates.windowToLocal(foldBounds.topLeft),
layoutCoordinates.windowToLocal(foldBounds.bottomRight)
)
Expand Down Expand Up @@ -258,7 +258,7 @@ public fun VerticalTwoPaneStrategy(
val foldBounds = horizontalFold.bounds.toComposeRect()
SplitResult(
isHorizontalSplit = false,
splitArea = Rect(
gapBounds = Rect(
layoutCoordinates.windowToLocal(foldBounds.topLeft),
layoutCoordinates.windowToLocal(foldBounds.bottomRight)
)
Expand All @@ -271,23 +271,23 @@ public fun VerticalTwoPaneStrategy(
/**
* Returns a [TwoPaneStrategy] that will place the slots horizontally.
*
* The split will be placed at the given [splitFraction] from start, with the given [splitWidth].
* The gap will be placed at the given [splitFraction] from start, with the given [gapWidth].
*
* This strategy is _not_ fold aware.
*/
public fun FractionHorizontalTwoPaneStrategy(
splitFraction: Float,
splitWidth: Dp = 0.dp,
gapWidth: Dp = 0.dp,
): TwoPaneStrategy = TwoPaneStrategy { density, layoutDirection, layoutCoordinates ->
val splitX = layoutCoordinates.size.width * when (layoutDirection) {
LayoutDirection.Ltr -> splitFraction
LayoutDirection.Rtl -> 1 - splitFraction
}
val splitWidthPixel = with(density) { splitWidth.toPx() }
val splitWidthPixel = with(density) { gapWidth.toPx() }

SplitResult(
isHorizontalSplit = true,
splitArea = Rect(
gapBounds = Rect(
left = splitX - splitWidthPixel / 2f,
top = 0f,
right = splitX + splitWidthPixel / 2f,
Expand All @@ -299,15 +299,15 @@ public fun FractionHorizontalTwoPaneStrategy(
/**
* Returns a [TwoPaneStrategy] that will place the slots horizontally.
*
* The split will be placed at [splitOffset] either from the start or end based on
* [offsetFromStart], with the given [splitWidth].
* The gap will be placed at [splitOffset] either from the start or end based on
* [offsetFromStart], with the given [gapWidth].
*
* This strategy is _not_ fold aware.
*/
public fun FixedOffsetHorizontalTwoPaneStrategy(
splitOffset: Dp,
offsetFromStart: Boolean,
splitWidth: Dp = 0.dp,
gapWidth: Dp = 0.dp,
): TwoPaneStrategy = TwoPaneStrategy { density, layoutDirection, layoutCoordinates ->
val splitOffsetPixel = with(density) { splitOffset.toPx() }
val splitX = when (layoutDirection) {
Expand All @@ -324,11 +324,11 @@ public fun FixedOffsetHorizontalTwoPaneStrategy(
splitOffsetPixel
}
}
val splitWidthPixel = with(density) { splitWidth.toPx() }
val splitWidthPixel = with(density) { gapWidth.toPx() }

SplitResult(
isHorizontalSplit = true,
splitArea = Rect(
gapBounds = Rect(
left = splitX - splitWidthPixel / 2f,
top = 0f,
right = splitX + splitWidthPixel / 2f,
Expand All @@ -340,20 +340,20 @@ public fun FixedOffsetHorizontalTwoPaneStrategy(
/**
* Returns a [TwoPaneStrategy] that will place the slots horizontally.
*
* The split will be placed at the given [splitFraction] from start, with the given [splitHeight].
* The split will be placed at the given [splitFraction] from start, with the given [gapHeight].
*
* This strategy is _not_ fold aware.
*/
public fun FractionVerticalTwoPaneStrategy(
splitFraction: Float,
splitHeight: Dp = 0.dp,
gapHeight: Dp = 0.dp,
): TwoPaneStrategy = TwoPaneStrategy { density, _, layoutCoordinates ->
val splitY = layoutCoordinates.size.height * splitFraction
val splitHeightPixel = with(density) { splitHeight.toPx() }
val splitHeightPixel = with(density) { gapHeight.toPx() }

SplitResult(
isHorizontalSplit = false,
splitArea = Rect(
gapBounds = Rect(
left = 0f,
top = splitY - splitHeightPixel / 2f,
right = layoutCoordinates.size.width.toFloat(),
Expand All @@ -366,14 +366,14 @@ public fun FractionVerticalTwoPaneStrategy(
* Returns a [TwoPaneStrategy] that will place the slots horizontally.
*
* The split will be placed at [splitOffset] either from the top or bottom based on
* [offsetFromTop], with the given [splitHeight].
* [offsetFromTop], with the given [gapHeight].
*
* This strategy is _not_ fold aware.
*/
public fun FixedOffsetVerticalTwoPaneStrategy(
splitOffset: Dp,
offsetFromTop: Boolean,
splitHeight: Dp = 0.dp,
gapHeight: Dp = 0.dp,
): TwoPaneStrategy = TwoPaneStrategy { density, _, layoutCoordinates ->
val splitOffsetPixel = with(density) { splitOffset.toPx() }
val splitY =
Expand All @@ -382,11 +382,11 @@ public fun FixedOffsetVerticalTwoPaneStrategy(
} else {
layoutCoordinates.size.height - splitOffsetPixel
}
val splitHeightPixel = with(density) { splitHeight.toPx() }
val splitHeightPixel = with(density) { gapHeight.toPx() }

SplitResult(
isHorizontalSplit = false,
splitArea = Rect(
gapBounds = Rect(
left = 0f,
top = splitY - splitHeightPixel / 2f,
right = layoutCoordinates.size.width.toFloat(),
Expand Down
Expand Up @@ -23,9 +23,6 @@ import androidx.compose.foundation.layout.requiredSize
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
import androidx.compose.material3.windowsizeclass.WindowSizeClass
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
Expand Down Expand Up @@ -214,7 +211,7 @@ class TwoPaneTest {
},
strategy = FractionHorizontalTwoPaneStrategy(
splitFraction = 1f / 3f,
splitWidth = 64.dp
gapWidth = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -275,7 +272,7 @@ class TwoPaneTest {
},
strategy = FractionHorizontalTwoPaneStrategy(
splitFraction = 1f / 3f,
splitWidth = 64.dp
gapWidth = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -393,7 +390,7 @@ class TwoPaneTest {
},
strategy = FractionVerticalTwoPaneStrategy(
splitFraction = 1f / 3f,
splitHeight = 64.dp
gapHeight = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -576,7 +573,7 @@ class TwoPaneTest {
strategy = FixedOffsetHorizontalTwoPaneStrategy(
splitOffset = 200.dp,
offsetFromStart = true,
splitWidth = 64.dp
gapWidth = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -638,7 +635,7 @@ class TwoPaneTest {
strategy = FixedOffsetHorizontalTwoPaneStrategy(
splitOffset = 200.dp,
offsetFromStart = true,
splitWidth = 64.dp
gapWidth = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -758,7 +755,7 @@ class TwoPaneTest {
strategy = FixedOffsetVerticalTwoPaneStrategy(
splitOffset = 300.dp,
offsetFromTop = true,
splitHeight = 64.dp
gapHeight = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down Expand Up @@ -877,7 +874,7 @@ class TwoPaneTest {
strategy = FixedOffsetVerticalTwoPaneStrategy(
splitOffset = 300.dp,
offsetFromTop = false,
splitHeight = 64.dp
gapHeight = 64.dp
),
modifier = Modifier
.requiredSize(900.dp, 1200.dp)
Expand Down

0 comments on commit 26d1a55

Please sign in to comment.