Skip to content

Commit 7e7e8c3

Browse files
authored
Rename geometry functions (#3029)
1 parent 84e92bf commit 7e7e8c3

37 files changed

Lines changed: 159 additions & 174 deletions

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/v2/SwingDialog.desktop.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import androidx.compose.ui.util.windowListenerRef
4040
import androidx.compose.ui.window.DialogWindowScope
4141
import androidx.compose.ui.window.UndecoratedWindowDecoration
4242
import androidx.compose.ui.window.WindowDecoration
43-
import androidx.compose.ui.window.asDpRect
43+
import androidx.compose.ui.window.toDpRect
4444
import androidx.compose.ui.window.resizerThickness
4545
import androidx.compose.ui.window.roundToDimensionOrNull
4646
import androidx.compose.ui.window.v2.DialogState
@@ -196,7 +196,7 @@ fun SwingDialog(
196196
dlg,
197197
object : ComponentAdapter() {
198198
fun applyBoundsChanges() {
199-
currentState._bounds = dlg.bounds.asDpRect()
199+
currentState._bounds = dlg.bounds.toDpRect()
200200
if (currentState._screenId != dlg.graphicsConfiguration.device.iDstring) {
201201
currentState._screenId = dlg.graphicsConfiguration.device.iDstring
202202
}

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/awt/v2/SwingWindow.desktop.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ import androidx.compose.ui.window.UndecoratedWindowDecoration
4646
import androidx.compose.ui.window.WindowDecoration
4747
import androidx.compose.ui.window.WindowLocationTracker
4848
import androidx.compose.ui.window.WindowPlacement
49-
import androidx.compose.ui.window.asDpRect
49+
import androidx.compose.ui.window.toDpRect
5050
import androidx.compose.ui.window.resizerThickness
5151
import androidx.compose.ui.window.roundToDimensionOrNull
5252
import androidx.compose.ui.window.v2.WindowBoundsProvider
@@ -189,7 +189,7 @@ fun SwingWindow(
189189
wnd,
190190
object : ComponentAdapter() {
191191
fun applyBoundsChanges() {
192-
currentState._bounds = wnd.bounds.asDpRect()
192+
currentState._bounds = wnd.bounds.toDpRect()
193193
if (currentState._screenId != wnd.graphicsConfiguration.device.iDstring) {
194194
currentState._screenId = wnd.graphicsConfiguration.device.iDstring
195195
}

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/AwtDragAndDropManager.desktop.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import androidx.compose.ui.unit.Density
3636
import androidx.compose.ui.unit.IntOffset
3737
import androidx.compose.ui.unit.LayoutDirection
3838
import androidx.compose.ui.unit.toOffset
39-
import androidx.compose.ui.window.asDpOffset
39+
import androidx.compose.ui.window.toDpOffset
4040
import androidx.compose.ui.window.density
4141
import androidx.compose.ui.window.layoutDirectionFor
4242
import java.awt.Image
@@ -88,7 +88,7 @@ internal class AwtDragAndDropManager(
8888
private val density: Density
8989
get() = rootContainer.density
9090

91-
private fun Point.toOffset() = asDpOffset().toOffset(density)
91+
private fun Point.toOffset() = toDpOffset().toOffset(density)
9292

9393
override val isRequestDragAndDropTransferRequired: Boolean
9494
get() = true

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/PlatformWindowContext.desktop.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import androidx.compose.ui.input.pointer.PointerKeyboardModifiers
2424
import androidx.compose.ui.unit.roundToIntSize
2525
import androidx.compose.ui.unit.toOffset
2626
import androidx.compose.ui.window.Dialog
27-
import androidx.compose.ui.window.asDpOffset
28-
import androidx.compose.ui.window.asDpSize
27+
import androidx.compose.ui.window.toDpOffset
28+
import androidx.compose.ui.window.toDpSize
2929
import androidx.compose.ui.window.density
3030
import androidx.compose.ui.window.sizeInPx
3131
import java.awt.Component
@@ -63,14 +63,14 @@ internal class PlatformWindowContext {
6363

6464
fun setContainerSizeFromComponent(component: Component) {
6565
_windowInfo.containerSize = component.sizeInPx.roundToIntSize()
66-
_windowInfo.containerDpSize = component.size.asDpSize()
66+
_windowInfo.containerDpSize = component.size.toDpSize()
6767
}
6868

6969
fun convertLocalToWindowPosition(container: Component, localPosition: Offset) =
70-
localPosition + offsetInWindow(container).asDpOffset().toOffset(container.density)
70+
localPosition + offsetInWindow(container).toDpOffset().toOffset(container.density)
7171

7272
fun convertWindowToLocalPosition(container: Component, positionInWindow: Offset) =
73-
positionInWindow - offsetInWindow(container).asDpOffset().toOffset(container.density)
73+
positionInWindow - offsetInWindow(container).toDpOffset().toOffset(container.density)
7474

7575
/**
7676
* If the [component]'s location on screen is undefined, returns [Offset.Unspecified]; otherwise
@@ -85,7 +85,7 @@ internal class PlatformWindowContext {
8585
val frame = SwingUtilities.getWindowAncestor(component) as? Frame
8686
if ((frame != null) && (frame.state == Frame.ICONIFIED)) return Offset.Unspecified
8787

88-
return block(component.locationOnScreen.asDpOffset().toOffset(component.density))
88+
return block(component.locationOnScreen.toDpOffset().toOffset(component.density))
8989
}
9090

9191
fun convertLocalToScreenPosition(container: Component, localPosition: Offset): Offset {

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/platform/a11y/ComposeAccessible.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import androidx.compose.ui.unit.toOffset
4343
import androidx.compose.ui.util.fastForEach
4444
import androidx.compose.ui.util.fastJoinToString
4545
import androidx.compose.ui.util.fastRoundToInt
46-
import androidx.compose.ui.window.asDpOffset
46+
import androidx.compose.ui.window.toDpOffset
4747
import java.awt.Color
4848
import java.awt.Cursor
4949
import java.awt.Dimension
@@ -232,7 +232,7 @@ internal class ComposeAccessible(
232232
}
233233

234234
private fun Point.toComposeOffset() =
235-
asDpOffset().toOffset(density)
235+
toDpOffset().toOffset(density)
236236

237237
private fun Dp.toAwtPx() =
238238
if (value.isInfinite()) Constraints.Infinity else value.fastRoundToInt()

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/scene/ComposeSceneMediator.desktop.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ import androidx.compose.ui.util.fastCoerceAtLeast
7171
import androidx.compose.ui.util.fastRoundToInt
7272
import androidx.compose.ui.viewinterop.SwingInteropContainer
7373
import androidx.compose.ui.window.WindowExceptionHandler
74-
import androidx.compose.ui.window.asDpOffset
74+
import androidx.compose.ui.window.toDpOffset
7575
import androidx.compose.ui.window.density
7676
import androidx.compose.ui.window.sizeInPx
7777
import java.awt.Component
@@ -475,7 +475,7 @@ internal class ComposeSceneMediator(
475475
get() {
476476
val pointInContainer = SwingUtilities.convertPoint(component, point, container)
477477
val offset = sceneBoundsInPx?.topLeft ?: Offset.Zero
478-
return pointInContainer.asDpOffset().toOffset(contentComponent.density) - offset
478+
return pointInContainer.toDpOffset().toOffset(contentComponent.density) - offset
479479
}
480480

481481
private fun onMouseEvent(event: MouseEvent): Unit = catchExceptions {

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/Geometry.desktop.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ import java.awt.Point
2828
import java.awt.Rectangle
2929
import kotlin.math.roundToInt
3030

31-
internal val Dimension.rightBottom get() = Point(width, height)
31+
internal val Dimension.bottomRight get() = Point(width, height)
3232
internal operator fun Point.plus(other: Point) = Point(x + other.x, y + other.y)
3333
internal operator fun Point.minus(other: Point) = Point(x - other.x, y - other.y)
3434

35-
internal val Rectangle.leftTop get() = Point(x, y)
36-
internal val Rectangle.rightBottom get() = Point(x + width, y + height)
35+
internal val Rectangle.topLeft get() = Point(x, y)
36+
internal val Rectangle.bottomRight get() = Point(x + width, y + height)
3737

38-
internal fun Dimension.asDpSize() = DpSize(width.dp, height.dp)
39-
internal fun Point.asDpOffset() = DpOffset(x.dp, y.dp)
40-
internal fun Rectangle.asDpRect() = DpRect(
38+
internal fun Dimension.toDpSize() = DpSize(width.dp, height.dp)
39+
internal fun Point.toDpOffset() = DpOffset(x.dp, y.dp)
40+
internal fun Rectangle.toDpRect() = DpRect(
4141
left = x.dp,
4242
top = y.dp,
4343
right = (x + width).dp,

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/LayoutConfiguration.desktop.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ internal val GlobalDensity get() = GraphicsEnvironment.getLocalGraphicsEnvironme
4343
internal val Component.density: Density get() = graphicsConfiguration.density
4444

4545
internal val Component.sizeInPx: Size
46-
get() = size.asDpSize().toSize(density)
46+
get() = size.toDpSize().toSize(density)
4747

4848
private val GraphicsConfiguration.density: Density get() = Density(
4949
defaultTransform.scaleX.toFloat(),

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/UndecoratedWindowResizer.desktop.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,19 @@ internal class UndecoratedWindowResizer(
7272
val right = measurables[1].measureSide(b, constraints.maxHeight - 2 * b)
7373
val top = measurables[2].measureSide(constraints.maxWidth - 2 * b, b)
7474
val bottom = measurables[3].measureSide(constraints.maxWidth - 2 * b, b)
75-
val leftTop = measurables[4].measureSide(b, b)
76-
val rightTop = measurables[5].measureSide(b, b)
77-
val leftBottom = measurables[6].measureSide(b, b)
78-
val rightBottom = measurables[7].measureSide(b, b)
75+
val topLeft = measurables[4].measureSide(b, b)
76+
val topRight = measurables[5].measureSide(b, b)
77+
val bottomLeft = measurables[6].measureSide(b, b)
78+
val bottomRight = measurables[7].measureSide(b, b)
7979
layout(constraints.maxWidth, constraints.maxHeight) {
8080
left.place(0, b)
8181
right.place(constraints.maxWidth - b, b)
8282
top.place(b, 0)
8383
bottom.place(0, constraints.maxHeight - b)
84-
leftTop.place(0, 0)
85-
rightTop.place(constraints.maxWidth - b, 0)
86-
leftBottom.place(0, constraints.maxHeight - b)
87-
rightBottom.place(constraints.maxWidth - b, constraints.maxHeight - b)
84+
topLeft.place(0, 0)
85+
topRight.place(constraints.maxWidth - b, 0)
86+
bottomLeft.place(0, constraints.maxHeight - b)
87+
bottomRight.place(constraints.maxWidth - b, constraints.maxHeight - b)
8888
}
8989
}
9090
)

compose/ui/ui/src/desktopMain/kotlin/androidx/compose/ui/window/WindowLocationTracker.desktop.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,13 @@ internal object WindowLocationTracker {
7979
val graphicsConfiguration = graphicsDevice.defaultConfiguration
8080
val screenBounds = graphicsConfiguration.bounds
8181
val screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(graphicsConfiguration)
82-
val screenLeftTop = screenBounds.leftTop + Point(screenInsets.left, screenInsets.top)
83-
val screenRightBottom = screenBounds.rightBottom - Point(screenInsets.right, screenInsets.bottom)
82+
val screenLeftTop = screenBounds.topLeft + Point(screenInsets.left, screenInsets.top)
83+
val screenBottomRight = screenBounds.bottomRight - Point(screenInsets.right, screenInsets.bottom)
8484

8585
val lastLocation = lastFocusedWindow?.location ?: screenLeftTop
8686
var location = lastLocation + cascadeOffset
87-
val rightBottom = location + windowSize.rightBottom
88-
if (rightBottom.x > screenRightBottom.x || rightBottom.y > screenRightBottom.y) {
87+
val bottomRight = location + windowSize.bottomRight
88+
if (bottomRight.x > screenBottomRight.x || bottomRight.y > screenBottomRight.y) {
8989
location = screenLeftTop + cascadeOffset
9090
}
9191
return location

0 commit comments

Comments
 (0)