From 6c1317ea93c3b6c5cd6abd2458be2e4e48c2481c Mon Sep 17 00:00:00 2001 From: Sebastiano Poggi Date: Mon, 30 Sep 2024 12:00:53 +0200 Subject: [PATCH] Fix z-order for text field/area placeholder (#615) This changes the order in which the placeholder and actual text field are laid out in the TextField and TextArea code. Since the two have the same zIndex (the default value, 0f) their placement order is reflected in the drawing order: the last placed is drawn last, on top of the rest. This fixes a minor cosmetic issue, where the placeholder would be drawn on top of the cursor when the TextArea/TextField is empty. --- .../org/jetbrains/jewel/ui/component/TextArea.kt | 6 +++--- .../org/jetbrains/jewel/ui/component/TextField.kt | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextArea.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextArea.kt index e725f2d2f..3708f46dc 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextArea.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextArea.kt @@ -339,11 +339,11 @@ private fun TextAreaDecorationBox( val height = calculateHeight(textAreaPlaceable, placeholderPlaceable, incomingConstraints) layout(width, height) { + // Placed similar to the input text below + placeholderPlaceable?.placeRelative(0, 0) + // Placed top-start textAreaPlaceable.placeRelative(0, 0) - - // Placed similar to the input text above - placeholderPlaceable?.placeRelative(0, 0) } } } diff --git a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextField.kt b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextField.kt index dbd649343..94a2646aa 100644 --- a/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextField.kt +++ b/ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextField.kt @@ -325,16 +325,16 @@ private fun Placeable.PlacementScope.place( Alignment.CenterVertically.align(trailingPlaceable.height, height), ) - // placed center vertically - textFieldPlaceable.placeRelative( + // placed similar to the input text below + placeholderPlaceable?.placeRelative( leadingPlaceable?.width ?: 0, - Alignment.CenterVertically.align(textFieldPlaceable.height, height), + Alignment.CenterVertically.align(placeholderPlaceable.height, height), ) - // placed similar to the input text above - placeholderPlaceable?.placeRelative( + // placed center vertically + textFieldPlaceable.placeRelative( leadingPlaceable?.width ?: 0, - Alignment.CenterVertically.align(placeholderPlaceable.height, height), + Alignment.CenterVertically.align(textFieldPlaceable.height, height), ) }