Update API surface of Constraints
Relnote: Improvements to the API surface of Constraints
Bug: 147672763
Test: built and ran demos; ran ui-layout tests
Change-Id: I0fd1505ae9a68c067a82eff6ab02b43080fe153c
diff --git a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/core/WithConstraintsBenchmark.kt b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/core/WithConstraintsBenchmark.kt
index ce493f0..4433072 100644
--- a/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/core/WithConstraintsBenchmark.kt
+++ b/ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/core/WithConstraintsBenchmark.kt
@@ -123,7 +123,7 @@
@Composable
private fun ChangingConstraintsLayout(size: State<IntPx>, children: @Composable() () -> Unit) {
Layout(children) { measurables, _ ->
- val constraints = Constraints.tightConstraints(size.value, size.value)
+ val constraints = Constraints.fixed(size.value, size.value)
measurables.first().measure(constraints).place(0.ipx, 0.ipx)
layout(100.ipx, 100.ipx) {}
}
diff --git a/ui/ui-core/api/0.1.0-dev04.txt b/ui/ui-core/api/0.1.0-dev04.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/0.1.0-dev04.txt
+++ b/ui/ui-core/api/0.1.0-dev04.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/api/current.txt b/ui/ui-core/api/current.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/current.txt
+++ b/ui/ui-core/api/current.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/api/public_plus_experimental_0.1.0-dev04.txt b/ui/ui-core/api/public_plus_experimental_0.1.0-dev04.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/public_plus_experimental_0.1.0-dev04.txt
+++ b/ui/ui-core/api/public_plus_experimental_0.1.0-dev04.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/api/public_plus_experimental_current.txt b/ui/ui-core/api/public_plus_experimental_current.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/public_plus_experimental_current.txt
+++ b/ui/ui-core/api/public_plus_experimental_current.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/api/restricted_0.1.0-dev04.txt b/ui/ui-core/api/restricted_0.1.0-dev04.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/restricted_0.1.0-dev04.txt
+++ b/ui/ui-core/api/restricted_0.1.0-dev04.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/api/restricted_current.txt b/ui/ui-core/api/restricted_current.txt
index 6522680..c72417d 100644
--- a/ui/ui-core/api/restricted_current.txt
+++ b/ui/ui-core/api/restricted_current.txt
@@ -74,9 +74,9 @@
}
public static final class Constraints.Companion {
- method public androidx.ui.core.Constraints tightConstraints(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForHeight(androidx.ui.unit.IntPx height);
- method public androidx.ui.core.Constraints tightConstraintsForWidth(androidx.ui.unit.IntPx width);
+ method public androidx.ui.core.Constraints fixed(androidx.ui.unit.IntPx width, androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedHeight(androidx.ui.unit.IntPx height);
+ method public androidx.ui.core.Constraints fixedWidth(androidx.ui.unit.IntPx width);
}
public final class ConstraintsKt {
@@ -84,17 +84,11 @@
method public static androidx.ui.core.Constraints enforce(androidx.ui.core.Constraints, androidx.ui.core.Constraints otherConstraints);
method public static boolean getHasBoundedHeight(androidx.ui.core.Constraints);
method public static boolean getHasBoundedWidth(androidx.ui.core.Constraints);
- method public static boolean getHasTightHeight(androidx.ui.core.Constraints);
- method public static boolean getHasTightWidth(androidx.ui.core.Constraints);
- method public static boolean isTight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedHeight(androidx.ui.core.Constraints);
+ method public static boolean getHasFixedWidth(androidx.ui.core.Constraints);
method public static boolean isZero(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints looseMin(androidx.ui.core.Constraints);
method public static androidx.ui.core.Constraints offset(androidx.ui.core.Constraints, androidx.ui.unit.IntPx horizontal = 0.ipx, androidx.ui.unit.IntPx vertical = 0.ipx);
method public static boolean satisfiedBy(androidx.ui.core.Constraints, androidx.ui.unit.IntPxSize size);
- method public static androidx.ui.core.Constraints tightMax(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints tightMin(androidx.ui.core.Constraints);
- method public static androidx.ui.core.Constraints withTight(androidx.ui.core.Constraints, androidx.ui.unit.IntPx? width = null, androidx.ui.unit.IntPx? height = null);
}
public final class ConsumedData {
diff --git a/ui/ui-core/src/main/java/androidx/ui/core/Constraints.kt b/ui/ui-core/src/main/java/androidx/ui/core/Constraints.kt
index 83cf619..27c3273 100644
--- a/ui/ui-core/src/main/java/androidx/ui/core/Constraints.kt
+++ b/ui/ui-core/src/main/java/androidx/ui/core/Constraints.kt
@@ -26,17 +26,17 @@
/**
* Immutable constraints used for measuring child [Layout]s. A parent [Layout]
- * can measure their children using the [measure] method on the corresponding [Measurable]s,
- * method which takes the [Constraints] the child has to follow. A [measure]d child is then
- * responsible to choose for themselves and return a size which satisfies the received set
- * of [Constraints]:
+ * can measure their children using the measure method on the corresponding [Measurable]s,
+ * method which takes the [Constraints] the child has to follow. A measured child is then
+ * responsible to choose for themselves and return a size which satisfies the set of [Constraints]
+ * received from their parent:
* - minWidth <= chosenWidth <= maxWidth
* - minHeight <= chosenHeight <= maxHeight
* The parent can then access the child chosen size on the resulting [Placeable]. The parent is
* responsible of defining a valid positioning of the children according to their sizes, so the
* parent needs to measure the children with appropriate [Constraints], such that whatever valid
* sizes children choose, they can be laid out in a way that also respects the parent's incoming
- * [Constraints]. Note that different children can be [measure]d with different [Constraints].
+ * [Constraints]. Note that different children can be measured with different [Constraints].
* A set of [Constraints] can have infinite maxWidth and/or maxHeight. This is a trick often
* used by parents to ask their children for their preferred size: unbounded constraints force
* children whose default behavior is to fill the available space (always size to
@@ -70,15 +70,14 @@
companion object {
/**
- * Creates constraints tight in both dimensions.
+ * Creates constraints for fixed size in both dimensions.
*/
- fun tightConstraints(width: IntPx, height: IntPx) =
- Constraints(width, width, height, height)
+ fun fixed(width: IntPx, height: IntPx) = Constraints(width, width, height, height)
/**
- * Creates constraints with tight width and loose height.
+ * Creates constraints for fixed width and unspecified height.
*/
- fun tightConstraintsForWidth(width: IntPx) = Constraints(
+ fun fixedWidth(width: IntPx) = Constraints(
minWidth = width,
maxWidth = width,
minHeight = IntPx.Zero,
@@ -86,9 +85,9 @@
)
/**
- * Creates constraints with tight height and loose width.
+ * Creates constraints for fixed height and unspecified width.
*/
- fun tightConstraintsForHeight(height: IntPx) = Constraints(
+ fun fixedHeight(height: IntPx) = Constraints(
minWidth = IntPx.Zero,
maxWidth = IntPx.Infinity,
minHeight = height,
@@ -110,24 +109,18 @@
val Constraints.hasBoundedWidth get() = maxWidth.isFinite()
/**
- * Whether there is exactly one size that satisfies the constraints.
- * @see hasTightHeight
- * @see hasTightWidth
- */
-val Constraints.isTight get() = minWidth == maxWidth && minHeight == maxHeight
-
-/**
* Whether there is exactly one width value that satisfies the constraints.
*/
-val Constraints.hasTightWidth get() = maxWidth == minWidth
+val Constraints.hasFixedWidth get() = maxWidth == minWidth
/**
* Whether there is exactly one height value that satisfies the constraints.
*/
-val Constraints.hasTightHeight get() = maxHeight == minHeight
+val Constraints.hasFixedHeight get() = maxHeight == minHeight
/**
- * Whether there is exactly one height value that satisfies the constraints.
+ * Whether the area of a component respecting these constraints will definitely be 0.
+ * This is true when at least one of maxWidth and maxHeight are 0.
*/
val Constraints.isZero get() = maxWidth == IntPx.Zero || maxHeight == IntPx.Zero
@@ -142,16 +135,6 @@
)
/**
- * Returns a copy of the current instance, overriding the specified values to be tight.
- */
-fun Constraints.withTight(width: IntPx? = null, height: IntPx? = null) = Constraints(
- minWidth = width ?: this.minWidth,
- maxWidth = width ?: this.maxWidth,
- minHeight = height ?: this.minHeight,
- maxHeight = height ?: this.maxHeight
-)
-
-/**
* Takes a size and returns the closest size to it that satisfies the constraints.
*/
fun Constraints.constrain(size: IntPxSize) = IntPxSize(
@@ -167,30 +150,6 @@
minHeight <= size.height && size.height <= maxHeight
/**
- * Returns a copy of the current instance with no min constraints.
- */
-fun Constraints.looseMin() = this.copy(minWidth = 0.ipx, minHeight = 0.ipx)
-
-/**
- * Returns a copy of the current instance with no max constraints.
- */
-fun Constraints.looseMax() = this.copy(maxWidth = IntPx.Infinity, maxHeight = IntPx.Infinity)
-
-/**
- * Returns a copy of the current instance with the constraints tightened to their smallest size.
- */
-fun Constraints.tightMin() = this.withTight(width = minWidth, height = minHeight)
-
-/**
- * Returns a copy of the current instance with the constraints tightened to their largest size.
- * Note that if any of the constraints are unbounded, they will be left unchanged.
- */
-fun Constraints.tightMax() = this.copy(
- minWidth = if (hasBoundedWidth) maxWidth else minWidth,
- minHeight = if (hasBoundedHeight) maxHeight else minHeight
-)
-
-/**
* Returns the Constraints obtained by offsetting the current instance with the given values.
*/
fun Constraints.offset(horizontal: IntPx = 0.ipx, vertical: IntPx = 0.ipx) = Constraints(
diff --git a/ui/ui-core/src/test/java/androidx/ui/core/ConstraintsTest.kt b/ui/ui-core/src/test/java/androidx/ui/core/ConstraintsTest.kt
index 1f68ddc..79aa819 100644
--- a/ui/ui-core/src/test/java/androidx/ui/core/ConstraintsTest.kt
+++ b/ui/ui-core/src/test/java/androidx/ui/core/ConstraintsTest.kt
@@ -39,13 +39,13 @@
val constraints = Constraints(0.ipx, 1.ipx, 2.ipx, 3.ipx)
constraints.assertEquals(0.ipx, 1.ipx, 2.ipx, 3.ipx)
- val tightConstraintsForWidth = Constraints.tightConstraintsForWidth(5.ipx)
+ val tightConstraintsForWidth = Constraints.fixedWidth(5.ipx)
tightConstraintsForWidth.assertEquals(5.ipx, 5.ipx, IntPx.Zero, IntPx.Infinity)
- val tightConstraintsForHeight = Constraints.tightConstraintsForHeight(5.ipx)
+ val tightConstraintsForHeight = Constraints.fixedHeight(5.ipx)
tightConstraintsForHeight.assertEquals(IntPx.Zero, IntPx.Infinity, 5.ipx, 5.ipx)
- val tightConstraints = Constraints.tightConstraints(5.ipx, 7.ipx)
+ val tightConstraints = Constraints.fixed(5.ipx, 7.ipx)
tightConstraints.assertEquals(5.ipx, 5.ipx, 7.ipx, 7.ipx)
}
@@ -61,16 +61,14 @@
}
@Test
- fun hasTightDimensions() {
+ fun hasFixedDimensions() {
val untight = Constraints(3.ipx, 4.ipx, 8.ipx, 9.ipx)
- assertFalse(untight.hasTightWidth)
- assertFalse(untight.hasTightHeight)
- assertFalse(untight.isTight)
+ assertFalse(untight.hasFixedWidth)
+ assertFalse(untight.hasFixedHeight)
val tight = Constraints(3.ipx, 3.ipx, 5.ipx, 5.ipx)
- assertTrue(tight.hasTightWidth)
- assertTrue(tight.hasTightHeight)
- assertTrue(tight.isTight)
+ assertTrue(tight.hasFixedWidth)
+ assertTrue(tight.hasFixedHeight)
}
@Test
@@ -100,13 +98,6 @@
}
@Test
- fun withTight() {
- val constraints = Constraints(2.ipx, 3.ipx, 2.ipx, 3.ipx)
- constraints.withTight().assertEquals(2.ipx, 3.ipx, 2.ipx, 3.ipx)
- constraints.withTight(7.ipx, 8.ipx).assertEquals(7.ipx, 7.ipx, 8.ipx, 8.ipx)
- }
-
- @Test
fun constrain() {
val constraints = Constraints(2.ipx, 5.ipx, 2.ipx, 5.ipx)
assertEquals(IntPxSize(2.ipx, 2.ipx), constraints.constrain(IntPxSize(1.ipx, 1.ipx)))
@@ -127,28 +118,6 @@
}
@Test
- fun loose() {
- val bounded = Constraints(2.ipx, 5.ipx, 2.ipx, 5.ipx)
- bounded.looseMin().assertEquals(0.ipx, 5.ipx, 0.ipx, 5.ipx)
- bounded.looseMax().assertEquals(2.ipx, IntPx.Infinity, 2.ipx, IntPx.Infinity)
-
- val unbounded = Constraints(2.ipx, IntPx.Infinity, 2.ipx, IntPx.Infinity)
- unbounded.looseMin().assertEquals(0.ipx, IntPx.Infinity, 0.ipx, IntPx.Infinity)
- unbounded.looseMax().assertEquals(2.ipx, IntPx.Infinity, 2.ipx, IntPx.Infinity)
- }
-
- @Test
- fun tight() {
- val bounded = Constraints(2.ipx, 5.ipx, 2.ipx, 5.ipx)
- bounded.tightMin().assertEquals(2.ipx, 2.ipx, 2.ipx, 2.ipx)
- bounded.tightMax().assertEquals(5.ipx, 5.ipx, 5.ipx, 5.ipx)
-
- val unbounded = Constraints(2.ipx, IntPx.Infinity, 2.ipx, IntPx.Infinity)
- unbounded.tightMin().assertEquals(2.ipx, 2.ipx, 2.ipx, 2.ipx)
- unbounded.tightMax().assertEquals(2.ipx, IntPx.Infinity, 2.ipx, IntPx.Infinity)
- }
-
- @Test
fun offset() {
val constraints = Constraints(2.ipx, 2.ipx, 5.ipx, 5.ipx)
constraints.offset(horizontal = 2.ipx, vertical = 3.ipx).assertEquals(
diff --git a/ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/MultipleCollect.kt b/ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/MultipleCollect.kt
index 5d5677b..176e918 100644
--- a/ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/MultipleCollect.kt
+++ b/ui/ui-framework/integration-tests/framework-demos/src/main/java/androidx/ui/framework/demos/MultipleCollect.kt
@@ -78,17 +78,17 @@
)
}) { measurables, constraints ->
val headerPlaceable = measurables.first { it.tag == "header" }.measure(
- Constraints.tightConstraints(constraints.maxWidth, 100.ipx)
+ Constraints.fixed(constraints.maxWidth, 100.ipx)
)
val footerPadding = 50.ipx
val footerPlaceable = measurables.first { it.tag == "footer" }.measure(
- Constraints.tightConstraints(constraints.maxWidth - footerPadding * 2, 100.ipx)
+ Constraints.fixed(constraints.maxWidth - footerPadding * 2, 100.ipx)
)
val itemHeight =
(constraints.maxHeight - headerPlaceable.height - footerPlaceable.height) /
measurables.filter { it.tag == "content" }.size
val contentPlaceables = measurables.filter { it.tag == "content" }.map { measurable ->
- measurable.measure(Constraints.tightConstraints(constraints.maxWidth, itemHeight))
+ measurable.measure(Constraints.fixed(constraints.maxWidth, itemHeight))
}
layout(constraints.maxWidth, constraints.maxHeight) {
diff --git a/ui/ui-framework/integration-tests/samples/src/main/java/androidx/ui/framework/samples/LayoutSample.kt b/ui/ui-framework/integration-tests/samples/src/main/java/androidx/ui/framework/samples/LayoutSample.kt
index 3278903..8d75bc0 100644
--- a/ui/ui-framework/integration-tests/samples/src/main/java/androidx/ui/framework/samples/LayoutSample.kt
+++ b/ui/ui-framework/integration-tests/samples/src/main/java/androidx/ui/framework/samples/LayoutSample.kt
@@ -108,7 +108,7 @@
val placeables = measurables.map { measurable ->
when (measurable.tag) {
// You should use appropriate constraints. Here we measure with dummy constraints.
- "header" -> measurable.measure(Constraints.tightConstraints(100.ipx, 100.ipx))
+ "header" -> measurable.measure(Constraints.fixed(100.ipx, 100.ipx))
"footer" -> measurable.measure(constraints)
else -> error("Unexpected tag")
}
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt
index 5f88291..deae4ca1 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/PopupTest.kt
@@ -29,6 +29,7 @@
import androidx.ui.unit.IntPx
import androidx.ui.unit.IntPxPosition
import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.ipx
import androidx.ui.unit.isFinite
import androidx.ui.unit.toPxPosition
import androidx.ui.unit.toPxSize
@@ -557,7 +558,7 @@
Layout(children) { measurables, constraints ->
val measurable = measurables.firstOrNull()
// The child cannot be larger than our max constraints, but we ignore min constraints.
- val placeable = measurable?.measure(constraints.looseMin())
+ val placeable = measurable?.measure(constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx))
// The layout is as large as possible for bounded constraints,
// or wrap content otherwise.
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/TextLayoutTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/TextLayoutTest.kt
index adead6a..e3540d0 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/TextLayoutTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/TextLayoutTest.kt
@@ -180,7 +180,9 @@
override fun run() {
activity.setContent {
Layout(composable) { measurables, constraints ->
- val placeables = measurables.map { it.measure(constraints.looseMin()) }
+ val placeables = measurables.map {
+ it.measure(constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx))
+ }
layout(constraints.maxWidth, constraints.maxHeight) {
var top = 0.px
placeables.forEach {
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt
index e05f728..eed565f 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/AndroidLayoutDrawTest.kt
@@ -53,7 +53,6 @@
import androidx.ui.core.draw
import androidx.ui.core.drawWithContent
import androidx.ui.core.globalPosition
-import androidx.ui.core.looseMin
import androidx.ui.core.offset
import androidx.ui.core.setContent
import androidx.ui.core.tag
@@ -392,8 +391,8 @@
val childrenCount = 3
val childConstraints = arrayOf(
Constraints(),
- Constraints.tightConstraintsForWidth(50.ipx),
- Constraints.tightConstraintsForHeight(50.ipx)
+ Constraints.fixedWidth(50.ipx),
+ Constraints.fixedHeight(50.ipx)
)
val headerChildrenCount = 1
val footerChildrenCount = 2
@@ -2024,7 +2023,7 @@
private val AlignTopLeft = object : LayoutModifier {
override fun DensityScope.modifyConstraints(constraints: Constraints) =
- constraints.looseMin()
+ constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx)
override fun DensityScope.modifySize(
constraints: Constraints,
childSize: IntPxSize
@@ -2257,7 +2256,7 @@
children: @Composable() () -> Unit = {}
) {
Layout(children = children, modifier = modifier) { measurables, _ ->
- val newConstraints = Constraints.tightConstraints(size, size)
+ val newConstraints = Constraints.fixed(size, size)
val placeables = measurables.map { m ->
m.measure(newConstraints)
}
@@ -2335,7 +2334,7 @@
Layout(children = children) { measurables, _ ->
val testConstraints = Constraints()
measurables.forEach { it.measure(testConstraints) }
- val childConstraints = Constraints.tightConstraints(size, size)
+ val childConstraints = Constraints.fixed(size, size)
try {
val placeables2 = measurables.map { it.measure(childConstraints) }
fail("Measuring twice on the same Measurable should throw an exception")
@@ -2636,7 +2635,7 @@
}
override fun DensityScope.modifyConstraints(constraints: Constraints): Constraints {
- return Constraints.tightConstraints(10.ipx, 10.ipx)
+ return Constraints.fixed(10.ipx, 10.ipx)
}
override fun DensityScope.modifySize(
diff --git a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/WithConstraintsTest.kt b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/WithConstraintsTest.kt
index e333ff6..c232ebe 100644
--- a/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/WithConstraintsTest.kt
+++ b/ui/ui-framework/src/androidTest/java/androidx/ui/core/test/WithConstraintsTest.kt
@@ -144,7 +144,7 @@
}
}) { measurables, constraints3 ->
val placeable = measurables[0].measure(
- Constraints.tightConstraints(
+ Constraints.fixed(
model.size,
model.size
)
@@ -283,13 +283,13 @@
}
}
assertTrue(latch.await(1, TimeUnit.SECONDS))
- assertEquals(Constraints.tightConstraints(50.ipx, 50.ipx), actualConstraints)
+ assertEquals(Constraints.fixed(50.ipx, 50.ipx), actualConstraints)
latch = CountDownLatch(1)
rule.runOnUiThread { model.value = 100.ipx }
assertTrue(latch.await(1, TimeUnit.SECONDS))
- assertEquals(Constraints.tightConstraints(100.ipx, 100.ipx), actualConstraints)
+ assertEquals(Constraints.fixed(100.ipx, 100.ipx), actualConstraints)
}
@Test
@@ -535,7 +535,7 @@
private fun ChangingConstraintsLayout(size: ValueModel<IntPx>, children: @Composable() () -> Unit) {
Layout(children) { measurables, _ ->
layout(100.ipx, 100.ipx) {
- val constraints = Constraints.tightConstraints(size.value, size.value)
+ val constraints = Constraints.fixed(size.value, size.value)
measurables.first().measure(constraints).place(0.ipx, 0.ipx)
}
}
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
index 7ac3bc3..84a3909 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/TextFieldDelegate.kt
@@ -104,7 +104,7 @@
): Triple<IntPx, IntPx, TextLayoutResult> {
val layoutResult = if (constraints.maxWidth.isFinite()) {
textDelegate.layout(
- Constraints.tightConstraintsForWidth(constraints.maxWidth),
+ Constraints.fixedWidth(constraints.maxWidth),
prevResultText
)
} else {
@@ -112,7 +112,7 @@
// falling back to wrap-content behavior since it may be in the horizontal scroller.
textDelegate.layoutIntrinsics()
textDelegate.layout(
- Constraints.tightConstraintsForWidth(textDelegate.maxIntrinsicWidth),
+ Constraints.fixedWidth(textDelegate.maxIntrinsicWidth),
prevResultText
)
}
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt
index 7b16ba5..7f8a404 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionContainer.kt
@@ -29,10 +29,8 @@
import androidx.ui.core.gesture.LongPressDragGestureDetector
import androidx.ui.core.gesture.PressReleasedGestureDetector
import androidx.ui.core.gesture.TouchSlopDragGestureDetector
-import androidx.ui.core.hasTightHeight
-import androidx.ui.core.hasTightWidth
-import androidx.ui.core.looseMin
-import androidx.ui.core.withTight
+import androidx.ui.core.hasFixedHeight
+import androidx.ui.core.hasFixedWidth
import androidx.ui.unit.Dp
import androidx.ui.unit.IntPx
import androidx.ui.unit.IntPxPosition
@@ -187,12 +185,17 @@
) {
Layout(children) { measurables, incomingConstraints ->
val containerConstraints = Constraints()
- .withTight(width?.toIntPx(), height?.toIntPx())
+ .copy(
+ width?.toIntPx() ?: 0.ipx,
+ width?.toIntPx() ?: IntPx.Infinity,
+ height?.toIntPx() ?: 0.ipx,
+ height?.toIntPx() ?: IntPx.Infinity
+ )
.enforce(incomingConstraints)
- val childConstraints = containerConstraints.looseMin()
+ val childConstraints = containerConstraints.copy(minWidth = 0.ipx, minHeight = 0.ipx)
var placeable: Placeable? = null
val containerWidth = if (
- containerConstraints.hasTightWidth &&
+ containerConstraints.hasFixedWidth &&
containerConstraints.maxWidth.isFinite()
) {
containerConstraints.maxWidth
@@ -201,7 +204,7 @@
max((placeable?.width ?: 0.ipx), containerConstraints.minWidth)
}
val containerHeight = if (
- containerConstraints.hasTightHeight &&
+ containerConstraints.hasFixedHeight &&
containerConstraints.maxHeight.isFinite()
) {
containerConstraints.maxHeight
diff --git a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionHandles.kt b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionHandles.kt
index 0d69168..b94ad32 100644
--- a/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionHandles.kt
+++ b/ui/ui-framework/src/main/java/androidx/ui/core/selection/SelectionHandles.kt
@@ -21,7 +21,6 @@
import androidx.ui.core.Constraints
import androidx.ui.core.Draw
import androidx.ui.core.Layout
-import androidx.ui.core.withTight
import androidx.ui.geometry.Rect
import androidx.ui.graphics.Color
import androidx.ui.graphics.Paint
@@ -81,7 +80,7 @@
children: @Composable() () -> Unit
) {
Layout(children) { measurables, _ ->
- val constraints = Constraints().withTight(width.toIntPx(), height.toIntPx())
+ val constraints = Constraints.fixed(width.toIntPx(), height.toIntPx())
val placeables = measurables.map { measurable ->
measurable.measure(constraints)
}
diff --git a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
index 54880f5..147c8ee 100644
--- a/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
+++ b/ui/ui-framework/src/test/java/androidx/ui/core/TextFieldDelegateTest.kt
@@ -498,6 +498,6 @@
assertThat(res.first).isEqualTo(123.ipx)
assertEquals(512.ipx, res.second)
- verify(mDelegate, times(1)).layout(Constraints.tightConstraintsForWidth(123.ipx))
+ verify(mDelegate, times(1)).layout(Constraints.fixedWidth(123.ipx))
}
}
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Align.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Align.kt
index 63ee82d..f30c91c 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Align.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Align.kt
@@ -21,7 +21,6 @@
import androidx.ui.core.Constraints
import androidx.ui.core.Layout
import androidx.ui.core.LayoutModifier
-import androidx.ui.core.looseMin
import androidx.ui.unit.DensityScope
import androidx.ui.unit.IntPxPosition
import androidx.ui.unit.IntPxSize
@@ -46,7 +45,7 @@
Layout(children) { measurables, constraints ->
val measurable = measurables.firstOrNull()
// The child cannot be larger than our max constraints, but we ignore min constraints.
- val placeable = measurable?.measure(constraints.looseMin())
+ val placeable = measurable?.measure(constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx))
// The layout is as large as possible for bounded constraints,
// or wrap content otherwise.
@@ -225,7 +224,7 @@
private val direction: Direction
) : LayoutModifier {
override fun DensityScope.modifyConstraints(constraints: Constraints) = when (direction) {
- Direction.Both -> constraints.looseMin()
+ Direction.Both -> constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx)
Direction.Horizontal -> constraints.copy(minWidth = 0.ipx)
Direction.Vertical -> constraints.copy(minHeight = 0.ipx)
}
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/AspectRatio.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/AspectRatio.kt
index 247117c..da98f0d 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/AspectRatio.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/AspectRatio.kt
@@ -58,7 +58,7 @@
override fun DensityScope.modifyConstraints(constraints: Constraints): Constraints {
val size = constraints.findSizeWith(aspectRatio)
return if (size != null)
- Constraints.tightConstraints(size.width, size.height)
+ Constraints.fixed(size.width, size.height)
else
constraints
}
@@ -124,7 +124,7 @@
val measurable = measurables.firstOrNull()
val childConstraints = if (size != null) {
- Constraints.tightConstraints(size.width, size.height)
+ Constraints.fixed(size.width, size.height)
} else {
constraints
}
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Container.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Container.kt
index 6eec551..0af085e 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Container.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Container.kt
@@ -23,11 +23,9 @@
import androidx.ui.core.Modifier
import androidx.ui.core.Placeable
import androidx.ui.core.enforce
-import androidx.ui.core.hasTightHeight
-import androidx.ui.core.hasTightWidth
-import androidx.ui.core.looseMin
+import androidx.ui.core.hasFixedHeight
+import androidx.ui.core.hasFixedWidth
import androidx.ui.core.offset
-import androidx.ui.core.withTight
import androidx.ui.unit.Dp
import androidx.ui.unit.IntPxSize
import androidx.ui.unit.dp
@@ -68,15 +66,19 @@
) {
Layout(children, modifier) { measurables, incomingConstraints ->
val containerConstraints = Constraints(constraints)
- .withTight(width?.toIntPx(), height?.toIntPx())
- .enforce(incomingConstraints)
+ .copy(
+ width?.toIntPx() ?: constraints.minWidth.toIntPx(),
+ width?.toIntPx() ?: constraints.maxWidth.toIntPx(),
+ height?.toIntPx() ?: constraints.minHeight.toIntPx(),
+ height?.toIntPx() ?: constraints.maxHeight.toIntPx()
+ ).enforce(incomingConstraints)
val totalHorizontal = padding.left.toIntPx() + padding.right.toIntPx()
val totalVertical = padding.top.toIntPx() + padding.bottom.toIntPx()
val childConstraints = containerConstraints
- .looseMin()
+ .copy(minWidth = 0.ipx, minHeight = 0.ipx)
.offset(-totalHorizontal, -totalVertical)
var placeable: Placeable? = null
- val containerWidth = if ((containerConstraints.hasTightWidth || expanded) &&
+ val containerWidth = if ((containerConstraints.hasFixedWidth || expanded) &&
containerConstraints.maxWidth.isFinite()
) {
containerConstraints.maxWidth
@@ -84,7 +86,7 @@
placeable = measurables.firstOrNull()?.measure(childConstraints)
max((placeable?.width ?: 0.ipx) + totalHorizontal, containerConstraints.minWidth)
}
- val containerHeight = if ((containerConstraints.hasTightHeight || expanded) &&
+ val containerHeight = if ((containerConstraints.hasFixedHeight || expanded) &&
containerConstraints.maxHeight.isFinite()
) {
containerConstraints.maxHeight
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Intrinsic.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Intrinsic.kt
index de48dc3..8ca9aac 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Intrinsic.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Intrinsic.kt
@@ -58,7 +58,7 @@
val measurable = measurables.firstOrNull()
val width = measurable?.minIntrinsicWidth(constraints.maxHeight) ?: 0.ipx
val placeable = measurable?.measure(
- Constraints.tightConstraintsForWidth(width).enforce(constraints)
+ Constraints.fixedWidth(width).enforce(constraints)
)
layout(placeable?.width ?: 0.ipx, placeable?.height ?: 0.ipx) {
placeable?.place(0.ipx, 0.ipx)
@@ -103,7 +103,7 @@
val measurable = measurables.firstOrNull()
val height = measurable?.minIntrinsicHeight(constraints.maxWidth) ?: 0.ipx
val placeable = measurable?.measure(
- Constraints.tightConstraintsForHeight(height).enforce(constraints)
+ Constraints.fixedHeight(height).enforce(constraints)
)
layout(placeable?.width ?: 0.ipx, placeable?.height ?: 0.ipx) {
placeable?.place(0.ipx, 0.ipx)
@@ -148,7 +148,7 @@
val measurable = measurables.firstOrNull()
val width = measurable?.maxIntrinsicWidth(constraints.maxHeight) ?: 0.ipx
val placeable = measurable?.measure(
- Constraints.tightConstraintsForWidth(width).enforce(constraints)
+ Constraints.fixedWidth(width).enforce(constraints)
)
layout(placeable?.width ?: 0.ipx, placeable?.height ?: 0.ipx) {
placeable?.place(0.ipx, 0.ipx)
@@ -193,7 +193,7 @@
val measurable = measurables.firstOrNull()
val height = measurable?.maxIntrinsicHeight(constraints.maxWidth) ?: 0.ipx
val placeable = measurable?.measure(
- Constraints.tightConstraintsForHeight(height).enforce(constraints)
+ Constraints.fixedHeight(height).enforce(constraints)
)
layout(placeable?.width ?: 0.ipx, placeable?.height ?: 0.ipx) {
placeable?.place(0.ipx, 0.ipx)
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/SizeModifiers.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/SizeModifiers.kt
index 3179784..f29edde 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/SizeModifiers.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/SizeModifiers.kt
@@ -23,7 +23,6 @@
import androidx.ui.core.enforce
import androidx.ui.core.hasBoundedHeight
import androidx.ui.core.hasBoundedWidth
-import androidx.ui.core.withTight
import androidx.ui.unit.DensityScope
import androidx.ui.unit.Dp
import androidx.ui.unit.IntPx
@@ -145,7 +144,7 @@
object Fill : LayoutModifier {
override fun DensityScope.modifyConstraints(constraints: Constraints): Constraints =
if (constraints.hasBoundedWidth) {
- constraints.withTight(width = constraints.maxWidth)
+ constraints.copy(minWidth = constraints.maxWidth, maxWidth = constraints.maxWidth)
} else {
constraints
}
@@ -241,7 +240,10 @@
object Fill : LayoutModifier {
override fun DensityScope.modifyConstraints(constraints: Constraints): Constraints =
if (constraints.hasBoundedHeight) {
- constraints.withTight(height = constraints.maxHeight)
+ constraints.copy(
+ minHeight = constraints.maxHeight,
+ maxHeight = constraints.maxHeight
+ )
} else {
constraints
}
@@ -384,11 +386,16 @@
object Fill : LayoutModifier {
override fun DensityScope.modifyConstraints(constraints: Constraints): Constraints =
when {
- constraints.hasBoundedWidth && constraints.hasBoundedHeight -> constraints
- .withTight(width = constraints.maxWidth, height = constraints.maxHeight)
- constraints.hasBoundedWidth -> constraints.withTight(width = constraints.maxWidth)
- constraints.hasBoundedHeight -> constraints.withTight(
- height = constraints.maxHeight)
+ constraints.hasBoundedWidth && constraints.hasBoundedHeight -> constraints.copy(
+ minWidth = constraints.maxWidth,
+ minHeight = constraints.maxHeight
+ )
+ constraints.hasBoundedWidth -> constraints.copy(
+ minWidth = constraints.maxWidth
+ )
+ constraints.hasBoundedHeight -> constraints.copy(
+ minHeight = constraints.maxHeight
+ )
else -> constraints
}
}
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Stack.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Stack.kt
index a4099a6..a687c77e 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Stack.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Stack.kt
@@ -24,10 +24,10 @@
import androidx.ui.core.Modifier
import androidx.ui.core.ParentDataModifier
import androidx.ui.core.Placeable
-import androidx.ui.core.looseMin
import androidx.ui.unit.DensityScope
import androidx.ui.unit.IntPx
import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.ipx
import androidx.ui.unit.isFinite
import androidx.ui.unit.max
@@ -51,8 +51,9 @@
Layout(stackChildren, modifier = modifier) { measurables, constraints ->
val placeables = arrayOfNulls<Placeable>(measurables.size)
// First measure aligned children to get the size of the layout.
+ val childConstraints = constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx)
(0 until measurables.size).filter { i -> !measurables[i].stretch }.forEach { i ->
- placeables[i] = measurables[i].measure(constraints.looseMin())
+ placeables[i] = measurables[i].measure(childConstraints)
}
val (stackWidth, stackHeight) = with(placeables.filterNotNull()) {
Pair(
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Table.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Table.kt
index 12e6b35..3cb26c8 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Table.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Table.kt
@@ -610,7 +610,7 @@
}
}
val decorationConstraints =
- Constraints.tightConstraints(tableSize.width, tableSize.height)
+ Constraints.fixed(tableSize.width, tableSize.height)
measurables.filter { it.rowIndex == null }.forEach {
it.measure(decorationConstraints).place(IntPx.Zero, IntPx.Zero)
}
diff --git a/ui/ui-layout/src/main/java/androidx/ui/layout/Wrap.kt b/ui/ui-layout/src/main/java/androidx/ui/layout/Wrap.kt
index fe392c6..16104a5 100644
--- a/ui/ui-layout/src/main/java/androidx/ui/layout/Wrap.kt
+++ b/ui/ui-layout/src/main/java/androidx/ui/layout/Wrap.kt
@@ -21,7 +21,6 @@
import androidx.ui.core.Constraints
import androidx.ui.core.Layout
import androidx.ui.core.LayoutModifier
-import androidx.ui.core.looseMin
import androidx.ui.unit.DensityScope
import androidx.ui.unit.IntPxPosition
import androidx.ui.unit.IntPxSize
@@ -42,7 +41,7 @@
Layout(children) { measurables, constraints ->
val measurable = measurables.firstOrNull()
// The child cannot be larger than our max constraints, but we ignore min constraints.
- val placeable = measurable?.measure(constraints.looseMin())
+ val placeable = measurable?.measure(constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx))
// Try to be as small as possible.
val layoutWidth = max(placeable?.width ?: 0.ipx, constraints.minWidth)
@@ -67,7 +66,8 @@
* size itself to min incoming constraints and place its content in the center.
*/
val LayoutWrapped: LayoutModifier = object : LayoutModifier {
- override fun DensityScope.modifyConstraints(constraints: Constraints) = constraints.looseMin()
+ override fun DensityScope.modifyConstraints(constraints: Constraints) =
+ constraints.copy(minWidth = 0.ipx, minHeight = 0.ipx)
override fun DensityScope.modifySize(
constraints: Constraints,
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/DataTable.kt b/ui/ui-material/src/main/java/androidx/ui/material/DataTable.kt
index 55471c3..c472027 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/DataTable.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/DataTable.kt
@@ -463,7 +463,7 @@
measurables.forEach { measurable ->
val i = measurable.parentData as Int
val placeable = measurable.measure(
- Constraints.tightConstraints(
+ Constraints.fixed(
width = constraints.maxWidth,
height = verticalOffsets[i + 2] - verticalOffsets[i + 1]
)
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Tab.kt b/ui/ui-material/src/main/java/androidx/ui/material/Tab.kt
index 1908d00..e38f9a3 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Tab.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Tab.kt
@@ -26,6 +26,7 @@
import androidx.ui.animation.PxPropKey
import androidx.ui.animation.Transition
import androidx.ui.core.Alignment
+import androidx.ui.core.Constraints
import androidx.ui.core.FirstBaseline
import androidx.ui.core.LastBaseline
import androidx.ui.core.Layout
@@ -38,7 +39,6 @@
import androidx.ui.core.WithConstraints
import androidx.ui.core.ambientDensity
import androidx.ui.core.tag
-import androidx.ui.core.withTight
import androidx.ui.foundation.ColoredRect
import androidx.ui.foundation.HorizontalScroller
import androidx.ui.foundation.ScrollerPosition
@@ -281,13 +281,13 @@
// The divider is measured with its own height, and width equal to the total width
// of the tab row, and then placed on top of the tabs.
measurables.firstOrNull { it.tag == DividerTag }
- ?.measure(constraints.withTight(width = layoutWidth))
+ ?.measure(constraints.copy(minWidth = layoutWidth, maxWidth = layoutWidth))
?.run { place(IntPx.Zero, layoutHeight - height) }
// The indicator container is measured to fill the entire space occupied by the tab
// row, and then placed on top of the divider.
measurables.firstOrNull { it.tag == IndicatorTag }
- ?.measure(constraints.withTight(width = layoutWidth, height = layoutHeight))
+ ?.measure(Constraints.fixed(layoutWidth, layoutHeight))
?.place(IntPx.Zero, IntPx.Zero)
}
}
diff --git a/ui/ui-platform/src/main/java/androidx/ui/core/AndroidOwner.kt b/ui/ui-platform/src/main/java/androidx/ui/core/AndroidOwner.kt
index 6d1a84a..737e58a 100644
--- a/ui/ui-platform/src/main/java/androidx/ui/core/AndroidOwner.kt
+++ b/ui/ui-platform/src/main/java/androidx/ui/core/AndroidOwner.kt
@@ -109,7 +109,7 @@
}
private val pointerInputEventProcessor = PointerInputEventProcessor(root)
- var constraints = Constraints.tightConstraints(width = IntPx.Zero, height = IntPx.Zero)
+ var constraints = Constraints.fixed(width = IntPx.Zero, height = IntPx.Zero)
// TODO(mount): reinstate when coroutines are supported by IR compiler
// private val ownerScope = CoroutineScope(Dispatchers.Main.immediate + Job())
diff --git a/ui/ui-platform/src/main/java/androidx/ui/core/ComponentNodes.kt b/ui/ui-platform/src/main/java/androidx/ui/core/ComponentNodes.kt
index 5f9076b..10a2672 100644
--- a/ui/ui-platform/src/main/java/androidx/ui/core/ComponentNodes.kt
+++ b/ui/ui-platform/src/main/java/androidx/ui/core/ComponentNodes.kt
@@ -823,7 +823,7 @@
/**
* The constraints used the last time [layout] was called.
*/
- var constraints: Constraints = Constraints.tightConstraints(IntPx.Zero, IntPx.Zero)
+ var constraints: Constraints = Constraints.fixed(IntPx.Zero, IntPx.Zero)
/**
* Implementation oddity around composition; used to capture a reference to this
diff --git a/ui/ui-text/src/test/java/androidx/ui/text/TextLayoutHelperTest.kt b/ui/ui-text/src/test/java/androidx/ui/text/TextLayoutHelperTest.kt
index 7d83f0a..44254d1 100644
--- a/ui/ui-text/src/test/java/androidx/ui/text/TextLayoutHelperTest.kt
+++ b/ui/ui-text/src/test/java/androidx/ui/text/TextLayoutHelperTest.kt
@@ -52,7 +52,7 @@
density = Density(1.0f),
layoutDirection = LayoutDirection.Ltr,
resourceLoader = resourceLoader,
- constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ constraints = Constraints.fixedWidth(100.ipx)
),
multiParagraph = mock(),
size = IntPxSize(50.ipx, 50.ipx)
@@ -61,7 +61,7 @@
@Test
fun testCanResue_same() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -77,7 +77,7 @@
@Test
fun testCanResue_different_text() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, Android").toAnnotatedString(),
style = TextStyle(),
@@ -93,7 +93,7 @@
@Test
fun testCanResue_different_style() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(fontSize = 1.5.em),
@@ -109,7 +109,7 @@
@Test
fun testCanResue_different_maxLines() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -125,7 +125,7 @@
@Test
fun testCanResue_different_softWrap() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -141,7 +141,7 @@
@Test
fun testCanResue_different_overflow() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -157,7 +157,7 @@
@Test
fun testCanResue_different_density() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -173,7 +173,7 @@
@Test
fun testCanResue_different_layoutDirection() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -189,7 +189,7 @@
@Test
fun testCanResue_different_resourceLoader() {
- val constraints = Constraints.tightConstraintsForWidth(100.ipx)
+ val constraints = Constraints.fixedWidth(100.ipx)
assertThat(referenceResult.canReuse(
text = AnnotatedString.Builder("Hello, World").toAnnotatedString(),
style = TextStyle(),
@@ -214,7 +214,7 @@
density = Density(1.0f),
layoutDirection = LayoutDirection.Ltr,
resourceLoader = resourceLoader,
- constraints = Constraints.tightConstraintsForWidth(200.ipx)
+ constraints = Constraints.fixedWidth(200.ipx)
)).isFalse()
}
}