On Thu, 23 Feb 2023 16:29:29 GMT, Andy Goryachev <[email protected]> wrote:
>> modules/javafx.controls/src/main/java/javafx/scene/control/skin/TextFieldSkin.java
>> line 805:
>>
>>> 803: // appear at the left of the centered prompt.
>>> 804: newX = midPoint -
>>> promptNode.getLayoutBounds().getWidth() / 2;
>>> 805: if (newX > 0) {
>>
>> Let's say `caretWidth / 2` is 5, and that would be position we would show
>> the prompt text if it doesn't fit.
>>
>> If the `newX` calculation is less than 5, but greater than 0, the prompt
>> text would be further to the left than you'd expect.
>>
>> So I think this line should be:
>>
>> Suggestion:
>>
>> if (newX > caretWidth / 2) {
>>
>>
>> Probably best to put that in a local variable.
>
> this is undocumented, I think, but the caret path can be one of the three
> things:
> 1. a single point (MoveTo, I think)
> 2. a single line - MoveTo followed by a LineTo
> 3. two separate lines (split caret) - MoveTo, LineTo, MoveTo, LineTo (split
> caret is explicitly ignored on line 252)
>
> One would think that the caret width can be changed by CSS, but it is not
> easy. The caretPath on TextInputControl:184 has no CSS class name set, so
> the width cannot be changed trivially via a stylesheet. I suppose the
> application code can dig the internals looking for paths and setting widths
> manually, but this would be a highly unreliable move.
>
> So I think this caretWidth can be other than 1.0 (line 233) for the purposes
> of this PR.
> Thanks for these details @andy-goryachev-oracle . I was trying to figure out
> how I can change the caret width. Just to check the behavior of text
> alignment, I changed the hard coded value at line no 233.
>
> > Let's say `caretWidth / 2` is 5, and that would be position we would show
> > the prompt text if it doesn't fit.
> > If the `newX` calculation is less than 5, but greater than 0, the prompt
> > text would be further to the left than you'd expect.
> > So I think this line should be:
> > Probably best to put that in a local variable.
>
> The newX is calculated symmetrically from midpoint using the text length. If
> we consider the condition `newX > careWidth/2`, we will be aligning the text
> at the position of `caretWidth/2` even when there is space for the whole
> text. Which means that the text will be aligned to left even when there is
> space for whole text with CENTER alignment. So in my opinion, current
> conditions and values gives better alignment behavior.
Alright, thanks for checking this.
-------------
PR: https://git.openjdk.org/jfx/pull/980