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/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())
)
}