Removal of Px usages part 5 of n
Relnote: "Replaced usage of Px class in various
compose classes as part of the large
refactoring effort to only rely on Dp
and primitive types for pixel parameters"
Bug: 156681014
Test: re-ran compose tests
Change-Id: Id343458210b56a9a4cdae4ef3d0f97ea79004942
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 c836622..23d1bfd 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
@@ -341,8 +341,8 @@
* or the color is partially transparent.
*/
private fun ColorWheel.colorForPosition(position: PxPosition): Color {
- val x = position.x.value.toInt().coerceAtLeast(0)
- val y = position.y.value.toInt().coerceAtLeast(0)
+ val x = position.x.toInt().coerceAtLeast(0)
+ val y = position.y.toInt().coerceAtLeast(0)
with(image.toPixelMap()) {
if (x >= width || y >= height) return Color.Unset
return this[x, y].takeIf { it.alpha == 1f } ?: Color.Unset
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 e5c5c54..f60edec 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
@@ -105,37 +105,37 @@
}
composeTestRule.runOnIdleComposeWithDensity {
- val appBarBottomEdgeY = appBarCoords!!.globalPosition.y.value +
+ val appBarBottomEdgeY = appBarCoords!!.globalPosition.y +
appBarCoords!!.size.height.value
// Navigation icon should be 4.dp from the start
val navigationIconPositionX = navigationIconCoords!!.globalPosition.x
- val navigationIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toPx()
+ val navigationIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toPx().value
assertThat(navigationIconPositionX).isEqualTo(navigationIconExpectedPositionX)
// Navigation icon should be 4.dp from the bottom
val navigationIconPositionY = navigationIconCoords!!.globalPosition.y
val navigationIconExpectedPositionY = (appBarBottomEdgeY -
AppBarStartAndEndPadding.toPx() - FakeIconSize.toPx()
- ).roundToInt().px
+ ).roundToInt().toFloat()
assertThat(navigationIconPositionY).isEqualTo(navigationIconExpectedPositionY)
// 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()).toPx()
+ val titleExpectedPositionX = (4.dp.toIntPx() + 68.dp.toIntPx()).value.toFloat()
assertThat(titlePositionX).isEqualTo(titleExpectedPositionX)
// Absolute position of the baseline
val titleLastBaselinePositionY = titleLastBaselineRelativePosition!! +
- titleCoords!!.globalPosition.y.value
+ titleCoords!!.globalPosition.y
// Baseline should be 20.sp from the bottom of the app bar
val titleExpectedLastBaselinePositionY = (appBarBottomEdgeY.px - 20.sp.toIntPx()
.toPx()).value
assertThat(titleLastBaselinePositionY).isEqualTo(titleExpectedLastBaselinePositionY)
// Action should be placed at the end
- val actionPositionX = actionCoords!!.globalPosition.x.value
+ val actionPositionX = actionCoords!!.globalPosition.x
val actionExpectedPositionX =
expectedActionPosition(appBarCoords!!.size.width.toPx().value)
assertThat(actionPositionX).isEqualTo(actionExpectedPositionX)
@@ -144,7 +144,7 @@
val actionPositionY = actionCoords!!.globalPosition.y
val actionExpectedPositionY = (appBarBottomEdgeY - AppBarStartAndEndPadding.toPx() -
FakeIconSize.toPx()
- ).roundToInt().px
+ ).roundToInt()
assertThat(actionPositionY).isEqualTo(actionExpectedPositionY)
}
}
@@ -172,11 +172,11 @@
// 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()).toPx()
+ val titleExpectedPositionX = (4.dp.toIntPx() + 12.dp.toIntPx()).toPx().value
assertThat(titlePositionX).isEqualTo(titleExpectedPositionX)
// Action should still be placed at the end
- val actionPositionX = actionCoords!!.globalPosition.x.value
+ val actionPositionX = actionCoords!!.globalPosition.x
val actionExpectedPositionX =
expectedActionPosition(appBarCoords!!.size.width.toPx().value)
assertThat(actionPositionX).isEqualTo(actionExpectedPositionX)
@@ -228,17 +228,17 @@
composeTestRule.runOnIdleComposeWithDensity {
// Child icon should be 4.dp from the start
val childIconPositionX = childCoords!!.globalPosition.x
- val childIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toPx()
+ val childIconExpectedPositionX = AppBarStartAndEndPadding.toIntPx().toPx().value
assertThat(childIconPositionX).isEqualTo(childIconExpectedPositionX)
- val appBarBottomEdgeY = appBarCoords!!.globalPosition.y.value +
+ val appBarBottomEdgeY = appBarCoords!!.globalPosition.y +
appBarCoords!!.size.height.value
// Child icon should be 4.dp from the bottom
val childIconPositionY = childCoords!!.globalPosition.y
val childIconExpectedPositionY = (appBarBottomEdgeY - AppBarStartAndEndPadding.toPx() -
FakeIconSize.toPx()
- ).roundToInt().px
+ ).roundToInt().toFloat()
assertThat(childIconPositionY).isEqualTo(childIconExpectedPositionY)
}
}
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 fede650..4da8b00 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
@@ -105,7 +105,7 @@
Truth.assertThat(coord.size.width).isEqualTo(expectedItemWidth)
Truth.assertThat(coord.size.height).isEqualTo(expectedItemHeight)
Truth.assertThat(coord.globalPosition.x)
- .isEqualTo((expectedItemWidth * index).toPx())
+ .isEqualTo((expectedItemWidth * index).value.toFloat())
}
}
}
@@ -142,14 +142,15 @@
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().toPx()
+ val textBaseline = 12.dp.toIntPx().value.toFloat()
// Relative position of the baseline to the top of text
- val relativeTextBaseline = textCoords[LastBaseline]!!.toPx()
+ val relativeTextBaseline = textCoords[LastBaseline]!!.toPx().value
// Absolute y position of the text baseline
val absoluteTextBaseline = textCoords.globalPosition.y + relativeTextBaseline
- val itemBottom = itemCoords.size.height.toPx() + itemCoords.globalPosition.y
+ val itemBottom = itemCoords.size.height.toPx().value +
+ itemCoords.globalPosition.y
// Text baseline should be 12.dp from the bottom of the item
Truth.assertThat(absoluteTextBaseline).isEqualTo(itemBottom - textBaseline)
@@ -157,9 +158,10 @@
val iconExpectedX = (itemCoords.size.width.toPx() - iconCoords.size.width.toPx()) / 2
// The bottom of the icon is 12.dp above the text baseline
val iconExpectedY =
- absoluteTextBaseline - 12.dp.toIntPx().toPx() - iconCoords.size.height
+ absoluteTextBaseline - 12.dp.toIntPx().value.toFloat() -
+ iconCoords.size.height.value
- Truth.assertThat(iconCoords.globalPosition.x.value).isWithin(1f).of(iconExpectedX.value)
+ Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(iconExpectedX.value)
Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY)
}
}
@@ -206,8 +208,8 @@
val iconExpectedX = (itemCoords.size.width.toPx() - iconCoords.size.width.toPx()) / 2
val iconExpectedY = (itemCoords.size.height - iconCoords.size.height) / 2
- Truth.assertThat(iconCoords.globalPosition.x.value).isWithin(1f).of(iconExpectedX.value)
- Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.toPx())
+ Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(iconExpectedX.value)
+ Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.toPx().value)
}
}
@@ -240,8 +242,8 @@
val iconExpectedX = (itemCoords.size.width.toPx() - iconCoords.size.width.toPx()) / 2
val iconExpectedY = (itemCoords.size.height - iconCoords.size.height) / 2
- Truth.assertThat(iconCoords.globalPosition.x.value).isWithin(1f).of(iconExpectedX.value)
- Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.toPx())
+ Truth.assertThat(iconCoords.globalPosition.x).isWithin(1f).of(iconExpectedX.value)
+ Truth.assertThat(iconCoords.globalPosition.y).isEqualTo(iconExpectedY.toPx().value)
}
}
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 ac60d2b..5514a48 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
@@ -553,7 +553,7 @@
val topLeft = childCoordinates!!.localToGlobal(PxPosition.Origin).x -
parentCoordinates!!.localToGlobal(PxPosition.Origin).x
val currentPadding = with(composeTestRule.density) {
- padding.toIntPx().toPx()
+ padding.toIntPx().value.toFloat()
}
assertThat(currentPadding).isEqualTo(topLeft)
}
@@ -561,8 +561,8 @@
}
fun assertWithinOnePixel(expected: PxPosition, actual: PxPosition) {
- assertWithinOnePixel(expected.x.value, actual.x.value)
- assertWithinOnePixel(expected.y.value, actual.y.value)
+ assertWithinOnePixel(expected.x, actual.x)
+ assertWithinOnePixel(expected.y, actual.y)
}
fun assertWithinOnePixel(expected: Float, actual: Float) {
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 ed3afdc..8c75f3f 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
@@ -70,7 +70,7 @@
}, bodyContent = emptyContent())
}
runOnIdleCompose {
- assertThat(position!!.x.value).isEqualTo(0f)
+ assertThat(position!!.x).isEqualTo(0f)
}
}
@@ -86,7 +86,7 @@
}
val width = composeTestRule.displayMetrics.widthPixels
runOnIdleCompose {
- assertThat(position!!.x.round().value).isEqualTo(-width)
+ assertThat(position!!.x.px.round().value).isEqualTo(-width)
}
}
@@ -124,7 +124,7 @@
// temporary calculation of landscape screen
val expectedHeight = if (width > height) 0 else (height / 2f).roundToInt()
runOnIdleCompose {
- assertThat(position!!.y.round().value).isEqualTo(expectedHeight)
+ assertThat(position!!.y.px.round().value).isEqualTo(expectedHeight)
}
}
@@ -140,7 +140,7 @@
}
val height = composeTestRule.displayMetrics.heightPixels
runOnIdleCompose {
- assertThat(position!!.y.round().value).isEqualTo(height)
+ assertThat(position!!.y.px.round().value).isEqualTo(height)
}
}
@@ -157,10 +157,10 @@
Box(
Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
val pos = info.localToGlobal(PxPosition.Origin)
- if (pos.x == 0.px) {
+ if (pos.x == 0.0f) {
// If fully opened, mark the openedLatch if present
openedLatch?.countDown()
- } else if (-pos.x.round() == contentWidth) {
+ } else if (-pos.x.px.round() == contentWidth) {
// If fully closed, mark the closedLatch if present
closedLatch?.countDown()
}
@@ -227,8 +227,8 @@
// Click on the left-center pixel of the drawer
findByTag("Drawer").doGesture {
- val left = 1.px
- val centerY = globalBounds.height / 2
+ val left = 1.0f
+ val centerY = (globalBounds.height / 2).value
sendClick(PxPosition(left, centerY))
}
@@ -251,10 +251,10 @@
drawerContent = {
Box(Modifier.fillMaxSize().onPositioned { info: LayoutCoordinates ->
val pos = info.localToGlobal(PxPosition.Origin)
- if (pos.y.round() == openedHeight) {
+ if (pos.y.px.round() == openedHeight) {
// If fully opened, mark the openedLatch if present
openedLatch?.countDown()
- } else if (pos.y.round() == contentHeight) {
+ } else if (pos.y.px.round() == contentHeight) {
// If fully closed, mark the closedLatch if present
closedLatch?.countDown()
}
@@ -326,8 +326,8 @@
// Click on the bottom-center pixel of the drawer
findByTag("Drawer").doGesture {
val bounds = globalBounds
- val centerX = bounds.width / 2
- val bottom = bounds.height - 1.px
+ val centerX = (bounds.width / 2).value
+ val bottom = (bounds.height - 1.px).value
sendClick(PxPosition(centerX, bottom))
}
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 d95ef48..6955ac6 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
@@ -60,6 +60,7 @@
import androidx.ui.unit.PxPosition
import androidx.ui.unit.dp
import androidx.ui.unit.ipx
+import androidx.ui.unit.px
import androidx.ui.unit.sp
import androidx.ui.unit.toPx
import com.google.common.truth.Truth.assertThat
@@ -200,10 +201,11 @@
assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
// centered position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().value.toFloat()
)
assertThat(labelPosition.value?.y).isEqualTo(
- ((ExpectedMinimumTextFieldHeight.toIntPx() - labelSize.value!!.height) / 2f).toPx()
+ ((ExpectedMinimumTextFieldHeight.toIntPx() - labelSize.value!!.height) / 2f)
+ .value.toFloat()
)
}
}
@@ -236,10 +238,10 @@
assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
// centered position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
assertThat(labelPosition.value?.y).isEqualTo(
- ((height.toIntPx() - labelSize.value!!.height) / 2f).toPx()
+ ((height.toIntPx() - labelSize.value!!.height) / 2f).toPx().value
)
}
}
@@ -248,7 +250,7 @@
fun testLabelPosition_whenFocused() {
val labelSize = Ref<IntPxSize>()
val labelPosition = Ref<PxPosition>()
- val baseline = Ref<Px>()
+ val baseline = Ref<Float>()
testRule.setMaterialContent {
Box {
FilledTextField(
@@ -260,7 +262,7 @@
labelPosition.value = it.globalPosition
labelSize.value = it.size
baseline.value =
- it[FirstBaseline]!!.toPx() + labelPosition.value!!.y
+ (it[FirstBaseline]!!.toPx() + labelPosition.value!!.y.px).value
})
}
)
@@ -277,10 +279,10 @@
assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
// label's top position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
assertThat(baseline.value).isEqualTo(
- ExpectedBaselineOffset.toIntPx().toPx()
+ ExpectedBaselineOffset.toIntPx().toPx().value
)
}
}
@@ -289,7 +291,7 @@
fun testLabelPosition_whenInput() {
val labelSize = Ref<IntPxSize>()
val labelPosition = Ref<PxPosition>()
- val baseline = Ref<Px>()
+ val baseline = Ref<Float>()
testRule.setMaterialContent {
Box {
FilledTextField(
@@ -300,7 +302,7 @@
labelPosition.value = it.globalPosition
labelSize.value = it.size
baseline.value =
- it[FirstBaseline]!!.toPx() + labelPosition.value!!.y
+ (it[FirstBaseline]!!.toPx() + labelPosition.value!!.y.px).value
})
}
)
@@ -314,10 +316,10 @@
assertThat(labelSize.value?.width).isGreaterThan(0.ipx)
// label's top position
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
assertThat(baseline.value).isEqualTo(
- ExpectedBaselineOffset.toIntPx().toPx()
+ ExpectedBaselineOffset.toIntPx().toPx().value
)
}
}
@@ -326,7 +328,7 @@
fun testPlaceholderPosition_withLabel() {
val placeholderSize = Ref<IntPxSize>()
val placeholderPosition = Ref<PxPosition>()
- val placeholderBaseline = Ref<Px>()
+ val placeholderBaseline = Ref<Float>()
testRule.setMaterialContent {
Box {
FilledTextField(
@@ -339,7 +341,8 @@
placeholderPosition.value = it.globalPosition
placeholderSize.value = it.size
placeholderBaseline.value =
- it[FirstBaseline]!!.toPx() + placeholderPosition.value!!.y
+ (it[FirstBaseline]!!.toPx() + placeholderPosition.value!!.y
+ .px).value
})
}
)
@@ -355,10 +358,10 @@
assertThat(placeholderSize.value?.width).isGreaterThan(0.ipx)
// placeholder's position
assertThat(placeholderPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
assertThat(placeholderBaseline.value).isEqualTo(
- ExpectedBaselineOffset.toIntPx().toPx() * 2
+ (ExpectedBaselineOffset.toIntPx().toPx() * 2).value
)
}
}
@@ -381,7 +384,7 @@
placeholderPosition.value = it.globalPosition
placeholderSize.value = it.size
placeholderBaseline.value =
- it[FirstBaseline]!!.toPx() + placeholderPosition.value!!.y
+ it[FirstBaseline]!!.toPx() + placeholderPosition.value!!.y.px
})
}
)
@@ -397,10 +400,10 @@
assertThat(placeholderSize.value?.width).isGreaterThan(0.ipx)
// centered position
assertThat(placeholderPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
assertThat(placeholderPosition.value?.y).isEqualTo(
- ((height.toIntPx() - placeholderSize.value!!.height) / 2f).toPx()
+ ((height.toIntPx() - placeholderSize.value!!.height) / 2f).toPx().value
)
}
}
@@ -490,18 +493,18 @@
testRule.runOnIdleComposeWithDensity {
// leading
assertThat(leadingSize.value).isEqualTo(IntPxSize(size.toIntPx(), size.toIntPx()))
- assertThat(leadingPosition.value?.x).isEqualTo(IconPadding.toIntPx().toPx())
+ assertThat(leadingPosition.value?.x).isEqualTo(IconPadding.toIntPx().toPx().value)
assertThat(leadingPosition.value?.y).isEqualTo(
- ((textFieldHeight.toIntPx() - leadingSize.value!!.height) / 2f).toPx()
+ ((textFieldHeight.toIntPx() - leadingSize.value!!.height) / 2f).toPx().value
)
// trailing
assertThat(trailingSize.value).isEqualTo(IntPxSize(size.toIntPx(), size.toIntPx()))
assertThat(trailingPosition.value?.x).isEqualTo(
(textFieldWidth.toIntPx() - IconPadding.toIntPx() - trailingSize.value!!.width)
- .toPx()
+ .toPx().value
)
assertThat(trailingPosition.value?.y).isEqualTo(
- ((textFieldHeight.toIntPx() - trailingSize.value!!.height) / 2f).toPx()
+ ((textFieldHeight.toIntPx() - trailingSize.value!!.height) / 2f).toPx().value
)
}
}
@@ -530,7 +533,8 @@
testRule.runOnIdleComposeWithDensity {
assertThat(labelPosition.value?.x).isEqualTo(
- (ExpectedPadding.toIntPx() + IconPadding.toIntPx() + iconSize.toIntPx()).toPx()
+ (ExpectedPadding.toIntPx() + IconPadding.toIntPx() + iconSize.toIntPx())
+ .toPx().value
)
}
}
@@ -558,7 +562,7 @@
testRule.runOnIdleComposeWithDensity {
assertThat(labelPosition.value?.x).isEqualTo(
- ExpectedPadding.toIntPx().toPx()
+ ExpectedPadding.toIntPx().toPx().value
)
}
}
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 59c481b..68495e1 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
@@ -45,6 +45,7 @@
import androidx.ui.unit.center
import androidx.ui.unit.dp
import androidx.ui.unit.height
+import androidx.ui.unit.px
import androidx.ui.unit.round
import androidx.ui.unit.toPx
import androidx.ui.unit.width
@@ -296,12 +297,12 @@
assertThat(iconBounds.width).isEqualTo(10.dp.toIntPx().toPx())
assertThat(iconBounds.height).isEqualTo(10.dp.toIntPx().toPx())
- assertWithinOnePixel(buttonBounds.center().y.value, iconBounds.center().y.value)
- assertWithinOnePixel(buttonBounds.center().y.value, textBounds.center().y.value)
+ assertWithinOnePixel(buttonBounds.center().y, iconBounds.center().y)
+ assertWithinOnePixel(buttonBounds.center().y, textBounds.center().y)
val halfPadding = 6.dp.toIntPx().toPx()
assertWithinOnePixel(
- (iconBounds.center().x + iconBounds.width / 2 + halfPadding).value,
- (textBounds.center().x - textBounds.width / 2 - halfPadding).value
+ (iconBounds.center().x.px + iconBounds.width / 2 + halfPadding).value,
+ (textBounds.center().x.px - textBounds.width / 2 - halfPadding).value
)
}
}
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 3722f51..dd359ac 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
@@ -79,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().toPx())
- Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().toPx())
+ Truth.assertThat(iconX).isEqualTo(12.dp.toIntPx().toPx().value)
+ Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().toPx().value)
}
}
@@ -104,8 +104,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
- val expectedX = ((48.dp - width) / 2).toIntPx().toPx()
- val expectedY = ((48.dp - height) / 2).toIntPx().toPx()
+ val expectedX = ((48.dp - width) / 2).toIntPx().toPx().value
+ val expectedY = ((48.dp - height) / 2).toIntPx().toPx().value
// Icon should be centered inside the IconButton
Truth.assertThat(iconX).isEqualTo(expectedX)
Truth.assertThat(iconY).isEqualTo(expectedY)
@@ -143,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().toPx())
- Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().toPx())
+ Truth.assertThat(iconX).isEqualTo(12.dp.toIntPx().toPx().value)
+ Truth.assertThat(iconY).isEqualTo(12.dp.toIntPx().toPx().value)
}
}
@@ -167,8 +167,8 @@
val iconX = iconCoords.positionInParent.x
val iconY = iconCoords.positionInParent.y
- val expectedX = ((48.dp - width) / 2).toIntPx().toPx()
- val expectedY = ((48.dp - height) / 2).toIntPx().toPx()
+ val expectedX = ((48.dp - width) / 2).toIntPx().toPx().value
+ val expectedY = ((48.dp - height) / 2).toIntPx().toPx().value
// 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/ListItemTest.kt b/ui/ui-material/src/androidTest/java/androidx/ui/material/ListItemTest.kt
index 456dd83..0db9b50 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
@@ -29,12 +29,9 @@
import androidx.ui.test.createComposeRule
import androidx.ui.unit.Dp
import androidx.ui.unit.IntPxSize
-import androidx.ui.unit.Px
import androidx.ui.unit.PxPosition
import androidx.ui.unit.dp
import androidx.ui.unit.ipx
-import androidx.ui.unit.px
-import androidx.ui.unit.toPx
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
@@ -205,17 +202,18 @@
}
}
composeTestRule.runOnIdleComposeWithDensity {
- assertThat(textPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(textPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().value
+ .toFloat())
assertThat(textPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).toPx()
+ ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).value.toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels.px - trailingSize.value!!.width -
- expectedRightPadding.toIntPx().toPx()
+ dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
+ expectedRightPadding.toIntPx().value.toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).toPx()
+ ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).value.toFloat()
)
}
}
@@ -239,16 +237,18 @@
}
}
composeTestRule.runOnIdleComposeWithDensity {
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx()
+ .value.toFloat())
assertThat(iconPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - iconSize.value!!.height) / 2).toPx()
+ ((listItemHeight.toIntPx() - iconSize.value!!.height) / 2).value.toFloat()
)
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedTextLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedTextLeftPadding.toIntPx().value.toFloat()
)
assertThat(textPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).toPx()
+ ((listItemHeight.toIntPx() - textSize.value!!.height) / 2).value.toFloat()
)
}
}
@@ -261,13 +261,13 @@
val expectedSecondaryTextBaselineOffset = 20.dp
val textPosition = Ref<PxPosition>()
- val textBaseline = Ref<Px>()
+ val textBaseline = Ref<Float>()
val textSize = Ref<IntPxSize>()
val secondaryTextPosition = Ref<PxPosition>()
- val secondaryTextBaseline = Ref<Px>()
+ val secondaryTextBaseline = Ref<Float>()
val secondaryTextSize = Ref<IntPxSize>()
val trailingPosition = Ref<PxPosition>()
- val trailingBaseline = Ref<Px>()
+ val trailingBaseline = Ref<Float>()
val trailingSize = Ref<IntPxSize>()
composeTestRule.setMaterialContent {
Box {
@@ -292,22 +292,24 @@
}
}
composeTestRule.runOnIdleComposeWithDensity {
- assertThat(textPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
- assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().toPx())
+ assertThat(textPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().value
+ .toFloat())
+ assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().value
+ .toFloat())
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().toPx() +
- expectedSecondaryTextBaselineOffset.toIntPx().toPx()
+ expectedTextBaseline.toIntPx().value.toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels.px - trailingSize.value!!.width -
- expectedRightPadding.toIntPx().toPx()
+ dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
+ expectedRightPadding.toIntPx().value.toFloat()
)
assertThat(trailingBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().toPx()
+ expectedTextBaseline.toIntPx().value.toFloat()
)
}
}
@@ -321,10 +323,10 @@
val expectedSecondaryTextBaselineOffset = 20.dp
val textPosition = Ref<PxPosition>()
- val textBaseline = Ref<Px>()
+ val textBaseline = Ref<Float>()
val textSize = Ref<IntPxSize>()
val secondaryTextPosition = Ref<PxPosition>()
- val secondaryTextBaseline = Ref<Px>()
+ val secondaryTextBaseline = Ref<Float>()
val secondaryTextSize = Ref<IntPxSize>()
val iconPosition = Ref<PxPosition>()
val iconSize = Ref<IntPxSize>()
@@ -352,21 +354,26 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
- assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().toPx())
+ assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().value
+ .toFloat())
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().toPx() +
- expectedSecondaryTextBaselineOffset.toIntPx().toPx()
+ expectedTextBaseline.toIntPx().value.toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
)
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(iconPosition.value!!.x).isEqualTo(
+ expectedLeftPadding.toIntPx().value.toFloat()
+ )
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().toPx()
+ expectedIconTopPadding.toIntPx().value.toFloat()
)
}
}
@@ -382,10 +389,10 @@
val expectedRightPadding = 16.dp
val textPosition = Ref<PxPosition>()
- val textBaseline = Ref<Px>()
+ val textBaseline = Ref<Float>()
val textSize = Ref<IntPxSize>()
val secondaryTextPosition = Ref<PxPosition>()
- val secondaryTextBaseline = Ref<Px>()
+ val secondaryTextBaseline = Ref<Float>()
val secondaryTextSize = Ref<IntPxSize>()
val iconPosition = Ref<PxPosition>()
val iconSize = Ref<IntPxSize>()
@@ -418,29 +425,33 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
- assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().toPx())
+ assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().value
+ .toFloat())
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().toPx() +
- expectedSecondaryTextBaselineOffset.toIntPx().toPx()
+ expectedTextBaseline.toIntPx().value.toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
)
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().value
+ .toFloat())
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().toPx()
+ expectedIconTopPadding.toIntPx().value.toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels.px - trailingSize.value!!.width -
- expectedRightPadding.toIntPx().toPx()
+ dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
+ expectedRightPadding.toIntPx().value.toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).toPx()
+ ((listItemHeight.toIntPx() - trailingSize.value!!.height) / 2).value.toFloat()
)
}
}
@@ -455,10 +466,10 @@
val expectedRightPadding = 16.dp
val textPosition = Ref<PxPosition>()
- val textBaseline = Ref<Px>()
+ val textBaseline = Ref<Float>()
val textSize = Ref<IntPxSize>()
val secondaryTextPosition = Ref<PxPosition>()
- val secondaryTextBaseline = Ref<Px>()
+ val secondaryTextBaseline = Ref<Float>()
val secondaryTextSize = Ref<IntPxSize>()
val iconPosition = Ref<PxPosition>()
val iconSize = Ref<IntPxSize>()
@@ -492,29 +503,33 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
- assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().toPx())
+ assertThat(textBaseline.value!!).isEqualTo(expectedTextBaseline.toIntPx().value
+ .toFloat())
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedTextBaseline.toIntPx().toPx() +
- expectedSecondaryTextBaselineOffset.toIntPx().toPx()
+ expectedTextBaseline.toIntPx().value.toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
)
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().value
+ .toFloat())
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().toPx()
+ expectedIconTopPadding.toIntPx().value.toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels.px - trailingSize.value!!.width -
- expectedRightPadding.toIntPx().toPx()
+ dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
+ expectedRightPadding.toIntPx().value.toFloat()
)
assertThat(trailingPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().toPx()
+ expectedIconTopPadding.toIntPx().value.toFloat()
)
}
}
@@ -530,19 +545,19 @@
val expectedRightPadding = 16.dp
val textPosition = Ref<PxPosition>()
- val textBaseline = Ref<Px>()
+ val textBaseline = Ref<Float>()
val textSize = Ref<IntPxSize>()
val overlineTextPosition = Ref<PxPosition>()
- val overlineTextBaseline = Ref<Px>()
+ val overlineTextBaseline = Ref<Float>()
val overlineTextSize = Ref<IntPxSize>()
val secondaryTextPosition = Ref<PxPosition>()
- val secondaryTextBaseline = Ref<Px>()
+ val secondaryTextBaseline = Ref<Float>()
val secondaryTextSize = Ref<IntPxSize>()
val iconPosition = Ref<PxPosition>()
val iconSize = Ref<IntPxSize>()
val trailingPosition = Ref<PxPosition>()
val trailingSize = Ref<IntPxSize>()
- val trailingBaseline = Ref<Px>()
+ val trailingBaseline = Ref<Float>()
composeTestRule.setMaterialContent {
Box {
ListItem(
@@ -590,40 +605,44 @@
}
composeTestRule.runOnIdleComposeWithDensity {
assertThat(textPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(textBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().toPx() +
- expectedTextBaselineOffset.toIntPx().toPx()
+ expectedOverlineBaseline.toIntPx().value.toFloat() +
+ expectedTextBaselineOffset.toIntPx().value.toFloat()
)
assertThat(overlineTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(overlineTextBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().toPx()
+ expectedOverlineBaseline.toIntPx().value.toFloat()
)
assertThat(secondaryTextPosition.value!!.x).isEqualTo(
- expectedLeftPadding.toIntPx().toPx() + iconSize.value!!.width +
- expectedContentLeftPadding.toIntPx().toPx()
+ expectedLeftPadding.toIntPx().value.toFloat() +
+ iconSize.value!!.width.value.toFloat() +
+ expectedContentLeftPadding.toIntPx().value.toFloat()
)
assertThat(secondaryTextBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().toPx() +
- expectedTextBaselineOffset.toIntPx().toPx() +
- expectedSecondaryTextBaselineOffset.toIntPx().toPx()
+ expectedOverlineBaseline.toIntPx().value.toFloat() +
+ expectedTextBaselineOffset.toIntPx().value.toFloat() +
+ expectedSecondaryTextBaselineOffset.toIntPx().value.toFloat()
)
- assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().toPx())
+ assertThat(iconPosition.value!!.x).isEqualTo(expectedLeftPadding.toIntPx().value
+ .toFloat())
assertThat(iconPosition.value!!.y).isEqualTo(
- expectedIconTopPadding.toIntPx().toPx()
+ expectedIconTopPadding.toIntPx().value.toFloat()
)
val dm = composeTestRule.displayMetrics
assertThat(trailingPosition.value!!.x).isEqualTo(
- dm.widthPixels.px - trailingSize.value!!.width -
- expectedRightPadding.toIntPx().toPx()
+ dm.widthPixels - trailingSize.value!!.width.value.toFloat() -
+ expectedRightPadding.toIntPx().value.toFloat()
)
assertThat(trailingBaseline.value!!).isEqualTo(
- expectedOverlineBaseline.toIntPx().toPx()
+ expectedOverlineBaseline.toIntPx().value.toFloat()
)
}
}
@@ -633,11 +652,11 @@
private fun saveLayout(
coords: Ref<PxPosition>,
size: Ref<IntPxSize>,
- baseline: Ref<Px> = Ref()
+ baseline: Ref<Float> = Ref()
): Modifier = Modifier.onPositioned { coordinates: LayoutCoordinates ->
coords.value = coordinates.localToGlobal(PxPosition.Origin)
- baseline.value = coordinates[FirstBaseline]?.toPx()?.let {
- it + coords.value!!.y
+ baseline.value = coordinates[FirstBaseline]?.value?.toFloat()?.let {
+ (it + coords.value!!.y)
}
size.value = coordinates.size
}
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 7e8f4ef..96945bc 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
@@ -132,7 +132,8 @@
)
}
}
- assertThat(appbarPosition.y + appbarSize.height).isEqualTo(contentPosition.y)
+ assertThat(appbarPosition.y + appbarSize.height.value.toFloat())
+ .isEqualTo(contentPosition.y)
}
@Test
@@ -166,8 +167,8 @@
)
}
}
- val appBarBottom = appbarPosition.y + appbarSize.height
- val contentBottom = contentPosition.y + contentSize.height
+ val appBarBottom = appbarPosition.y + appbarSize.height.value
+ val contentBottom = contentPosition.y + contentSize.height.value
assertThat(appBarBottom).isEqualTo(contentBottom)
}
@@ -200,15 +201,15 @@
}
}
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
findByTag(scaffoldTag).doGesture {
sendSwipeRight()
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
findByTag(scaffoldTag).doGesture {
sendSwipeLeft()
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
runOnUiThread {
scaffoldState.isDrawerGesturesEnabled = true
@@ -217,11 +218,11 @@
findByTag(scaffoldTag).doGesture {
sendSwipeRight()
}
- assertThat(drawerChildPosition.x).isEqualTo(0.px)
+ assertThat(drawerChildPosition.x).isEqualTo(0f)
findByTag(scaffoldTag).doGesture {
sendSwipeLeft()
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
}
@Test
@@ -253,15 +254,15 @@
}
}
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
runOnUiThread {
scaffoldState.drawerState = DrawerState.Opened
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
runOnUiThread {
scaffoldState.drawerState = DrawerState.Closed
}
- assertThat(drawerChildPosition.x).isLessThan(0.px)
+ assertThat(drawerChildPosition.x).isLessThan(0f)
}
@Test
@@ -298,7 +299,7 @@
Text("body")
}
}
- val expectedFabY = bottomBarPosition.y - fabSize.height / 2
+ val expectedFabY = bottomBarPosition.y - (fabSize.height / 2).value
assertThat(fabPosition.y).isEqualTo(expectedFabY)
}
@@ -337,7 +338,7 @@
Text("body")
}
}
- val expectedFabY = bottomBarPosition.y - fabSize.height / 2
+ val expectedFabY = bottomBarPosition.y - (fabSize.height / 2).value
assertThat(fabPosition.y).isEqualTo(expectedFabY)
}
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 9068ae4..8b504e6 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
@@ -44,13 +44,14 @@
import androidx.ui.unit.IntPx
import androidx.ui.unit.PxPosition
import androidx.ui.unit.dp
-import androidx.ui.unit.round
+import androidx.ui.unit.ipx
import androidx.ui.unit.toPx
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
+import kotlin.math.roundToInt
@MediumTest
@RunWith(JUnit4::class)
@@ -110,7 +111,8 @@
assertThat(it[FirstBaseline])
.isEqualTo(it[LastBaseline])
// TODO(aelias): Remove 'parentCoordinates!!' when Semantics no longer using PassThroughLayout
- assertThat(it.parentCoordinates!!.positionInParent.y.round() + it[FirstBaseline]!!)
+ assertThat(it.parentCoordinates!!.positionInParent.y.roundToInt().ipx +
+ it[FirstBaseline]!!)
.isEqualTo(30.dp.toIntPx())
}
}
@@ -167,11 +169,11 @@
assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
assertThat(localButtonTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
assertThat(
- localTextCoords.globalPosition.y.round() +
+ localTextCoords.globalPosition.y.roundToInt().ipx +
localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
assertThat(
- buttonTextPos.y.round() + localButtonTextCoords[FirstBaseline]!!
+ buttonTextPos.y.roundToInt().ipx + localButtonTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
}
}
@@ -201,7 +203,8 @@
assertThat(it[FirstBaseline]).isNotEqualTo(it[LastBaseline])
// TODO(aelias): Remove 'parentCoordinates!!' when Semantics no longer using PassThroughLayout
assertThat(
- it.parentCoordinates!!.positionInParent.y.round() + it[FirstBaseline]!!
+ it.parentCoordinates!!.positionInParent.y.roundToInt().ipx +
+ it[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
}
}
@@ -246,18 +249,20 @@
val buttonPositionInSnack =
localSnackCoords.childToLocal(localButtonCoords, PxPosition.Origin)
val buttonCenter =
- buttonPositionInSnack.y + localButtonCoords.size.height / 2
+ buttonPositionInSnack.y.roundToInt() +
+ (localButtonCoords.size.height / 2).value.toFloat()
assertThat(localTextCoords[FirstBaseline]).isNotEqualTo(IntPx.Zero)
assertThat(localTextCoords[LastBaseline]).isNotEqualTo(IntPx.Zero)
assertThat(localTextCoords[FirstBaseline])
.isNotEqualTo(localTextCoords[LastBaseline])
assertThat(
- localTextCoords.globalPosition.y.round() +
+ localTextCoords.globalPosition.y.roundToInt().ipx +
localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
- assertThat(buttonCenter).isEqualTo((localSnackCoords.size.height / 2).toPx())
+ assertThat(buttonCenter)
+ .isEqualTo((localSnackCoords.size.height / 2).value.toFloat())
}
}
}
@@ -303,21 +308,22 @@
localSnackCoords.childToLocal(localTextCoords, PxPosition.Origin)
assertThat(
- textPositionInSnack.y.round() + localTextCoords[FirstBaseline]!!
+ textPositionInSnack.y.roundToInt().ipx + localTextCoords[FirstBaseline]!!
).isEqualTo(30.dp.toIntPx())
assertThat(
- buttonPositionInSnack.y.round() - textPositionInSnack.y.round() -
+ buttonPositionInSnack.y.roundToInt().ipx -
+ textPositionInSnack.y.roundToInt().ipx -
localTextCoords[LastBaseline]!!
).isEqualTo(18.dp.toIntPx())
assertThat(
- localSnackCoords.size.height - buttonPositionInSnack.y.round() -
+ localSnackCoords.size.height - buttonPositionInSnack.y.roundToInt().ipx -
localButtonCoords.size.height
).isEqualTo(8.dp.toIntPx())
assertThat(
- localSnackCoords.size.width - buttonPositionInSnack.x.round() -
+ localSnackCoords.size.width - buttonPositionInSnack.x.roundToInt().ipx -
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 e8cb5a6..c61b4b7 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
@@ -45,7 +45,6 @@
import androidx.ui.test.findAll
import androidx.ui.test.isInMutuallyExclusiveGroup
import androidx.ui.test.runOnIdleCompose
-import androidx.ui.unit.Px
import androidx.ui.unit.PxPosition
import androidx.ui.unit.dp
import androidx.ui.unit.toPx
@@ -147,12 +146,12 @@
val tabRowWidth = tabRowCoords.size.width
val tabRowHeight = tabRowCoords.size.height
- val indicatorPositionX = indicatorCoords.localToGlobal(PxPosition.Origin).x.value
+ val indicatorPositionX = indicatorCoords.localToGlobal(PxPosition.Origin).x
val expectedPositionX = 0.dp.toPx()
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(PxPosition.Origin).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx().value
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
tabRowWidth to tabRowHeight
@@ -166,11 +165,11 @@
runOnIdleCompose {
with(composeTestRule.density) {
val indicatorPositionX = indicatorCoords.localToGlobal(PxPosition.Origin).x
- val expectedPositionX = tabRowWidth / 2
- assertThat(indicatorPositionX).isEqualTo(expectedPositionX.toPx())
+ val expectedPositionX = (tabRowWidth / 2).value.toFloat()
+ assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(PxPosition.Origin).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx().value
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
}
}
@@ -180,7 +179,7 @@
fun singleLineTab_textBaseline() {
lateinit var tabRowCoords: LayoutCoordinates
lateinit var textCoords: LayoutCoordinates
- var textBaseline: Px = Px(Float.NEGATIVE_INFINITY)
+ var textBaseline = Float.NEGATIVE_INFINITY
composeTestRule.setMaterialContent {
var state by state { 0 }
@@ -196,7 +195,7 @@
text = {
Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.toPx()
+ textBaseline = coords[LastBaseline]!!.toPx().value
})
},
selected = state == index,
@@ -216,7 +215,7 @@
val textPositionY = textCoords.localToGlobal(PxPosition.Origin).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = tabRowHeight.toPx() - expectedBaselineDistance
+ val expectedPositionY = (tabRowHeight.toPx() - expectedBaselineDistance).value
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -225,7 +224,7 @@
fun singleLineTab_withIcon_textBaseline() {
lateinit var tabRowCoords: LayoutCoordinates
lateinit var textCoords: LayoutCoordinates
- var textBaseline: Px = Px(Float.NEGATIVE_INFINITY)
+ var textBaseline = Float.NEGATIVE_INFINITY
composeTestRule.setMaterialContent {
var state by state { 0 }
@@ -241,7 +240,7 @@
text = {
Text(text, Modifier.onPositioned { coords: LayoutCoordinates ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.toPx()
+ textBaseline = coords[LastBaseline]!!.toPx().value
})
},
icon = { Icon(Icons.Filled.Favorite) },
@@ -262,7 +261,7 @@
val textPositionY = textCoords.localToGlobal(PxPosition.Origin).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = tabRowHeight.toPx() - expectedBaselineDistance
+ val expectedPositionY = (tabRowHeight.toPx() - expectedBaselineDistance).value
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -271,7 +270,7 @@
fun twoLineTab_textBaseline() {
lateinit var tabRowCoords: LayoutCoordinates
lateinit var textCoords: LayoutCoordinates
- var textBaseline: Px = Px(Float.NEGATIVE_INFINITY)
+ var textBaseline = Float.NEGATIVE_INFINITY
composeTestRule.setMaterialContent {
var state by state { 0 }
@@ -287,7 +286,7 @@
text = {
Text(text, Modifier.preferredWidth(100.dp).onPositioned { coords ->
textCoords = coords
- textBaseline = coords[LastBaseline]!!.toPx()
+ textBaseline = coords[LastBaseline]!!.toPx().value
}, maxLines = 2)
},
selected = state == index,
@@ -307,7 +306,7 @@
val textPositionY = textCoords.localToGlobal(PxPosition.Origin).y
val baselinePositionY = textPositionY + textBaseline
- val expectedPositionY = tabRowHeight.toPx() - expectedBaselineDistance
+ val expectedPositionY = (tabRowHeight.toPx() - expectedBaselineDistance).value
assertThat(baselinePositionY).isEqualTo(expectedPositionY)
}
}
@@ -358,11 +357,11 @@
// Indicator should be placed in the bottom left of the first tab
val indicatorPositionX = indicatorCoords.localToGlobal(PxPosition.Origin).x
// Tabs in a scrollable tab row are offset 52.dp from each end
- val expectedPositionX = scrollableTabRowOffset.toIntPx().toPx()
+ val expectedPositionX = scrollableTabRowOffset.toIntPx().toPx().value
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(PxPosition.Origin).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx().value
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
tabRowHeight
@@ -375,11 +374,12 @@
// should be in the middle of the TabRow
composeTestRule.runOnIdleComposeWithDensity {
val indicatorPositionX = indicatorCoords.localToGlobal(PxPosition.Origin).x
- val expectedPositionX = (scrollableTabRowOffset + minimumTabWidth).toIntPx().toPx()
+ val expectedPositionX = (scrollableTabRowOffset + minimumTabWidth).toIntPx()
+ .toPx().value
assertThat(indicatorPositionX).isEqualTo(expectedPositionX)
val indicatorPositionY = indicatorCoords.localToGlobal(PxPosition.Origin).y
- val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx()
+ val expectedPositionY = (tabRowHeight - indicatorHeight.toIntPx()).toPx().value
assertThat(indicatorPositionY).isEqualTo(expectedPositionY)
}
}
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 4ede707..a502104 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
@@ -127,7 +127,7 @@
val pressed = state { false }
val press = Modifier.pressIndicatorGestureFilter(
pos ->
- position.holder.snapTo(pos.x.value)
+ position.holder.snapTo(pos.x)
pressed.value = true
},
>
diff --git a/ui/ui-material/src/main/java/androidx/ui/material/ripple/DefaultRippleEffect.kt b/ui/ui-material/src/main/java/androidx/ui/material/ripple/DefaultRippleEffect.kt
index 20b689e..321f2fd 100644
--- a/ui/ui-material/src/main/java/androidx/ui/material/ripple/DefaultRippleEffect.kt
+++ b/ui/ui-material/src/main/java/androidx/ui/material/ripple/DefaultRippleEffect.kt
@@ -247,7 +247,8 @@
* - fits within the border of the surface it belongs to for unbounded ripples
*/
internal fun Density.getRippleEndRadius(bounded: Boolean, size: PxSize): Float {
- val radiusCoveringBounds = (PxPosition(size.width, size.height).getDistance() / 2f).value
+ val radiusCoveringBounds =
+ (PxPosition(size.width.value, size.height.value).getDistance() / 2f).value
return if (bounded) {
radiusCoveringBounds + BoundedRippleExtraRadius.toPx()
} else {