Skip to content

Commit

Permalink
Fix z-order for text field/area placeholder (#615)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rock3r authored Sep 30, 2024
1 parent 44c0d60 commit 6c1317e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions ui/src/main/kotlin/org/jetbrains/jewel/ui/component/TextField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
}

Expand Down

0 comments on commit 6c1317e

Please sign in to comment.