Remove IntPx
Relnote: "Replaced usage of IntPx with Int. Replaced IntPxPosition
with IntOffset. Replaced IntPxSize with IntSize."
Test: ran many tests and demo app.
Bug: 148980115
Change-Id: Ib7b44d92ce3aff86c606753f0ac5c3122b71041d
diff --git a/ui/ui-material/api/0.1.0-dev14.txt b/ui/ui-material/api/0.1.0-dev14.txt
index ad1e0c1..45c0703 100644
--- a/ui/ui-material/api/0.1.0-dev14.txt
+++ b/ui/ui-material/api/0.1.0-dev14.txt
@@ -261,7 +261,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/api/current.txt b/ui/ui-material/api/current.txt
index ad1e0c1..45c0703 100644
--- a/ui/ui-material/api/current.txt
+++ b/ui/ui-material/api/current.txt
@@ -261,7 +261,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/api/public_plus_experimental_0.1.0-dev14.txt b/ui/ui-material/api/public_plus_experimental_0.1.0-dev14.txt
index ad1e0c1..45c0703 100644
--- a/ui/ui-material/api/public_plus_experimental_0.1.0-dev14.txt
+++ b/ui/ui-material/api/public_plus_experimental_0.1.0-dev14.txt
@@ -261,7 +261,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/api/public_plus_experimental_current.txt b/ui/ui-material/api/public_plus_experimental_current.txt
index ad1e0c1..45c0703 100644
--- a/ui/ui-material/api/public_plus_experimental_current.txt
+++ b/ui/ui-material/api/public_plus_experimental_current.txt
@@ -261,7 +261,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/api/restricted_0.1.0-dev14.txt b/ui/ui-material/api/restricted_0.1.0-dev14.txt
index 3f699964..28f1ace 100644
--- a/ui/ui-material/api/restricted_0.1.0-dev14.txt
+++ b/ui/ui-material/api/restricted_0.1.0-dev14.txt
@@ -262,7 +262,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/api/restricted_current.txt b/ui/ui-material/api/restricted_current.txt
index 3f699964..28f1ace 100644
--- a/ui/ui-material/api/restricted_current.txt
+++ b/ui/ui-material/api/restricted_current.txt
@@ -262,7 +262,7 @@
public static final class TabRow.TabPosition {
method public int component1();
method public int component2();
- method public androidx.ui.material.TabRow.TabPosition copy-rRMsBxU(int left, int width);
+ method public androidx.ui.material.TabRow.TabPosition copy(int left, int width);
method public int getLeft();
method public int getRight();
method public int getWidth();
diff --git a/ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt b/ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt
index 797bbef..96375fc 100644
--- a/ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt
+++ b/ui/ui-material/icons/extended/src/androidTest/java/androidx/ui/material/icons/test/IconComparisonTest.kt
@@ -49,7 +49,6 @@
import androidx.ui.test.findByTag
import androidx.ui.test.runOnUiThread
import androidx.ui.test.waitForIdle
-import androidx.ui.unit.ipx
import androidx.ui.unit.toRect
import com.google.common.truth.Truth
import org.junit.Rule
@@ -205,7 +204,7 @@
// Using ipx directly ensures that we will always have a consistent layout / drawing
// story, so anti-aliasing should be identical.
val layoutSize = with(DensityAmbient.current) {
- Modifier.preferredSize(72.ipx.toDp())
+ Modifier.preferredSize(72.toDp())
}
Row(Modifier.gravity(Alignment.Center)) {
Box(
diff --git a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/ColorPickerDemo.kt b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/ColorPickerDemo.kt
index 9ca4548..3e7c208 100644
--- a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/ColorPickerDemo.kt
+++ b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/ColorPickerDemo.kt
@@ -95,7 +95,7 @@
.fillMaxSize()
.aspectRatio(1f)
) {
- val diameter = constraints.maxWidth.value
+ val diameter = constraints.maxWidth
var position by state { Offset.Zero }
val colorWheel = remember(diameter) { ColorWheel(diameter) }
diff --git a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MaterialTextField.kt b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MaterialTextField.kt
index 47923fa..dbbca87 100644
--- a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MaterialTextField.kt
+++ b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MaterialTextField.kt
@@ -52,10 +52,7 @@
import androidx.ui.material.samples.TextFieldWithHelperMessage
import androidx.ui.material.samples.TextFieldWithHideKeyboardOnImeAction
import androidx.ui.savedinstancestate.savedInstanceState
-import androidx.ui.unit.IntPx
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
-
@Composable
fun TextFieldsDemo() {
val space = with(DensityAmbient.current) { 5.dp.toIntPx() }
@@ -196,14 +193,14 @@
*/
private enum class Option { None, Helper, Error }
-private fun arrangeWithSpacer(space: IntPx) = object : Arrangement.Vertical {
+private fun arrangeWithSpacer(space: Int) = object : Arrangement.Vertical {
override fun arrange(
- totalSize: IntPx,
- size: List<IntPx>,
+ totalSize: Int,
+ size: List<Int>,
layoutDirection: LayoutDirection
- ): List<IntPx> {
- val positions = mutableListOf<IntPx>()
- var current = 0.ipx
+ ): List<Int> {
+ val positions = mutableListOf<Int>()
+ var current = 0
size.forEach {
positions.add(current)
current += (it + space)
diff --git a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MenuDemo.kt b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MenuDemo.kt
index 2bf97f1..d8b32fb 100644
--- a/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MenuDemo.kt
+++ b/ui/ui-material/integration-tests/material-demos/src/main/java/androidx/ui/material/demos/MenuDemo.kt
@@ -34,10 +34,11 @@
import androidx.ui.material.IconButton
import androidx.ui.material.icons.Icons
import androidx.ui.material.icons.filled.MoreVert
-import androidx.ui.unit.IntPxPosition
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntOffset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.Position
import androidx.ui.unit.dp
+import kotlin.math.roundToInt
@Composable
fun MenuDemo() {
@@ -48,9 +49,12 @@
Modifier.fillMaxSize().wrapContentSize(
object : Alignment {
override fun align(
- size: IntPxSize,
+ size: IntSize,
layoutDirection: LayoutDirection
- ) = IntPxPosition(size.width * i / 10f, size.height * j / 10f)
+ ) = IntOffset(
+ (size.width * i / 10f).roundToInt(),
+ (size.height * j / 10f).roundToInt()
+ )
}
)
)
diff --git a/ui/ui-material/samples/src/main/java/androidx/ui/material/samples/TabSamples.kt b/ui/ui-material/samples/src/main/java/androidx/ui/material/samples/TabSamples.kt
index b2c6788..e2a5d4d 100644
--- a/ui/ui-material/samples/src/main/java/androidx/ui/material/samples/TabSamples.kt
+++ b/ui/ui-material/samples/src/main/java/androidx/ui/material/samples/TabSamples.kt
@@ -297,8 +297,8 @@
transitionDefinition {
tabPositions.forEachIndexed { index, position ->
state(index) {
- this[indicatorStart] = position.left.value.toFloat()
- this[indicatorEnd] = position.right.value.toFloat()
+ this[indicatorStart] = position.left.toFloat()
+ this[indicatorEnd] = position.right.toFloat()
this[indicatorColor] = colors[index % colors.size]
}
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
index ff9e9cb..8be4be4 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/AppBarTest.kt
@@ -36,7 +36,6 @@
import androidx.ui.text.TextStyle
import androidx.ui.unit.Density
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import androidx.ui.unit.sp
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
@@ -62,7 +61,7 @@
TopAppBar(title = { Text("Title") })
}
.assertHeightEqualsTo(appBarHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -92,7 +91,7 @@
Text("title", Modifier.onPositioned { coords: LayoutCoordinates ->
titleCoords = coords
titleLastBaselineRelativePosition =
- coords[LastBaseline]!!.value.toFloat()
+ coords[LastBaseline]!!.toFloat()
})
},
actions = {
@@ -104,11 +103,11 @@
composeTestRule.runOnIdleComposeWithDensity {
val appBarBottomEdgeY = appBarCoords!!.globalPosition.y +
- appBarCoords!!.size.height.value
+ appBarCoords!!.size.height
// Navigation icon should be 4.dp from the start
val navigationIconPositionX = navigationIconCoords!!.globalPosition.x
- val navigationIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().value.toFloat()
+ val navigationIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toFloat()
assertThat(navigationIconPositionX).isEqualTo(navigationIconExpectedPositionX)
// Navigation icon should be 4.dp from the bottom
@@ -121,7 +120,7 @@
// Title should be 72.dp from the start
val titlePositionX = titleCoords!!.globalPosition.x
// 4.dp padding for the whole app bar + 68.dp inset
- val titleExpectedPositionX = (4.dp.toIntPx() + 68.dp.toIntPx()).value.toFloat()
+ val titleExpectedPositionX = (4.dp.toIntPx() + 68.dp.toIntPx()).toFloat()
assertThat(titlePositionX).isEqualTo(titleExpectedPositionX)
// Absolute position of the baseline
@@ -129,13 +128,13 @@
titleCoords!!.globalPosition.y
// Baseline should be 20.sp from the bottom of the app bar
val titleExpectedLastBaselinePositionY =
- (appBarBottomEdgeY - 20.sp.toIntPx().value.toFloat())
+ (appBarBottomEdgeY - 20.sp.toIntPx().toFloat())
assertThat(titleLastBaselinePositionY).isEqualTo(titleExpectedLastBaselinePositionY)
// Action should be placed at the end
val actionPositionX = actionCoords!!.globalPosition.x
val actionExpectedPositionX =
- expectedActionPosition(appBarCoords!!.size.width.value.toFloat())
+ expectedActionPosition(appBarCoords!!.size.width.toFloat())
assertThat(actionPositionX).isEqualTo(actionExpectedPositionX)
// Action should be 4.dp from the bottom
@@ -170,13 +169,13 @@
// Title should now be placed 16.dp from the start, as there is no navigation icon
val titlePositionX = titleCoords!!.globalPosition.x
// 4.dp padding for the whole app bar + 12.dp inset
- val titleExpectedPositionX = (4.dp.toIntPx() + 12.dp.toIntPx()).value.toFloat()
+ val titleExpectedPositionX = (4.dp.toIntPx() + 12.dp.toIntPx()).toFloat()
assertThat(titlePositionX).isEqualTo(titleExpectedPositionX)
// Action should still be placed at the end
val actionPositionX = actionCoords!!.globalPosition.x
val actionExpectedPositionX =
- expectedActionPosition(appBarCoords!!.size.width.value.toFloat())
+ expectedActionPosition(appBarCoords!!.size.width.toFloat())
assertThat(actionPositionX).isEqualTo(actionExpectedPositionX)
}
}
@@ -208,7 +207,7 @@
BottomAppBar {}
}
.assertHeightEqualsTo(appBarHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -226,11 +225,11 @@
composeTestRule.runOnIdleComposeWithDensity {
// Child icon should be 4.dp from the start
val childIconPositionX = childCoords!!.globalPosition.x
- val childIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().value.toFloat()
+ val childIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toFloat()
assertThat(childIconPositionX).isEqualTo(childIconExpectedPositionX)
val appBarBottomEdgeY = appBarCoords!!.globalPosition.y +
- appBarCoords!!.size.height.value
+ appBarCoords!!.size.height
// Child icon should be 4.dp from the bottom
val childIconPositionY = childCoords!!.globalPosition.y
@@ -251,8 +250,8 @@
}
private fun Density.expectedActionPosition(appBarWidth: Float): Float {
- return appBarWidth - AppBarStartAndEndPadding.toIntPx().value -
- FakeIconSize.toIntPx().value
+ return appBarWidth - AppBarStartAndEndPadding.toIntPx() -
+ FakeIconSize.toIntPx()
}
private val AppBarStartAndEndPadding = 4.dp
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
index 320ba93..66ffb61 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/BottomNavigationTest.kt
@@ -104,7 +104,7 @@
Truth.assertThat(coord.size.width).isEqualTo(expectedItemWidth)
Truth.assertThat(coord.size.height).isEqualTo(expectedItemHeight)
Truth.assertThat(coord.globalPosition.x)
- .isEqualTo((expectedItemWidth * index).value.toFloat())
+ .isEqualTo((expectedItemWidth * index).toFloat())
}
}
}
@@ -141,24 +141,24 @@
composeTestRule.runOnIdleComposeWithDensity {
// Distance from the bottom to the text baseline and from the text baseline to the
// bottom of the icon
- val textBaseline = 12.dp.toIntPx().value.toFloat()
+ val textBaseline = 12.dp.toIntPx().toFloat()
// Relative position of the baseline to the top of text
- val relativeTextBaseline = textCoords[LastBaseline]!!.value.toFloat()
+ val relativeTextBaseline = textCoords[LastBaseline]!!.toFloat()
// Absolute y position of the text baseline
val absoluteTextBaseline = textCoords.globalPosition.y + relativeTextBaseline
- val itemBottom = itemCoords.size.height.value.toFloat() + itemCoords.globalPosition.y
+ val itemBottom = itemCoords.size.height.toFloat() + itemCoords.globalPosition.y
// Text baseline should be 12.dp from the bottom of the item
Truth.assertThat(absoluteTextBaseline).isEqualTo(itemBottom - textBaseline)
// The icon should be centered in the item
- val iconExpectedX = (itemCoords.size.width.value.toFloat() - iconCoords.size.width
- .value.toFloat()) / 2
+ val iconExpectedX = (itemCoords.size.width.toFloat() - iconCoords.size.width
+ .toFloat()) / 2
// The bottom of the icon is 12.dp above the text baseline
val iconExpectedY =
- absoluteTextBaseline - 12.dp.toIntPx().value.toFloat() -
- iconCoords.size.height.value
+ absoluteTextBaseline - 12.dp.toIntPx().toFloat() -
+ iconCoords.size.height
Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(iconExpectedX)
Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY)
@@ -204,10 +204,10 @@
composeTestRule.runOnIdleComposeWithDensity {
// The icon should be centered in the item
- val iconExpectedX = (itemCoords.size.width.value.toFloat() -
- iconCoords.size.width.value.toFloat()) / 2
+ val iconExpectedX = (itemCoords.size.width.toFloat() -
+ iconCoords.size.width.toFloat()) / 2
val iconExpectedY = ((itemCoords.size.height - iconCoords.size.height) / 2)
- .value.toFloat()
+ .toFloat()
Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(iconExpectedX)
Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY)
@@ -244,8 +244,8 @@
val iconExpectedY = (itemCoords.size.height - iconCoords.size.height) / 2
Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(
- iconExpectedX.value.toFloat())
- Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.value.toFloat())
+ iconExpectedX.toFloat())
+ Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.toFloat())
}
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
index fb7f056..c76740b 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
@@ -223,7 +223,7 @@
with(composeTestRule.density) {
assertThat(realSize.height)
- .isGreaterThan(36.dp.toIntPx().value.toFloat())
+ .isGreaterThan(36.dp.toIntPx().toFloat())
}
}
@@ -491,8 +491,8 @@
assertThat(contentBounds.width).isLessThan(buttonBounds.width)
assertThat(contentBounds.height).isLessThan(buttonBounds.height)
with(composeTestRule.density) {
- assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().value.toFloat())
- assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().value.toFloat())
+ assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().toFloat())
+ assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().toFloat())
}
assertWithinOnePixel(buttonBounds.center(), contentBounds.center())
}
@@ -554,7 +554,7 @@
val topLeft = childCoordinates!!.localToGlobal(Offset.Zero).x -
parentCoordinates!!.localToGlobal(Offset.Zero).x
val currentPadding = with(composeTestRule.density) {
- padding.toIntPx().value.toFloat()
+ padding.toIntPx().toFloat()
}
assertThat(currentPadding).isEqualTo(topLeft)
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/DividerUiTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/DividerUiTest.kt
index 5bc2877..3c4ee77 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/DividerUiTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/DividerUiTest.kt
@@ -19,7 +19,6 @@
import androidx.test.filters.MediumTest
import androidx.ui.test.createComposeRule
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -42,7 +41,7 @@
Divider()
}
.assertHeightEqualsTo(defaultHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -53,7 +52,7 @@
.setMaterialContentAndCollectSizes {
Divider(thickness = height)
}
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
.assertHeightEqualsTo(height)
}
@@ -68,6 +67,6 @@
Divider(startIndent = indent, thickness = height)
}
.assertHeightEqualsTo(height)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
}
\ No newline at end of file
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
index 55bd392..44a9372 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/DrawerTest.kt
@@ -26,6 +26,7 @@
import androidx.ui.core.testTag
import androidx.ui.foundation.Box
import androidx.ui.foundation.clickable
+import androidx.ui.geometry.Offset
import androidx.ui.layout.fillMaxSize
import androidx.ui.test.createComposeRule
import androidx.ui.test.doGesture
@@ -34,9 +35,7 @@
import androidx.ui.test.runOnIdleCompose
import androidx.ui.test.runOnUiThread
import androidx.ui.test.sendClick
-import androidx.ui.unit.IntPx
-import androidx.ui.unit.IntPxSize
-import androidx.ui.geometry.Offset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
import androidx.ui.unit.height
import androidx.ui.unit.width
@@ -90,7 +89,7 @@
@Test
fun modalDrawer_testEndPadding_whenOpened() {
- var size: IntPxSize? = null
+ var size: IntSize? = null
composeTestRule.setMaterialContent {
ModalDrawerLayout(DrawerState.Opened, {}, drawerContent = {
Box(Modifier.fillMaxSize().onPositioned { coords: LayoutCoordinates ->
@@ -101,7 +100,7 @@
val width = composeTestRule.displayMetrics.widthPixels
composeTestRule.runOnIdleComposeWithDensity {
- assertThat(size!!.width.value)
+ assertThat(size!!.width)
.isEqualTo(width - 56.dp.toPx().roundToInt())
}
}
@@ -145,7 +144,7 @@
@Test
@Ignore("failing in postsubmit, fix in b/148751721")
fun modalDrawer_openAndClose() {
- var contentWidth: IntPx? = null
+ var contentWidth: Int? = null
var openedLatch: CountDownLatch? = null
var closedLatch: CountDownLatch? = CountDownLatch(1)
val drawerState = mutableStateOf(DrawerState.Closed)
@@ -158,7 +157,7 @@
if (pos.x == 0.0f) {
// If fully opened, mark the openedLatch if present
openedLatch?.countDown()
- } else if (-pos.x.roundToInt() == contentWidth?.value) {
+ } else if (-pos.x.roundToInt() == contentWidth) {
// If fully closed, mark the closedLatch if present
closedLatch?.countDown()
}
@@ -239,8 +238,8 @@
@Test
@Ignore("failing in postsubmit, fix in b/148751721")
fun bottomDrawer_openAndClose() {
- var contentHeight: IntPx? = null
- var openedHeight: IntPx? = null
+ var contentHeight: Int? = null
+ var openedHeight: Int? = null
var openedLatch: CountDownLatch? = null
var closedLatch: CountDownLatch? = CountDownLatch(1)
val drawerState = mutableStateOf(DrawerState.Closed)
@@ -249,10 +248,10 @@
drawerContent = {
Box(Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
val pos = info.localToGlobal(Offset.Zero)
- if (pos.y.roundToInt() == openedHeight?.value) {
+ if (pos.y.roundToInt() == openedHeight) {
// If fully opened, mark the openedLatch if present
openedLatch?.countDown()
- } else if (pos.y.roundToInt() == contentHeight?.value) {
+ } else if (pos.y.roundToInt() == contentHeight) {
// If fully closed, mark the closedLatch if present
closedLatch?.countDown()
}
@@ -261,7 +260,7 @@
bodyContent = {
Box(Modifier.fillMaxSize().onPositioned {
contentHeight = it.size.height
- openedHeight = it.size.height * BottomDrawerOpenFraction
+ openedHeight = (it.size.height * BottomDrawerOpenFraction).roundToInt()
})
}
)
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
index 14af10b..203aec8 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ElevationOverlayTest.kt
@@ -29,9 +29,8 @@
import androidx.ui.test.createComposeRule
import androidx.ui.test.findByTag
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
@@ -43,7 +42,7 @@
class ElevationOverlayTest(private val elevation: Dp?, overlayColor: Color?) {
private val Tag = "Surface"
- private val SurfaceSize = IntPxSize(10.ipx, 10.ipx)
+ private val SurfaceSize = IntSize(10, 10)
private val expectedOverlayColor = overlayColor!!
companion object {
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/FilledTextFieldTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/FilledTextFieldTest.kt
index 2f4cd3e..359c7c7 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/FilledTextFieldTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/FilledTextFieldTest.kt
@@ -42,6 +42,7 @@
import androidx.ui.input.KeyboardType
import androidx.ui.input.PasswordVisualTransformation
import androidx.ui.input.TextInputService
+import androidx.ui.geometry.Offset
import androidx.ui.layout.Column
import androidx.ui.layout.Stack
import androidx.ui.layout.fillMaxWidth
@@ -61,10 +62,8 @@
import androidx.ui.test.sendSwipeUp
import androidx.ui.text.FirstBaseline
import androidx.ui.text.SoftwareKeyboardController
-import androidx.ui.unit.IntPxSize
-import androidx.ui.geometry.Offset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import androidx.ui.unit.sp
import com.google.common.truth.Truth.assertThat
import com.nhaarman.mockitokotlin2.any
@@ -78,6 +77,7 @@
import org.junit.runners.JUnit4
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
+import kotlin.math.roundToInt
@MediumTest
@RunWith(JUnit4::class)
@@ -184,7 +184,7 @@
@Test
fun testLabelPosition_initial_withDefaultHeight() {
- val labelSize = Ref<IntPxSize>()
+ val labelSize = Ref<IntSize>()
val labelPosition = Ref<Offset>()
testRule.setMaterialContent {
Box {
@@ -210,15 +210,15 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(labelSize.value).isNotNull()
- assertThat(labelSize.value?.height).isGreaterThan(0.ipx)
- assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(labelSize.value?.height).isGreaterThan(0)
+ assertThat(labelSize.value?.width).isGreaterThan(0)
// centered position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(labelPosition.value?.y).isEqualTo(
((ExpectedMinimumTextFieldHeight.toIntPx() - labelSize.value!!.height) / 2f)
- .value.toFloat()
+ .roundToInt().toFloat()
)
}
}
@@ -226,7 +226,7 @@
@Test
fun testLabelPosition_initial_withCustomHeight() {
val height = 80.dp
- val labelSize = Ref<IntPxSize>()
+ val labelSize = Ref<IntSize>()
val labelPosition = Ref<Offset>()
testRule.setMaterialContent {
Box {
@@ -247,21 +247,21 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(labelSize.value).isNotNull()
- assertThat(labelSize.value?.height).isGreaterThan(0.ipx)
- assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(labelSize.value?.height).isGreaterThan(0)
+ assertThat(labelSize.value?.width).isGreaterThan(0)
// centered position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(labelPosition.value?.y).isEqualTo(
- ((height.toIntPx() - labelSize.value!!.height) / 2f).value.toFloat()
+ ((height.toIntPx() - labelSize.value!!.height) / 2f).roundToInt().toFloat()
)
}
}
@Test
fun testLabelPosition_whenFocused() {
- val labelSize = Ref<IntPxSize>()
+ val labelSize = Ref<IntSize>()
val labelPosition = Ref<Offset>()
val baseline = Ref<Float>()
testRule.setMaterialContent {
@@ -275,7 +275,7 @@
labelPosition.value = it.globalPosition
labelSize.value = it.size
baseline.value =
- it[FirstBaseline]!!.value.toFloat() + labelPosition.value!!.y
+ it[FirstBaseline]!!.toFloat() + labelPosition.value!!.y
})
}
)
@@ -288,21 +288,21 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(labelSize.value).isNotNull()
- assertThat(labelSize.value?.height).isGreaterThan(0.ipx)
- assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(labelSize.value?.height).isGreaterThan(0)
+ assertThat(labelSize.value?.width).isGreaterThan(0)
// label's top position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(baseline.value).isEqualTo(
- ExpectedBaselineOffset.toIntPx().value.toFloat()
+ ExpectedBaselineOffset.toIntPx().toFloat()
)
}
}
@Test
fun testLabelPosition_whenInput() {
- val labelSize = Ref<IntPxSize>()
+ val labelSize = Ref<IntSize>()
val labelPosition = Ref<Offset>()
val baseline = Ref<Float>()
testRule.setMaterialContent {
@@ -315,7 +315,7 @@
labelPosition.value = it.globalPosition
labelSize.value = it.size
baseline.value =
- it[FirstBaseline]!!.value.toFloat() + labelPosition.value!!.y
+ it[FirstBaseline]!!.toFloat() + labelPosition.value!!.y
})
}
)
@@ -325,21 +325,21 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(labelSize.value).isNotNull()
- assertThat(labelSize.value?.height).isGreaterThan(0.ipx)
- assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(labelSize.value?.height).isGreaterThan(0)
+ assertThat(labelSize.value?.width).isGreaterThan(0)
// label's top position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(baseline.value).isEqualTo(
- ExpectedBaselineOffset.toIntPx().value.toFloat()
+ ExpectedBaselineOffset.toIntPx().toFloat()
)
}
}
@Test
fun testPlaceholderPosition_withLabel() {
- val placeholderSize = Ref<IntPxSize>()
+ val placeholderSize = Ref<IntSize>()
val placeholderPosition = Ref<Offset>()
val placeholderBaseline = Ref<Float>()
testRule.setMaterialContent {
@@ -356,8 +356,7 @@
placeholderPosition.value = it.globalPosition
placeholderSize.value = it.size
placeholderBaseline.value =
- it[FirstBaseline]!!.value.toFloat() +
- placeholderPosition.value!!.y
+ it[FirstBaseline]!!.toFloat() + placeholderPosition.value!!.y
})
}
)
@@ -369,23 +368,23 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(placeholderSize.value).isNotNull()
- assertThat(placeholderSize.value?.height).isGreaterThan(0.ipx)
- assertThat(placeholderSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(placeholderSize.value?.height).isGreaterThan(0)
+ assertThat(placeholderSize.value?.width).isGreaterThan(0)
// placeholder's position
assertThat(placeholderPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(placeholderBaseline.value)
.isEqualTo(
- 60.dp.toIntPx().value.toFloat() -
- ExpectedLastBaselineOffset.toIntPx().value.toFloat()
+ 60.dp.toIntPx().toFloat() -
+ ExpectedLastBaselineOffset.toIntPx().toFloat()
)
}
}
@Test
fun testPlaceholderPosition_whenNoLabel() {
- val placeholderSize = Ref<IntPxSize>()
+ val placeholderSize = Ref<IntSize>()
val placeholderPosition = Ref<Offset>()
val placeholderBaseline = Ref<Float>()
val height = 60.dp
@@ -401,8 +400,7 @@
placeholderPosition.value = it.globalPosition
placeholderSize.value = it.size
placeholderBaseline.value =
- it[FirstBaseline]!!.value.toFloat() +
- placeholderPosition.value!!.y
+ it[FirstBaseline]!!.toFloat() + placeholderPosition.value!!.y
})
}
)
@@ -414,21 +412,21 @@
testRule.runOnIdleComposeWithDensity {
// size
assertThat(placeholderSize.value).isNotNull()
- assertThat(placeholderSize.value?.height).isGreaterThan(0.ipx)
- assertThat(placeholderSize.value?.width).isGreaterThan(0.ipx)
+ assertThat(placeholderSize.value?.height).isGreaterThan(0)
+ assertThat(placeholderSize.value?.width).isGreaterThan(0)
// centered position
assertThat(placeholderPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
assertThat(placeholderPosition.value?.y).isEqualTo(
- ((height.toIntPx() - placeholderSize.value!!.height) / 2f).value.toFloat()
+ ((height.toIntPx() - placeholderSize.value!!.height) / 2f).roundToInt().toFloat()
)
}
}
@Test
fun testNoPlaceholder_whenInputNotEmpty() {
- val placeholderSize = Ref<IntPxSize>()
+ val placeholderSize = Ref<IntSize>()
val placeholderPosition = Ref<Offset>()
testRule.setMaterialContent {
Box {
@@ -483,9 +481,9 @@
val textFieldWidth = 300.dp
val size = 30.dp
val leadingPosition = Ref<Offset>()
- val leadingSize = Ref<IntPxSize>()
+ val leadingSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
testRule.setMaterialContent {
FilledTextField(
@@ -510,20 +508,22 @@
testRule.runOnIdleComposeWithDensity {
// leading
- assertThat(leadingSize.value).isEqualTo(IntPxSize(size.toIntPx(), size.toIntPx()))
- assertThat(leadingPosition.value?.x).isEqualTo(IconPadding.toIntPx().value.toFloat())
+ assertThat(leadingSize.value).isEqualTo(IntSize(size.toIntPx(), size.toIntPx()))
+ assertThat(leadingPosition.value?.x).isEqualTo(IconPadding.toIntPx().toFloat())
assertThat(leadingPosition.value?.y).isEqualTo(
- ((textFieldHeight.toIntPx() - leadingSize.value!!.height) / 2f).value.toFloat()
+ ((textFieldHeight.toIntPx() - leadingSize.value!!.height) / 2f).roundToInt()
+ .toFloat()
)
// trailing
- assertThat(trailingSize.value).isEqualTo(IntPxSize(size.toIntPx(), size.toIntPx()))
+ assertThat(trailingSize.value).isEqualTo(IntSize(size.toIntPx(), size.toIntPx()))
assertThat(trailingPosition.value?.x).isEqualTo(
(textFieldWidth.toIntPx() - IconPadding.toIntPx() - trailingSize.value!!.width)
- .value.toFloat()
+ .toFloat()
)
- assertThat(trailingPosition.value?.y).isEqualTo(
- ((textFieldHeight.toIntPx() - trailingSize.value!!.height) / 2f).value.toFloat()
- )
+ assertThat(trailingPosition.value?.y)
+ .isEqualTo(((textFieldHeight.toIntPx() - trailingSize.value!!.height) / 2f)
+ .roundToInt().toFloat()
+ )
}
}
@@ -551,7 +551,7 @@
testRule.runOnIdleComposeWithDensity {
assertThat(labelPosition.value?.x).isEqualTo(
- (ExpectedPadding.toIntPx() + IconPadding.toIntPx() + iconSize.toIntPx()).value
+ (ExpectedPadding.toIntPx() + IconPadding.toIntPx() + iconSize.toIntPx())
.toFloat()
)
}
@@ -580,7 +580,7 @@
testRule.runOnIdleComposeWithDensity {
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().value.toFloat()
+ ExpectedPadding.toIntPx().toFloat()
)
}
}
@@ -836,8 +836,8 @@
val tag = "testTag"
val scrollerPosition = TextFieldScrollerPosition()
- val parentSize = 200.ipx
- val textFieldSize = 50.ipx
+ val parentSize = 200
+ val textFieldSize = 50
with(testRule.density) {
testRule.setContent {
@@ -863,7 +863,7 @@
findByTag(tag)
.captureToBitmap()
- .assertPixels(expectedSize = IntPxSize(parentSize, parentSize)) { position ->
+ .assertPixels(expectedSize = IntSize(parentSize, parentSize)) { position ->
if (position.x > textFieldSize && position.y > textFieldSize) Color.White else null
}
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/FloatingActionButtonTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/FloatingActionButtonTest.kt
index 5e25dac..1814e90 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/FloatingActionButtonTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/FloatingActionButtonTest.kt
@@ -116,8 +116,8 @@
)
}
with(composeTestRule.density) {
- assertThat(size.height.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx().value)
- assertThat(size.width.roundToInt().toFloat()).isAtLeast(48.dp.toIntPx().value)
+ assertThat(size.height.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx())
+ assertThat(size.width.roundToInt().toFloat()).isAtLeast(48.dp.toIntPx())
}
}
@@ -131,8 +131,8 @@
)
}
with(composeTestRule.density) {
- assertThat(size.width.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx().value)
- assertThat(size.height.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx().value)
+ assertThat(size.width.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx())
+ assertThat(size.height.roundToInt().toFloat()).isEqualTo(48.dp.toIntPx())
}
}
@@ -223,8 +223,8 @@
assertThat(contentBounds.width).isLessThan(buttonBounds.width)
assertThat(contentBounds.height).isLessThan(buttonBounds.height)
with(composeTestRule.density) {
- assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().value.toFloat())
- assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().value.toFloat())
+ assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().toFloat())
+ assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().toFloat())
}
assertWithinOnePixel(buttonBounds.center(), contentBounds.center())
}
@@ -254,8 +254,8 @@
assertThat(contentBounds.width).isLessThan(buttonBounds.width)
assertThat(contentBounds.height).isLessThan(buttonBounds.height)
with(composeTestRule.density) {
- assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().value.toFloat())
- assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().value.toFloat())
+ assertThat(contentBounds.width).isEqualTo(2.dp.toIntPx().toFloat())
+ assertThat(contentBounds.height).isEqualTo(2.dp.toIntPx().toFloat())
}
assertWithinOnePixel(buttonBounds.center(), contentBounds.center())
}
@@ -290,14 +290,14 @@
val textBounds = textCoordinates!!.boundsInRoot
val iconBounds = iconCoordinates!!.boundsInRoot
with(composeTestRule.density) {
- assertThat(textBounds.width).isEqualTo(2.dp.toIntPx().value.toFloat())
- assertThat(textBounds.height).isEqualTo(2.dp.toIntPx().value.toFloat())
- assertThat(iconBounds.width).isEqualTo(10.dp.toIntPx().value.toFloat())
- assertThat(iconBounds.height).isEqualTo(10.dp.toIntPx().value.toFloat())
+ assertThat(textBounds.width).isEqualTo(2.dp.toIntPx().toFloat())
+ assertThat(textBounds.height).isEqualTo(2.dp.toIntPx().toFloat())
+ assertThat(iconBounds.width).isEqualTo(10.dp.toIntPx().toFloat())
+ assertThat(iconBounds.height).isEqualTo(10.dp.toIntPx().toFloat())
assertWithinOnePixel(buttonBounds.center().y, iconBounds.center().y)
assertWithinOnePixel(buttonBounds.center().y, textBounds.center().y)
- val halfPadding = 6.dp.toIntPx().value.toFloat()
+ val halfPadding = 6.dp.toIntPx().toFloat()
assertWithinOnePixel(
iconBounds.center().x + iconBounds.width / 2 + halfPadding,
textBounds.center().x - textBounds.width / 2 - halfPadding
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
index 56c5ee5..e061541 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconButtonTest.kt
@@ -37,6 +37,7 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import kotlin.math.roundToInt
@LargeTest
@RunWith(JUnit4::class)
@@ -78,8 +79,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
// Icon should be centered inside the IconButton
- Truth.assertThat(iconX).isEqualTo(12.dp.toIntPx().value.toFloat())
- Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().value.toFloat())
+ Truth.assertThat(iconX).isEqualTo((24.dp.toIntPx() / 2f).roundToInt().toFloat())
+ Truth.assertThat(iconY).isEqualTo((24.dp.toIntPx() / 2f).roundToInt().toFloat())
}
}
@@ -103,8 +104,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
- val expectedX = ((48.dp - width) / 2).toIntPx().value.toFloat()
- val expectedY = ((48.dp - height) / 2).toIntPx().value.toFloat()
+ val expectedX = ((48.dp.toIntPx() - width.toIntPx()) / 2f).roundToInt().toFloat()
+ val expectedY = ((48.dp.toIntPx() - height.toIntPx()) / 2f).roundToInt().toFloat()
// Icon should be centered inside the IconButton
Truth.assertThat(iconX).isEqualTo(expectedX)
Truth.assertThat(iconY).isEqualTo(expectedY)
@@ -142,8 +143,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
// Icon should be centered inside the IconButton
- Truth.assertThat(iconX).isEqualTo(12.dp.toIntPx().value.toFloat())
- Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().value.toFloat())
+ Truth.assertThat(iconX).isEqualTo((24.dp.toIntPx() / 2f).roundToInt().toFloat())
+ Truth.assertThat(iconY).isEqualTo((24.dp.toIntPx() / 2f).roundToInt().toFloat())
}
}
@@ -166,8 +167,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
- val expectedX = ((48.dp - width) / 2).toIntPx().value.toFloat()
- val expectedY = ((48.dp - height) / 2).toIntPx().value.toFloat()
+ val expectedX = ((48.dp.toIntPx() - width.toIntPx()) / 2f).roundToInt().toFloat()
+ val expectedY = ((48.dp.toIntPx() - height.toIntPx()) / 2f).roundToInt().toFloat()
// Icon should be centered inside the IconButton
Truth.assertThat(iconX).isEqualTo(expectedX)
Truth.assertThat(iconY).isEqualTo(expectedY)
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconTest.kt
index 378a760..6bf1b54 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/IconTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/IconTest.kt
@@ -72,7 +72,7 @@
composeTestRule
.setMaterialContentAndCollectSizes {
val dummyImage = with(DensityAmbient.current) {
- ImageAsset(width.toIntPx().value, height.toIntPx().value)
+ ImageAsset(width.toIntPx(), height.toIntPx())
}
Icon(dummyImage)
@@ -89,7 +89,7 @@
composeTestRule
.setMaterialContentAndCollectSizes {
val dummyImage = with(DensityAmbient.current) {
- ImageAsset(width.toIntPx().value, height.toIntPx().value)
+ ImageAsset(width.toIntPx(), height.toIntPx())
}
Icon(dummyImage)
@@ -119,7 +119,7 @@
composeTestRule
.setMaterialContentAndCollectSizes {
val dummyImage = with(DensityAmbient.current) {
- ImageAsset(width.toIntPx().value, height.toIntPx().value)
+ ImageAsset(width.toIntPx(), height.toIntPx())
}
val imagePainter = ImagePainter(dummyImage)
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
index 5584105..b4fef6f 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
@@ -25,13 +25,12 @@
import androidx.ui.foundation.Box
import androidx.ui.foundation.Image
import androidx.ui.foundation.Text
+import androidx.ui.geometry.Offset
import androidx.ui.graphics.ImageAsset
import androidx.ui.test.createComposeRule
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPxSize
-import androidx.ui.geometry.Offset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -59,7 +58,7 @@
ListItem(text = "Primary text")
}
.assertHeightEqualsTo(expectedHeightNoIcon)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -71,7 +70,7 @@
ListItem(text = "Primary text", icon = icon24x24)
}
.assertHeightEqualsTo(expectedHeightSmallIcon)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -83,7 +82,7 @@
ListItem(text = "Primary text", icon = icon56x56)
}
.assertHeightEqualsTo(expectedHeightLargeIcon)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -95,7 +94,7 @@
ListItem(text = "Primary text", secondaryText = "Secondary text")
}
.assertHeightEqualsTo(expectedHeightNoIcon)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -112,7 +111,7 @@
)
}
.assertHeightEqualsTo(expectedHeightWithIcon)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -128,7 +127,7 @@
)
}
.assertHeightEqualsTo(expectedHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -144,7 +143,7 @@
)
}
.assertHeightEqualsTo(expectedHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -161,7 +160,7 @@
)
}
.assertHeightEqualsTo(expectedHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -178,7 +177,7 @@
)
}
.assertHeightEqualsTo(expectedHeight)
- .assertWidthEqualsTo { dm.widthPixels.ipx }
+ .assertWidthEqualsTo { dm.widthPixels }
}
@Test
@@ -188,9 +187,9 @@
val expectedRightPadding = 16.dp
val textPosition = Ref<Offset>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -203,17 +202,18 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx()
- .value.toFloat())
+ .toFloat())
assertThat(textPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).value.toFloat()
+ ((listItemHeight.toIntPx() - textSize.value!!.height) / 2f).roundToInt().toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels - trailingSize.value!!.width.value -
- expectedRightPadding.toIntPx().value.toFloat()
+ dm.widthPixels - trailingSize.value!!.width -
+ expectedRightPadding.toIntPx().toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).value.toFloat()
+ ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2f).roundToInt()
+ .toFloat()
)
}
}
@@ -225,9 +225,9 @@
val expectedTextLeftPadding = 32.dp
val textPosition = Ref<Offset>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val iconPosition = Ref<Offset>()
- val iconSize = Ref<IntPxSize>()
+ val iconSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -238,18 +238,18 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(iconPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - iconSize.value!!.height) / 2).value.toFloat()
+ ((listItemHeight.toIntPx() - iconSize.value!!.height) / 2f).roundToInt().toFloat()
)
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedTextLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedTextLeftPadding.toIntPx().toFloat()
)
assertThat(textPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).value.toFloat()
+ ((listItemHeight.toIntPx() - textSize.value!!.height) / 2f).roundToInt().toFloat()
)
}
}
@@ -263,13 +263,13 @@
val textPosition = Ref<Offset>()
val textBaseline = Ref<Float>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val secondaryTextPosition = Ref<Offset>()
val secondaryTextBaseline = Ref<Float>()
- val secondaryTextSize = Ref<IntPxSize>()
+ val secondaryTextSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
val trailingBaseline = Ref<Float>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -294,25 +294,25 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat() +
- expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels - trailingSize.value!!.width.value -
- expectedRightPadding.toIntPx().value.toFloat()
+ dm.widthPixels - trailingSize.value!!.width -
+ expectedRightPadding.toIntPx().toFloat()
)
assertThat(trailingBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat()
)
}
}
@@ -327,12 +327,12 @@
val textPosition = Ref<Offset>()
val textBaseline = Ref<Float>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val secondaryTextPosition = Ref<Offset>()
val secondaryTextBaseline = Ref<Float>()
- val secondaryTextSize = Ref<IntPxSize>()
+ val secondaryTextSize = Ref<IntSize>()
val iconPosition = Ref<Offset>()
- val iconSize = Ref<IntPxSize>()
+ val iconSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -357,26 +357,26 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() + iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() + iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat() +
- expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().value.toFloat()
+ expectedIconTopPadding.toIntPx().toFloat()
)
}
}
@@ -393,14 +393,14 @@
val textPosition = Ref<Offset>()
val textBaseline = Ref<Float>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val secondaryTextPosition = Ref<Offset>()
val secondaryTextBaseline = Ref<Float>()
- val secondaryTextSize = Ref<IntPxSize>()
+ val secondaryTextSize = Ref<IntSize>()
val iconPosition = Ref<Offset>()
- val iconSize = Ref<IntPxSize>()
+ val iconSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -428,34 +428,34 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() + iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() + iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat() +
- expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().value.toFloat()
+ expectedIconTopPadding.toIntPx().toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels - trailingSize.value!!.width.value -
- expectedRightPadding.toIntPx().value.toFloat()
+ dm.widthPixels - trailingSize.value!!.width -
+ expectedRightPadding.toIntPx().toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).value.toFloat()
+ ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).toFloat()
)
}
}
@@ -471,14 +471,14 @@
val textPosition = Ref<Offset>()
val textBaseline = Ref<Float>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val secondaryTextPosition = Ref<Offset>()
val secondaryTextBaseline = Ref<Float>()
- val secondaryTextSize = Ref<IntPxSize>()
+ val secondaryTextSize = Ref<IntSize>()
val iconPosition = Ref<Offset>()
- val iconSize = Ref<IntPxSize>()
+ val iconSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -507,32 +507,31 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() + iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() + iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() + iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() + iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().value.toFloat() +
- expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
+ expectedTextBaseline.toIntPx().toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().toFloat()
)
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx()
- .value.toFloat())
+ assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toFloat())
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().value.toFloat()
+ expectedIconTopPadding.toIntPx().toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
- expectedRightPadding.toIntPx().value.toFloat()
+ dm.widthPixels - trailingSize.value!!.width.toFloat() -
+ expectedRightPadding.toIntPx().toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().value.toFloat()
+ expectedIconTopPadding.toIntPx().toFloat()
)
}
}
@@ -549,17 +548,17 @@
val textPosition = Ref<Offset>()
val textBaseline = Ref<Float>()
- val textSize = Ref<IntPxSize>()
+ val textSize = Ref<IntSize>()
val overlineTextPosition = Ref<Offset>()
val overlineTextBaseline = Ref<Float>()
- val overlineTextSize = Ref<IntPxSize>()
+ val overlineTextSize = Ref<IntSize>()
val secondaryTextPosition = Ref<Offset>()
val secondaryTextBaseline = Ref<Float>()
- val secondaryTextSize = Ref<IntPxSize>()
+ val secondaryTextSize = Ref<IntSize>()
val iconPosition = Ref<Offset>()
- val iconSize = Ref<IntPxSize>()
+ val iconSize = Ref<IntSize>()
val trailingPosition = Ref<Offset>()
- val trailingSize = Ref<IntPxSize>()
+ val trailingSize = Ref<IntSize>()
val trailingBaseline = Ref<Float>()
composeTestRule.setMaterialContent {
Box {
@@ -608,45 +607,45 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().value.toFloat() +
- expectedTextBaselineOffset.toIntPx().value.toFloat()
+ expectedOverlineBaseline.toIntPx().toFloat() +
+ expectedTextBaselineOffset.toIntPx().toFloat()
)
assertThat(overlineTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(overlineTextBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().value.toFloat()
+ expectedOverlineBaseline.toIntPx().toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat() +
- iconSize.value!!.width.value +
- expectedContentLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat() +
+ iconSize.value!!.width +
+ expectedContentLeftPadding.toIntPx().toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().value.toFloat() +
- expectedTextBaselineOffset.toIntPx().value.toFloat() +
- expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
+ expectedOverlineBaseline.toIntPx().toFloat() +
+ expectedTextBaselineOffset.toIntPx().toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().value.toFloat()
+ expectedLeftPadding.toIntPx().toFloat()
)
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().value.toFloat()
+ expectedIconTopPadding.toIntPx().toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels - trailingSize.value!!.width.value -
- expectedRightPadding.toIntPx().value.toFloat()
+ dm.widthPixels - trailingSize.value!!.width -
+ expectedRightPadding.toIntPx().toFloat()
)
assertThat(trailingBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().value.toFloat()
+ expectedOverlineBaseline.toIntPx().toFloat()
)
}
}
@@ -655,11 +654,11 @@
private fun saveLayout(
coords: Ref<Offset>,
- size: Ref<IntPxSize>,
+ size: Ref<IntSize>,
baseline: Ref<Float> = Ref()
): Modifier = Modifier.onPositioned { coordinates: LayoutCoordinates ->
coords.value = coordinates.localToGlobal(Offset.Zero)
- baseline.value = coordinates[FirstBaseline]?.value?.toFloat()?.let {
+ baseline.value = coordinates[FirstBaseline]?.toFloat()?.let {
it + coords.value!!.y
}
size.value = coordinates.size
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/MenuTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/MenuTest.kt
index 7ba6686..93df35d 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/MenuTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/MenuTest.kt
@@ -21,6 +21,7 @@
import androidx.compose.mutableStateOf
import androidx.compose.setValue
import androidx.test.filters.MediumTest
+import androidx.ui.core.DensityAmbient
import androidx.ui.core.LayoutDirection
import androidx.ui.core.Modifier
import androidx.ui.core.testTag
@@ -44,11 +45,10 @@
import androidx.ui.test.runOnIdleCompose
import androidx.ui.test.waitForIdle
import androidx.ui.unit.Density
-import androidx.ui.unit.IntPxPosition
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntOffset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.Position
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -100,18 +100,20 @@
@Test
fun menu_hasExpectedSize() {
composeTestRule.setContent {
- DropdownMenu(
- expanded = true,
- toggle = {
- Box(Modifier.size(20.dp).drawBackground(Color.Blue))
- },
- >
- ) {
- Semantics(properties = { testTag = "MenuContent1" }, container = true) {
- Box(Modifier.preferredSize(70.dp))
- }
- Semantics(properties = { testTag = "MenuContent2" }, container = true) {
- Box(Modifier.preferredSize(130.dp))
+ with(DensityAmbient.current) {
+ DropdownMenu(
+ expanded = true,
+ toggle = {
+ Box(Modifier.size(20.toDp()).drawBackground(Color.Blue))
+ },
+ >
+ ) {
+ Semantics(properties = { testTag = "MenuContent1" }, container = true) {
+ Box(Modifier.preferredSize(70.toDp()))
+ }
+ Semantics(properties = { testTag = "MenuContent2" }, container = true) {
+ Box(Modifier.preferredSize(130.toDp()))
+ }
}
}
}
@@ -123,8 +125,8 @@
hasAnyChildThat(hasTestTag("MenuContent2"))
).assertExists().fetchSemanticsNode()
with(composeTestRule.density) {
- assertThat(node.size.width).isEqualTo(130.dp.toIntPx() + MenuElevation.toIntPx() * 2)
- assertThat(node.size.height).isEqualTo(200.dp.toIntPx() +
+ assertThat(node.size.width).isEqualTo(130 + MenuElevation.toIntPx() * 2)
+ assertThat(node.size.height).isEqualTo(200 +
DropdownMenuVerticalPadding.toIntPx() * 2 + MenuElevation.toIntPx() * 2
)
}
@@ -139,12 +141,12 @@
widthPixels = screenWidth
heightPixels = screenHeight
}
- val anchorPosition = IntPxPosition(100.ipx, 200.ipx)
- val anchorSize = IntPxSize(10.ipx, 20.ipx)
+ val anchorPosition = IntOffset(100, 200)
+ val anchorSize = IntSize(10, 20)
val inset = with(density) { MenuElevation.toIntPx() }
val offsetX = 20
val offsetY = 40
- val popupSize = IntPxSize(50.ipx, 80.ipx)
+ val popupSize = IntSize(50, 80)
val ltrPosition = DropdownMenuPositionProvider(
Position(offsetX.dp, offsetY.dp),
@@ -158,10 +160,10 @@
)
assertThat(ltrPosition.x).isEqualTo(
- anchorPosition.x + anchorSize.width - inset + offsetX.ipx
+ anchorPosition.x + anchorSize.width - inset + offsetX
)
assertThat(ltrPosition.y).isEqualTo(
- anchorPosition.y + anchorSize.height - inset + offsetY.ipx
+ anchorPosition.y + anchorSize.height - inset + offsetY
)
val rtlPosition = DropdownMenuPositionProvider(
@@ -176,10 +178,10 @@
)
assertThat(rtlPosition.x).isEqualTo(
- anchorPosition.x - popupSize.width + inset - offsetX.ipx
+ anchorPosition.x - popupSize.width + inset - offsetX
)
assertThat(rtlPosition.y).isEqualTo(
- anchorPosition.y + anchorSize.height - inset + offsetY.ipx
+ anchorPosition.y + anchorSize.height - inset + offsetY
)
}
@@ -192,13 +194,13 @@
widthPixels = screenWidth
heightPixels = screenHeight
}
- val anchorPosition = IntPxPosition(450.ipx, 950.ipx)
- val anchorPositionRtl = IntPxPosition(50.ipx, 950.ipx)
- val anchorSize = IntPxSize(10.ipx, 20.ipx)
+ val anchorPosition = IntOffset(450, 950)
+ val anchorPositionRtl = IntOffset(50, 950)
+ val anchorSize = IntSize(10, 20)
val inset = with(density) { MenuElevation.toIntPx() }
val offsetX = 20
val offsetY = 40
- val popupSize = IntPxSize(150.ipx, 80.ipx)
+ val popupSize = IntSize(150, 80)
val ltrPosition = DropdownMenuPositionProvider(
Position(offsetX.dp, offsetY.dp),
@@ -212,10 +214,10 @@
)
assertThat(ltrPosition.x).isEqualTo(
- anchorPosition.x - popupSize.width + inset - offsetX.ipx
+ anchorPosition.x - popupSize.width + inset - offsetX
)
assertThat(ltrPosition.y).isEqualTo(
- anchorPosition.y - popupSize.height + inset - offsetY.ipx
+ anchorPosition.y - popupSize.height + inset - offsetY
)
val rtlPosition = DropdownMenuPositionProvider(
@@ -230,10 +232,10 @@
)
assertThat(rtlPosition.x).isEqualTo(
- anchorPositionRtl.x + anchorSize.width - inset + offsetX.ipx
+ anchorPositionRtl.x + anchorSize.width - inset + offsetX
)
assertThat(rtlPosition.y).isEqualTo(
- anchorPositionRtl.y - popupSize.height + inset - offsetY.ipx
+ anchorPositionRtl.y - popupSize.height + inset - offsetY
)
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
index 1554075..4efacb2 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
@@ -32,6 +32,7 @@
import androidx.ui.foundation.Icon
import androidx.ui.foundation.Text
import androidx.ui.foundation.drawBackground
+import androidx.ui.geometry.Offset
import androidx.ui.graphics.Color
import androidx.ui.layout.DpConstraints
import androidx.ui.layout.InnerPadding
@@ -51,8 +52,7 @@
import androidx.ui.test.runOnUiThread
import androidx.ui.test.sendSwipeLeft
import androidx.ui.test.sendSwipeRight
-import androidx.ui.unit.IntPxSize
-import androidx.ui.geometry.Offset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
import androidx.ui.unit.toSize
import androidx.ui.unit.width
@@ -106,7 +106,7 @@
@Test
fun scaffold_AppbarAndContent_inColumn() {
var appbarPosition: Offset = Offset.Zero
- lateinit var appbarSize: IntPxSize
+ lateinit var appbarSize: IntSize
var contentPosition: Offset = Offset.Zero
composeTestRule.setMaterialContent {
Scaffold(
@@ -130,16 +130,16 @@
)
}
}
- assertThat(appbarPosition.y + appbarSize.height.value.toFloat())
+ assertThat(appbarPosition.y + appbarSize.height.toFloat())
.isEqualTo(contentPosition.y)
}
@Test
fun scaffold_bottomBarAndContent_inStack() {
var appbarPosition: Offset = Offset.Zero
- lateinit var appbarSize: IntPxSize
+ lateinit var appbarSize: IntSize
var contentPosition: Offset = Offset.Zero
- lateinit var contentSize: IntPxSize
+ lateinit var contentSize: IntSize
composeTestRule.setMaterialContent {
Scaffold(
bottomBar = {
@@ -165,8 +165,8 @@
)
}
}
- val appBarBottom = appbarPosition.y + appbarSize.height.value
- val contentBottom = contentPosition.y + contentSize.height.value
+ val appBarBottom = appbarPosition.y + appbarSize.height
+ val contentBottom = contentPosition.y + contentSize.height
assertThat(appBarBottom).isEqualTo(contentBottom)
}
@@ -266,7 +266,7 @@
@Test
fun scaffold_centerDockedFab_position() {
var fabPosition: Offset = Offset.Zero
- lateinit var fabSize: IntPxSize
+ lateinit var fabSize: IntSize
var bottomBarPosition: Offset = Offset.Zero
composeTestRule.setContent {
Scaffold(
@@ -297,14 +297,14 @@
Text("body")
}
}
- val expectedFabY = bottomBarPosition.y - (fabSize.height / 2).value
+ val expectedFabY = bottomBarPosition.y - (fabSize.height / 2)
assertThat(fabPosition.y).isEqualTo(expectedFabY)
}
@Test
fun scaffold_endDockedFab_position() {
var fabPosition: Offset = Offset.Zero
- lateinit var fabSize: IntPxSize
+ lateinit var fabSize: IntSize
var bottomBarPosition: Offset = Offset.Zero
composeTestRule.setContent {
Scaffold(
@@ -336,7 +336,7 @@
Text("body")
}
}
- val expectedFabY = bottomBarPosition.y - (fabSize.height / 2).value
+ val expectedFabY = bottomBarPosition.y - (fabSize.height / 2)
assertThat(fabPosition.y).isEqualTo(expectedFabY)
}
@@ -379,7 +379,7 @@
@Test
fun scaffold_geometry_fabSize() {
- lateinit var fabSize: IntPxSize
+ lateinit var fabSize: IntSize
val showFab = mutableStateOf(true)
val scaffoldState = ScaffoldState()
composeTestRule.setContent {
@@ -417,7 +417,7 @@
@Test
fun scaffold_geometry_bottomBarSize() {
- lateinit var bottomBarSize: IntPxSize
+ lateinit var bottomBarSize: IntSize
val showBottom = mutableStateOf(true)
val scaffoldState = ScaffoldState()
composeTestRule.setContent {
@@ -454,7 +454,7 @@
@Test
fun scaffold_geometry_topBarSize() {
- lateinit var topBarSize: IntPxSize
+ lateinit var topBarSize: IntSize
val showTop = mutableStateOf(true)
val scaffoldState = ScaffoldState()
composeTestRule.setContent {
@@ -491,7 +491,7 @@
@Test
fun scaffold_innerPadding_lambdaParam() {
- lateinit var bottomBarSize: IntPxSize
+ lateinit var bottomBarSize: IntSize
lateinit var innerPadding: InnerPadding
val scaffoldState = ScaffoldState()
@@ -522,7 +522,7 @@
@Test
fun scaffold_bottomBar_geometryPropagation() {
- lateinit var bottomBarSize: IntPxSize
+ lateinit var bottomBarSize: IntSize
lateinit var geometry: ScaffoldGeometry
val scaffoldState = ScaffoldState()
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
index b84cefa..99fb902 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
@@ -31,6 +31,7 @@
import androidx.ui.core.testTag
import androidx.ui.foundation.Text
import androidx.ui.foundation.shape.corner.CutCornerShape
+import androidx.ui.geometry.Offset
import androidx.ui.graphics.Color
import androidx.ui.graphics.compositeOver
import androidx.ui.layout.DpConstraints
@@ -41,10 +42,7 @@
import androidx.ui.test.doClick
import androidx.ui.test.findByTag
import androidx.ui.test.findByText
-import androidx.ui.unit.IntPx
-import androidx.ui.geometry.Offset
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -106,11 +104,11 @@
assertThat(textCoords).isNotNull()
textCoords?.let {
with(composeTestRule.density) {
- assertThat(it[FirstBaseline]).isNotEqualTo(IntPx.Zero)
+ assertThat(it[FirstBaseline]).isNotEqualTo(0)
assertThat(it[FirstBaseline])
.isEqualTo(it[LastBaseline])
// TODO(aelias): Remove 'parentCoordinates!!' when Semantics no longer using PassThroughLayout
- assertThat(it.parentCoordinates!!.positionInParent.y.roundToInt().ipx +
+ assertThat(it.parentCoordinates!!.positionInParent.y.roundToInt() +
it[FirstBaseline]!!)
.isEqualTo(30.dp.toIntPx())
}
@@ -165,14 +163,14 @@
with(composeTestRule.density) {
val buttonTextPos =
localSnackCoords.childToLocal(localButtonTextCoords, Offset.Zero)
- assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
- assertThat(localButtonTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
+ assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(0)
+ assertThat(localButtonTextCoords[FirstBaseline]).isNotEqualTo(0)
assertThat(
- localTextCoords.globalPosition.y.roundToInt().ipx +
+ localTextCoords.globalPosition.y.roundToInt() +
localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
assertThat(
- buttonTextPos.y.roundToInt().ipx + localButtonTextCoords[FirstBaseline]!!
+ buttonTextPos.y.roundToInt() + localButtonTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
}
}
@@ -197,12 +195,12 @@
assertThat(textCoords).isNotNull()
textCoords?.let {
with(composeTestRule.density) {
- assertThat(it[FirstBaseline]).isNotEqualTo(IntPx.Zero)
- assertThat(it[LastBaseline]).isNotEqualTo(IntPx.Zero)
+ assertThat(it[FirstBaseline]).isNotEqualTo(0)
+ assertThat(it[LastBaseline]).isNotEqualTo(0)
assertThat(it[FirstBaseline]).isNotEqualTo(it[LastBaseline])
// TODO(aelias): Remove 'parentCoordinates!!' when Semantics no longer using PassThroughLayout
assertThat(
- it.parentCoordinates!!.positionInParent.y.roundToInt().ipx +
+ it.parentCoordinates!!.positionInParent.y.roundToInt() +
it[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
}
@@ -249,19 +247,19 @@
localSnackCoords.childToLocal(localButtonCoords, Offset.Zero)
val buttonCenter =
buttonPositionInSnack.y.roundToInt() +
- (localButtonCoords.size.height / 2).value.toFloat()
+ (localButtonCoords.size.height / 2).toFloat()
- assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
- assertThat(localTextCoords[LastBaseline]).isNotEqualTo(IntPx.Zero)
+ assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(0)
+ assertThat(localTextCoords[LastBaseline]).isNotEqualTo(0)
assertThat(localTextCoords[FirstBaseline])
.isNotEqualTo(localTextCoords[LastBaseline])
assertThat(
- localTextCoords.globalPosition.y.roundToInt().ipx +
+ localTextCoords.globalPosition.y.roundToInt() +
localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
assertThat(buttonCenter).isEqualTo(
- (localSnackCoords.size.height / 2).value.toFloat()
+ (localSnackCoords.size.height / 2).toFloat()
)
}
}
@@ -308,22 +306,22 @@
localSnackCoords.childToLocal(localTextCoords, Offset.Zero)
assertThat(
- textPositionInSnack.y.roundToInt().ipx + localTextCoords[FirstBaseline]!!
+ textPositionInSnack.y.roundToInt() + localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
assertThat(
- buttonPositionInSnack.y.roundToInt().ipx -
- textPositionInSnack.y.roundToInt().ipx -
+ buttonPositionInSnack.y.roundToInt() -
+ textPositionInSnack.y.roundToInt() -
localTextCoords[LastBaseline]!!
).isEqualTo(18.dp.toIntPx())
assertThat(
- localSnackCoords.size.height - buttonPositionInSnack.y.roundToInt().ipx -
+ localSnackCoords.size.height - buttonPositionInSnack.y.roundToInt() -
localButtonCoords.size.height
).isEqualTo(8.dp.toIntPx())
assertThat(
- localSnackCoords.size.width - buttonPositionInSnack.x.roundToInt().ipx -
+ localSnackCoords.size.width - buttonPositionInSnack.x.roundToInt() -
localButtonCoords.size.width
).isEqualTo(8.dp.toIntPx())
}
diff --git a/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
index 043f69e..35dd52a 100644
--- a/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
+++ b/ui/ui-material/src/androidTest/java/androidx/ui/material/TabTest.kt
@@ -150,7 +150,7 @@
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(Offset.Zero).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).value.toFloat()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toFloat()
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
tabRowWidth to tabRowHeight
@@ -164,12 +164,12 @@
runOnIdleCompose {
with(composeTestRule.density) {
val indicatorPositionX = indicatorCoords.localToGlobal(Offset.Zero).x
- val expectedPositionX = (tabRowWidth / 2).value.toFloat()
+ val expectedPositionX = (tabRowWidth / 2).toFloat()
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(Offset.Zero).y
val expectedPositionY =
- (tabRowHeight - indicatorHeight.toIntPx()).value.toFloat()
+ (tabRowHeight - indicatorHeight.toIntPx()).toFloat()
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
}
}
@@ -195,7 +195,7 @@
text = {
Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.value.toFloat()
+ textBaseline = coords[LastBaseline]!!.toFloat()
})
},
selected = state == index,
@@ -209,13 +209,13 @@
val expectedBaseline = 18.dp
val indicatorHeight = 2.dp
val expectedBaselineDistance =
- (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).value.toFloat()
+ (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).toFloat()
val tabRowHeight = tabRowCoords.size.height
val textPositionY = textCoords.localToGlobal(Offset.Zero).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = (tabRowHeight.value.toFloat() - expectedBaselineDistance)
+ val expectedPositionY = (tabRowHeight.toFloat() - expectedBaselineDistance)
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -240,7 +240,7 @@
text = {
Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.value.toFloat()
+ textBaseline = coords[LastBaseline]!!.toFloat()
})
},
icon = { Icon(Icons.Filled.Favorite) },
@@ -255,13 +255,13 @@
val expectedBaseline = 14.dp
val indicatorHeight = 2.dp
val expectedBaselineDistance =
- (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).value.toFloat()
+ (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).toFloat()
val tabRowHeight = tabRowCoords.size.height
val textPositionY = textCoords.localToGlobal(Offset.Zero).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = (tabRowHeight.value.toFloat() - expectedBaselineDistance)
+ val expectedPositionY = (tabRowHeight.toFloat() - expectedBaselineDistance)
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -286,7 +286,7 @@
text = {
Text(text, Modifier.preferredWidth(100.dp).onPositioned { coords ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.value.toFloat()
+ textBaseline = coords[LastBaseline]!!.toFloat()
}, maxLines = 2)
},
selected = state == index,
@@ -300,13 +300,13 @@
val expectedBaseline = 10.dp
val indicatorHeight = 2.dp
val expectedBaselineDistance =
- (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).value.toFloat()
+ (expectedBaseline.toIntPx() + indicatorHeight.toIntPx()).toFloat()
val tabRowHeight = tabRowCoords.size.height
val textPositionY = textCoords.localToGlobal(Offset.Zero).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = (tabRowHeight.value.toFloat() - expectedBaselineDistance)
+ val expectedPositionY = (tabRowHeight.toFloat() - expectedBaselineDistance)
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -357,11 +357,11 @@
// Indicator should be placed in the bottom left of the first tab
val indicatorPositionX = indicatorCoords.localToGlobal(Offset.Zero).x
// Tabs in a scrollable tab row are offset 52.dp from each end
- val expectedPositionX = scrollableTabRowOffset.toIntPx().value.toFloat()
+ val expectedPositionX = scrollableTabRowOffset.toIntPx().toFloat()
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(Offset.Zero).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).value.toFloat()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toFloat()
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
tabRowHeight
@@ -375,12 +375,12 @@
composeTestRule.runOnIdleComposeWithDensity {
val indicatorPositionX = indicatorCoords.localToGlobal(Offset.Zero).x
val expectedPositionX =
- (scrollableTabRowOffset + minimumTabWidth).toIntPx().value.toFloat()
+ (scrollableTabRowOffset + minimumTabWidth).toIntPx().toFloat()
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(Offset.Zero).y
val expectedPositionY =
- (tabRowHeight - indicatorHeight.toIntPx()).value.toFloat()
+ (tabRowHeight - indicatorHeight.toIntPx()).toFloat()
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
}
}
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/BottomNavigation.kt b/ui/ui-material/src/main/java/androidx/ui/material/BottomNavigation.kt
index 3474e3e..828e39b 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/BottomNavigation.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/BottomNavigation.kt
@@ -46,9 +46,10 @@
import androidx.ui.text.LastBaseline
import androidx.ui.text.style.TextAlign
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPx
import androidx.ui.unit.dp
import androidx.ui.unit.max
+import kotlin.math.max
+import kotlin.math.roundToInt
// TODO: b/149825331 add documentation references to Scaffold here and samples for using
// BottomNavigation inside a Scaffold
@@ -221,12 +222,12 @@
val textPlaceable = measurables.first { it.tag == "text" }.measure(
// Measure with loose constraints for height as we don't want the text to take up more
// space than it needs
- constraints.copy(minHeight = IntPx.Zero)
+ constraints.copy(minHeight = 0)
)
// If the text is empty, just place the icon.
if (textPlaceable.width <= BottomNavigationItemHorizontalPadding.toIntPx() * 2 &&
- textPlaceable.height == IntPx.Zero
+ textPlaceable.height == 0
) {
placeIcon(iconPlaceable, constraints)
} else {
@@ -250,7 +251,7 @@
val height = constraints.maxHeight
val iconY = (height - iconPlaceable.height) / 2
return layout(iconPlaceable.width, height) {
- iconPlaceable.place(IntPx.Zero, iconY)
+ iconPlaceable.place(0, iconY)
}
}
@@ -308,7 +309,7 @@
// When selected the icon is above the unselected position, so we will animate moving
// downwards from the selected state, so when progress is 1, the total distance is 0, and we
// are at the selected state.
- val offset = iconDistance * (1 - iconPositionAnimationProgress)
+ val offset = (iconDistance * (1 - iconPositionAnimationProgress)).roundToInt()
return layout(containerWidth, height) {
if (iconPositionAnimationProgress != 0f) {
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Drawer.kt b/ui/ui-material/src/main/java/androidx/ui/material/Drawer.kt
index b7e405d..0338451 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Drawer.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Drawer.kt
@@ -23,8 +23,6 @@
import androidx.ui.core.DensityAmbient
import androidx.ui.core.Modifier
import androidx.ui.core.WithConstraints
-import androidx.ui.core.hasBoundedHeight
-import androidx.ui.core.hasBoundedWidth
import androidx.ui.foundation.Box
import androidx.ui.foundation.Canvas
import androidx.ui.foundation.clickable
@@ -97,7 +95,7 @@
val dpConstraints = with(DensityAmbient.current) {
DpConstraints(constraints)
}
- val minValue = -constraints.maxWidth.value.toFloat()
+ val minValue = -constraints.maxWidth.toFloat()
val maxValue = 0f
val anchors = listOf(minValue to DrawerState.Closed, maxValue to DrawerState.Opened)
@@ -171,7 +169,7 @@
DpConstraints(constraints)
}
val minValue = 0f
- val maxValue = constraints.maxHeight.value.toFloat()
+ val maxValue = constraints.maxHeight.toFloat()
// TODO: add proper landscape support
val isLandscape = constraints.maxWidth > constraints.maxHeight
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/ListItem.kt b/ui/ui-material/src/main/java/androidx/ui/material/ListItem.kt
index a84e856..3fc7b54 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/ListItem.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/ListItem.kt
@@ -18,6 +18,7 @@
import androidx.compose.Composable
import androidx.ui.core.Alignment
+import androidx.ui.core.Constraints
import androidx.ui.core.Layout
import androidx.ui.core.Modifier
import androidx.ui.core.semantics.semantics
@@ -39,12 +40,11 @@
import androidx.ui.text.TextStyle
import androidx.ui.text.style.TextOverflow
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPx
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import androidx.ui.unit.max
import androidx.ui.util.fastForEachIndexed
+import kotlin.math.max
/**
* Material Design implementation of [list items](https://material.io/components/lists).
@@ -412,20 +412,20 @@
content: @Composable () -> Unit
) {
Layout(content, modifier) { measurables, constraints, _ ->
- val childConstraints = constraints.copy(minHeight = 0.ipx, maxHeight = IntPx.Infinity)
+ val childConstraints = constraints.copy(minHeight = 0, maxHeight = Constraints.Infinity)
val placeables = measurables.map { it.measure(childConstraints) }
- val containerWidth = placeables.fold(0.ipx) { maxWidth, placeable ->
+ val containerWidth = placeables.fold(0) { maxWidth, placeable ->
max(maxWidth, placeable.width)
}
- val y = Array(placeables.size) { 0.ipx }
- var containerHeight = 0.ipx
+ val y = Array(placeables.size) { 0 }
+ var containerHeight = 0
placeables.fastForEachIndexed { index, placeable ->
val toPreviousBaseline = if (index > 0) {
placeables[index - 1].height - placeables[index - 1][LastBaseline]!!
- } else 0.ipx
+ } else 0
val topPadding = max(
- 0.ipx,
+ 0,
offsets[index].toIntPx() - placeable[FirstBaseline]!! - toPreviousBaseline
)
y[index] = topPadding + containerHeight
@@ -434,7 +434,7 @@
layout(containerWidth, containerHeight) {
placeables.fastForEachIndexed { index, placeable ->
- placeable.place(0.ipx, y[index])
+ placeable.place(0, y[index])
}
}
}
@@ -454,20 +454,20 @@
content: @Composable () -> Unit
) {
Layout(content, modifier) { measurables, constraints, _ ->
- val placeable = measurables[0].measure(constraints.copy(minHeight = 0.ipx))
+ val placeable = measurables[0].measure(constraints.copy(minHeight = 0))
val baseline = placeable[FirstBaseline]
- val y: IntPx
- val containerHeight: IntPx
+ val y: Int
+ val containerHeight: Int
if (baseline != null) {
y = offset.toIntPx() - baseline
containerHeight = max(constraints.minHeight, y + placeable.height)
} else {
containerHeight = max(constraints.minHeight, placeable.height)
y = Alignment.Center
- .align(IntPxSize(0.ipx, containerHeight - placeable.height)).y
+ .align(IntSize(0, containerHeight - placeable.height)).y
}
layout(placeable.width, containerHeight) {
- placeable.place(0.ipx, y)
+ placeable.place(0, y)
}
}
}
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Menu.kt b/ui/ui-material/src/main/java/androidx/ui/material/Menu.kt
index 3e24c4ed..3d11dcd 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Menu.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Menu.kt
@@ -48,11 +48,9 @@
import androidx.ui.layout.preferredWidth
import androidx.ui.material.ripple.RippleIndication
import androidx.ui.unit.Density
-import androidx.ui.unit.IntPxPosition
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntOffset
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
-
/**
* A Material Design [dropdown menu](https://material.io/components/menus#dropdown-menu).
*
@@ -242,11 +240,11 @@
val displayMetrics: DisplayMetrics
) : PopupPositionProvider {
override fun calculatePosition(
- parentLayoutPosition: IntPxPosition,
- parentLayoutSize: IntPxSize,
+ parentLayoutPosition: IntOffset,
+ parentLayoutSize: IntSize,
layoutDirection: LayoutDirection,
- popupSize: IntPxSize
- ): IntPxPosition {
+ popupSize: IntSize
+ ): IntOffset {
// The padding inset that accommodates elevation, needs to be taken into account.
val inset = with(density) { MenuElevation.toIntPx() }
val realPopupWidth = popupSize.width - inset * 2
@@ -259,25 +257,25 @@
// Compute horizontal position.
val toRight = parentRight + contentOffsetX
val toLeft = parentLayoutPosition.x - contentOffsetX - realPopupWidth
- val toDisplayRight = displayMetrics.widthPixels.ipx - realPopupWidth
- val toDisplayLeft = 0.ipx
+ val toDisplayRight = displayMetrics.widthPixels - realPopupWidth
+ val toDisplayLeft = 0
val x = if (layoutDirection == LayoutDirection.Ltr) {
sequenceOf(toRight, toLeft, toDisplayRight)
} else {
sequenceOf(toLeft, toRight, toDisplayLeft)
}.firstOrNull {
- it >= 0.ipx && it + realPopupWidth <= displayMetrics.widthPixels.ipx
+ it >= 0 && it + realPopupWidth <= displayMetrics.widthPixels
} ?: toLeft
// Compute vertical position.
val toBottom = parentBottom + contentOffsetY
val toTop = parentLayoutPosition.y - contentOffsetY - realPopupHeight
val toCenter = parentLayoutPosition.y - realPopupHeight / 2
- val toDisplayBottom = displayMetrics.heightPixels.ipx - realPopupHeight
+ val toDisplayBottom = displayMetrics.heightPixels - realPopupHeight
val y = sequenceOf(toBottom, toTop, toCenter, toDisplayBottom).firstOrNull {
- it >= 0.ipx && it + realPopupHeight <= displayMetrics.heightPixels.ipx
+ it >= 0 && it + realPopupHeight <= displayMetrics.heightPixels
} ?: toTop
- return IntPxPosition(x - inset, y - inset)
+ return IntOffset(x - inset, y - inset)
}
}
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt b/ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt
index 1fe1e5b..bf358a4 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Scaffold.kt
@@ -43,7 +43,6 @@
import androidx.ui.layout.padding
import androidx.ui.material.Scaffold.FabPosition
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPx
import androidx.ui.unit.PxBounds
import androidx.ui.geometry.Size
import androidx.ui.unit.dp
@@ -291,8 +290,8 @@
}
layout(layoutWidth, layoutHeight) {
- appBarPlaceable.place(IntPx.Zero, appBarVerticalOffset)
- fabPlaceable.place(fabPosX, IntPx.Zero)
+ appBarPlaceable.place(0, appBarVerticalOffset)
+ fabPlaceable.place(fabPosX, 0)
}
}
}
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Slider.kt b/ui/ui-material/src/main/java/androidx/ui/material/Slider.kt
index f306d06..847a052 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Slider.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Slider.kt
@@ -116,7 +116,7 @@
position.>
position.scaledValue = value
WithConstraints(modifier.sliderSemantics(value, position, onValueChange, valueRange, steps)) {
- val maxPx = constraints.maxWidth.value.toFloat()
+ val maxPx = constraints.maxWidth.toFloat()
val minPx = 0f
position.setBounds(minPx, maxPx)
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Snackbar.kt b/ui/ui-material/src/main/java/androidx/ui/material/Snackbar.kt
index 0857d41..b8da79d 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Snackbar.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Snackbar.kt
@@ -33,10 +33,8 @@
import androidx.ui.layout.relativePaddingFrom
import androidx.ui.layout.padding
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPx
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
-import androidx.ui.unit.max
+import kotlin.math.max
/**
* Snackbars provide brief messages about app processes at the bottom of the screen.
@@ -111,7 +109,7 @@
val minHeight = if (firstBaseline == lastBaseline) MinHeightOneLine else MinHeightTwoLines
layout(constraints.maxWidth, max(minHeight.toIntPx(), textPlaceable.height)) {
val textPlaceY = HeightToFirstLine.toIntPx() - firstBaseline
- textPlaceable.place(0.ipx, textPlaceY)
+ textPlaceable.place(0, textPlaceY)
}
}
}
@@ -159,7 +157,7 @@
(constraints.maxWidth - buttonPlaceable.width - TextEndExtraSpacing.toIntPx())
.coerceAtLeast(constraints.minWidth)
val textPlaceable = measurables.first { it.tag == textTag }.measure(
- constraints.copy(minHeight = IntPx.Zero, maxWidth = textMaxWidth)
+ constraints.copy(minHeight = 0, maxWidth = textMaxWidth)
)
val firstTextBaseline =
@@ -171,8 +169,8 @@
val textPlaceY = baselineOffset - firstTextBaseline
val buttonPlaceX = constraints.maxWidth - buttonPlaceable.width
- val containerHeight: IntPx
- val buttonPlaceY: IntPx
+ val containerHeight: Int
+ val buttonPlaceY: Int
if (isOneLine) {
val minContainerHeight = MinHeightOneLine.toIntPx()
val contentHeight = buttonPlaceable.height + SingleTextYPadding.toIntPx() * 2
@@ -188,7 +186,7 @@
}
layout(constraints.maxWidth, containerHeight) {
- textPlaceable.place(0.ipx, textPlaceY)
+ textPlaceable.place(0, textPlaceY)
buttonPlaceable.place(buttonPlaceX, buttonPlaceY)
}
}
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/Surface.kt b/ui/ui-material/src/main/java/androidx/ui/material/Surface.kt
index 6799e69..ddb46bb 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/Surface.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/Surface.kt
@@ -36,7 +36,6 @@
import androidx.ui.text.TextStyle
import androidx.ui.unit.Dp
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
import kotlin.math.ln
/**
@@ -130,7 +129,7 @@
} else {
val placeable = measurable.measure(constraints)
layout(placeable.width, placeable.height) {
- placeable.placeAbsolute(0.ipx, 0.ipx)
+ placeable.placeAbsolute(0, 0)
}
}
}
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 066358b..2b23ae9 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
@@ -60,14 +60,12 @@
import androidx.ui.text.LastBaseline
import androidx.ui.text.style.TextAlign
import androidx.ui.unit.Density
-import androidx.ui.unit.IntPx
-import androidx.ui.unit.coerceAtLeast
import androidx.ui.unit.dp
-import androidx.ui.unit.max
import androidx.ui.unit.sp
import androidx.ui.util.fastFirstOrNull
import androidx.ui.util.fastForEach
import androidx.ui.util.fastForEachIndexed
+import kotlin.math.max
/**
* A TabRow contains a row of [Tab]s, and displays an indicator underneath the currently
@@ -182,7 +180,7 @@
@Composable
private fun FixedTabRow(
- width: IntPx,
+ width: Int,
tabCount: Int,
tabs: @Composable (Modifier) -> Unit,
indicatorContainer: @Composable (tabPositions: List<TabPosition>) -> Unit,
@@ -210,7 +208,7 @@
@Composable
private fun ScrollableTabRow(
- width: IntPx,
+ width: Int,
selectedIndex: Int,
tabs: @Composable () -> Unit,
indicatorContainer: @Composable (tabPositions: List<TabPosition>) -> Unit,
@@ -248,10 +246,10 @@
Box(Modifier.tag(dividerTag), children = divider)
}
) { measurables, constraints, _ ->
- val tabPlaceables = mutableListOf<Pair<Placeable, IntPx>>()
+ val tabPlaceables = mutableListOf<Pair<Placeable, Int>>()
val minTabWidth = ScrollableTabRowMinimumTabWidth.toIntPx()
- var layoutHeight = IntPx.Zero
+ var layoutHeight = 0
val tabConstraints = constraints.copy(minWidth = minTabWidth)
@@ -281,20 +279,20 @@
layout(layoutWidth, layoutHeight) {
// Place the tabs
tabPlaceables.fastForEach { (placeable, left) ->
- placeable.place(left, IntPx.Zero)
+ placeable.place(left, 0)
}
// 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.fastFirstOrNull { it.tag == dividerTag }
?.measure(constraints.copy(minWidth = layoutWidth, maxWidth = layoutWidth))
- ?.run { place(IntPx.Zero, layoutHeight - height) }
+ ?.run { place(0, 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.fastFirstOrNull { it.tag == indicatorTag }
?.measure(Constraints.fixed(layoutWidth, layoutHeight))
- ?.place(IntPx.Zero, IntPx.Zero)
+ ?.place(0, 0)
}
}
}
@@ -304,8 +302,8 @@
private fun ScrollableTabData(
initialSelectedTab: Int,
tabPositions: List<TabPosition>,
- visibleWidth: IntPx,
- edgeOffset: IntPx
+ visibleWidth: Int,
+ edgeOffset: Int
): ScrollableTabData = ScrollerPosition().let { scrollerPosition ->
remember(scrollerPosition) {
ScrollableTabData(
@@ -325,8 +323,8 @@
val scrollerPosition: ScrollerPosition,
initialSelectedTab: Int,
var tabPositions: List<TabPosition>,
- var visibleWidth: IntPx,
- val edgeOffset: IntPx
+ var visibleWidth: Int,
+ val edgeOffset: Int
) {
var selectedTab: Int = initialSelectedTab
set(value) {
@@ -358,8 +356,8 @@
val totalTabRowWidth = tabPositions.last().right + edgeOffset
// How much space we have to scroll. If the visible width is <= to the total width, then
// we have no space to scroll as everything is always visible.
- val availableSpace = (totalTabRowWidth - visibleWidth).coerceAtLeast(IntPx.Zero)
- return centeredTabOffset.coerceIn(IntPx.Zero, availableSpace).value.toFloat()
+ val availableSpace = (totalTabRowWidth - visibleWidth).coerceAtLeast(0)
+ return centeredTabOffset.coerceIn(0, availableSpace).toFloat()
}
}
@@ -373,8 +371,8 @@
* @property right the right edge's x position from the start of the [TabRow]
* @property width the width of this tab
*/
- data class TabPosition internal constructor(val left: IntPx, val width: IntPx) {
- val right: IntPx get() = left + width
+ data class TabPosition internal constructor(val left: Int, val width: Int) {
+ val right: Int get() = left + width
}
/**
@@ -431,13 +429,13 @@
// When this is supported by transitionDefinition, we should fix this to just set a
// default or similar.
state(selectedIndex) {
- this[IndicatorOffset] = tabPositions[selectedIndex].left.value.toFloat()
+ this[IndicatorOffset] = tabPositions[selectedIndex].left.toFloat()
}
tabPositions.forEachIndexed { index, position ->
if (index != selectedIndex) {
state(index) {
- this[IndicatorOffset] = position.left.value.toFloat()
+ this[IndicatorOffset] = position.left.toFloat()
}
}
}
@@ -595,16 +593,16 @@
val textPlaceable = measurables.first { it.tag == "text" }.measure(
// Measure with loose constraints for height as we don't want the text to take up more
// space than it needs
- constraints.copy(minHeight = IntPx.Zero)
+ constraints.copy(minHeight = 0)
)
val iconPlaceable = measurables.first { it.tag == "icon" }.measure(constraints)
val hasTextPlaceable =
- textPlaceable.width != IntPx.Zero && textPlaceable.height != IntPx.Zero
+ textPlaceable.width != 0 && textPlaceable.height != 0
val hasIconPlaceable =
- iconPlaceable.width != IntPx.Zero && iconPlaceable.height != IntPx.Zero
+ iconPlaceable.width != 0 && iconPlaceable.height != 0
val tabWidth = max(textPlaceable.width, iconPlaceable.width)
@@ -645,10 +643,10 @@
*/
private fun Placeable.PlacementScope.placeIcon(
iconPlaceable: Placeable,
- tabHeight: IntPx
+ tabHeight: Int
) {
val iconY = (tabHeight - iconPlaceable.height) / 2
- iconPlaceable.place(IntPx.Zero, iconY)
+ iconPlaceable.place(0, iconY)
}
/**
@@ -658,9 +656,9 @@
private fun Placeable.PlacementScope.placeText(
density: Density,
textPlaceable: Placeable,
- tabHeight: IntPx,
- firstBaseline: IntPx,
- lastBaseline: IntPx
+ tabHeight: Int,
+ firstBaseline: Int,
+ lastBaseline: Int
) {
val baselineOffset = if (firstBaseline == lastBaseline) {
SingleLineTextBaseline
@@ -672,7 +670,7 @@
val totalOffset = with(density) { baselineOffset.toIntPx() + IndicatorHeight.toIntPx() }
val textPlaceableY = tabHeight - lastBaseline - totalOffset
- textPlaceable.place(IntPx.Zero, textPlaceableY)
+ textPlaceable.place(0, textPlaceableY)
}
/**
@@ -684,10 +682,10 @@
density: Density,
textPlaceable: Placeable,
iconPlaceable: Placeable,
- tabWidth: IntPx,
- tabHeight: IntPx,
- firstBaseline: IntPx,
- lastBaseline: IntPx
+ tabWidth: Int,
+ tabHeight: Int,
+ firstBaseline: Int,
+ lastBaseline: Int
) {
val baselineOffset = if (firstBaseline == lastBaseline) {
SingleLineTextBaselineWithIcon
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/TextField.kt b/ui/ui-material/src/main/java/androidx/ui/material/TextField.kt
index e37b6c1..645e0c9 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/TextField.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/TextField.kt
@@ -45,12 +45,13 @@
import androidx.ui.core.Placeable
import androidx.ui.core.Ref
import androidx.ui.core.clipToBounds
+import androidx.ui.core.constrainWidth
import androidx.ui.core.drawBehind
-import androidx.ui.core.offset
-import androidx.ui.core.tag
import androidx.ui.core.focus.FocusModifier
import androidx.ui.core.focus.FocusState
import androidx.ui.core.focus.focusState
+import androidx.ui.core.offset
+import androidx.ui.core.tag
import androidx.ui.foundation.Box
import androidx.ui.foundation.ContentColorAmbient
import androidx.ui.foundation.ProvideTextStyle
@@ -66,10 +67,10 @@
import androidx.ui.geometry.Offset
import androidx.ui.graphics.Color
import androidx.ui.graphics.Shape
+import androidx.ui.graphics.drawscope.Stroke
import androidx.ui.input.ImeAction
import androidx.ui.input.KeyboardType
import androidx.ui.input.VisualTransformation
-import androidx.ui.graphics.drawscope.Stroke
import androidx.ui.layout.padding
import androidx.ui.layout.preferredSizeIn
import androidx.ui.material.ripple.RippleIndication
@@ -81,12 +82,10 @@
import androidx.ui.text.TextStyle
import androidx.ui.text.lerp
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPx
-import androidx.ui.unit.IntPxSize
+import androidx.ui.unit.IntSize
import androidx.ui.unit.dp
-import androidx.ui.unit.ipx
-import androidx.ui.unit.max
-import androidx.ui.unit.min
+import kotlin.math.max
+import kotlin.math.min
import kotlin.math.roundToInt
/**
@@ -527,17 +526,17 @@
),
children = textField,
measureBlock = { measurables, constraints, _ ->
- val childConstraints = constraints.copy(maxHeight = IntPx.Infinity)
+ val childConstraints = constraints.copy(maxHeight = Constraints.Infinity)
val placeable = measurables.first().measure(childConstraints)
val height = min(placeable.height, constraints.maxHeight)
- val diff = placeable.height.value.toFloat() - height.value.toFloat()
+ val diff = placeable.height.toFloat() - height.toFloat()
layout(placeable.width, height) {
// update current and maximum positions to correctly calculate delta in scrollable
scrollerPosition.maximum = diff
if (scrollerPosition.current > diff) scrollerPosition.current = diff
val yOffset = scrollerPosition.current - diff
- placeable.place(0.ipx, yOffset.roundToInt().ipx)
+ placeable.place(0, yOffset.roundToInt())
}
}
)
@@ -603,15 +602,15 @@
val labelConstraints = constraints
.offset(vertical = -LastBaselineOffset.toIntPx())
- .copy(minWidth = IntPx.Zero, minHeight = IntPx.Zero)
+ .copy(minWidth = 0, minHeight = 0)
val labelPlaceable = measurables.first { it.tag == LabelTag }.measure(labelConstraints)
val labelBaseline = labelPlaceable[LastBaseline] ?: labelPlaceable.height
- val labelEndPosition = (baseLineOffset - labelBaseline).coerceAtLeast(IntPx.Zero)
+ val labelEndPosition = (baseLineOffset - labelBaseline).coerceAtLeast(0)
val effectiveLabelBaseline = max(labelBaseline, baseLineOffset)
val textFieldConstraints = constraints
.offset(vertical = -LastBaselineOffset.toIntPx() - effectiveLabelBaseline)
- .copy(minHeight = IntPx.Zero)
+ .copy(minHeight = 0)
val textfieldPlaceable = measurables
.first { it.tag == TextFieldTag }
.measure(textFieldConstraints)
@@ -628,7 +627,7 @@
layout(width, height) {
// Text field and label are placed with respect to the baseline offsets.
// But if label is empty, then the text field should be centered vertically.
- if (labelPlaceable.width != IntPx.Zero) {
+ if (labelPlaceable.width != 0) {
// only respects the offset from the last baseline to the bottom of the text field
val textfieldPositionY = height - LastBaselineOffset.toIntPx() -
min(textfieldLastBaseline, textfieldPlaceable.height)
@@ -680,15 +679,15 @@
},
modifier = modifier
) { measurables, incomingConstraints, _ ->
- val constraints = incomingConstraints.copy(minWidth = IntPx.Zero, minHeight = IntPx.Zero)
- var occupiedSpace = 0.ipx
+ val constraints = incomingConstraints.copy(minWidth = 0, minHeight = 0)
+ var occupiedSpace = 0
val leadingPlaceable = measurables.find { it.tag == "leading" }?.measure(constraints)
- occupiedSpace += leadingPlaceable?.width ?: 0.ipx
+ occupiedSpace += leadingPlaceable?.width ?: 0
val trailingPlaceable = measurables.find { it.tag == "trailing" }
?.measure(constraints.offset(horizontal = -occupiedSpace))
- occupiedSpace += trailingPlaceable?.width ?: 0.ipx
+ occupiedSpace += trailingPlaceable?.width ?: 0
val textFieldPlaceable = measurables.first {
it.tag != "leading" && it.tag != "trailing"
@@ -701,16 +700,16 @@
leadingPlaceable,
trailingPlaceable,
textFieldPlaceable
- ).maxBy { it?.height ?: 0.ipx }?.height ?: 0.ipx,
+ ).maxBy { it?.height ?: 0 }?.height ?: 0,
incomingConstraints.minHeight
)
layout(width, height) {
leadingPlaceable?.place(
- 0.ipx,
+ 0,
Alignment.CenterVertically.align(height - leadingPlaceable.height)
)
textFieldPlaceable.place(
- leadingPlaceable?.width ?: 0.ipx,
+ leadingPlaceable?.width ?: 0,
Alignment.CenterVertically.align(height - textFieldPlaceable.height)
)
trailingPlaceable?.place(
@@ -731,17 +730,17 @@
val horizontal = start.toIntPx() + end.toIntPx()
val placeable = measurable.measure(constraints.offset(-horizontal))
val width = if (placeable.nonZero) {
- (placeable.width + horizontal).coerceIn(constraints.minWidth, constraints.maxWidth)
+ constraints.constrainWidth(placeable.width + horizontal)
} else {
- 0.ipx
+ 0
}
return layout(width, placeable.height) {
- placeable.place(start.toIntPx(), 0.ipx)
+ placeable.place(start.toIntPx(), 0)
}
}
}
-private val Placeable.nonZero: Boolean get() = this.width != 0.ipx || this.height != 0.ipx
+private val Placeable.nonZero: Boolean get() = this.width != 0 || this.height != 0
/**
* A draw modifier that draws a bottom indicator line
@@ -763,47 +762,47 @@
* Places the provided text field, placeholder and label with respect to the baseline offsets
*/
private fun Placeable.PlacementScope.placeLabelAndTextfield(
- width: IntPx,
- height: IntPx,
+ width: Int,
+ height: Int,
textfieldPlaceable: Placeable,
labelPlaceable: Placeable,
placeholderPlaceable: Placeable?,
- labelEndPosition: IntPx,
- textPosition: IntPx,
+ labelEndPosition: Int,
+ textPosition: Int,
animationProgress: Float
) {
val labelCenterPosition = Alignment.CenterStart.align(
- IntPxSize(
+ IntSize(
width - labelPlaceable.width,
height - labelPlaceable.height
)
)
val labelDistance = labelCenterPosition.y - labelEndPosition
val labelPositionY =
- labelCenterPosition.y - labelDistance * animationProgress
- labelPlaceable.place(IntPx.Zero, labelPositionY)
+ labelCenterPosition.y - (labelDistance * animationProgress).roundToInt()
+ labelPlaceable.place(0, labelPositionY)
- textfieldPlaceable.place(IntPx.Zero, textPosition)
- placeholderPlaceable?.place(IntPx.Zero, textPosition)
+ textfieldPlaceable.place(0, textPosition)
+ placeholderPlaceable?.place(0, textPosition)
}
/**
* Places the provided text field and placeholder center vertically
*/
private fun Placeable.PlacementScope.placeTextfield(
- width: IntPx,
- height: IntPx,
+ width: Int,
+ height: Int,
textPlaceable: Placeable,
placeholderPlaceable: Placeable?
) {
val textCenterPosition = Alignment.CenterStart.align(
- IntPxSize(
+ IntSize(
width - textPlaceable.width,
height - textPlaceable.height
)
)
- textPlaceable.place(IntPx.Zero, textCenterPosition.y)
- placeholderPlaceable?.place(IntPx.Zero, textCenterPosition.y)
+ textPlaceable.place(0, textCenterPosition.y)
+ placeholderPlaceable?.place(0, textCenterPosition.y)
}
private object TextFieldTransitionScope {
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt b/ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt
index 5b6a74d..11f3a96 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/ripple/Ripple.kt
@@ -41,14 +41,13 @@
import androidx.ui.core.composed
import androidx.ui.core.gesture.pressIndicatorGestureFilter
import androidx.ui.foundation.Interaction
+import androidx.ui.geometry.Offset
+import androidx.ui.geometry.Size
import androidx.ui.graphics.Color
import androidx.ui.graphics.useOrElse
import androidx.ui.unit.Density
import androidx.ui.unit.Dp
-import androidx.ui.unit.IntPxSize
-import androidx.ui.geometry.Offset
-import androidx.ui.geometry.Size
-import androidx.ui.unit.ipx
+import androidx.ui.unit.IntSize
import androidx.ui.unit.toSize
import androidx.ui.util.fastForEach
@@ -104,7 +103,7 @@
var color: Color by mutableStateOf(Color.Transparent, StructurallyEqual)
- private var size: IntPxSize = IntPxSize(0.ipx, 0.ipx)
+ private var size: IntSize = IntSize(0, 0)
private var effects = modelListOf<RippleAnimation>()
private var currentEffect: RippleAnimation? = null
@@ -114,9 +113,9 @@
layoutDirection: LayoutDirection
): MeasureScope.MeasureResult {
val placeable = measurable.measure(constraints)
- size = IntPxSize(placeable.width, placeable.height)
+ size = IntSize(placeable.width, placeable.height)
return layout(placeable.width, placeable.height) {
- placeable.place(0.ipx, 0.ipx)
+ placeable.place(0, 0)
}
}
@@ -137,7 +136,7 @@
val targetRadius = with(density) {
radius?.toPx() ?: getRippleEndRadius(
bounded,
- Size(size.width.value.toFloat(), size.height.value.toFloat())
+ Size(size.width.toFloat(), size.height.toFloat())
)
}