Issue with Textfield edition when text alignment is defined as right

31 views
Skip to first unread message

Thomas

unread,
Apr 25, 2018, 12:22:54 AM4/25/18
to CodenameOne Discussions
I have some editable TextFields where I defined the text alignment as `alignment:right`. They are correctly rendered exept when the user try to edit them. In that case, the text is automatically re-aligned to the left of the TextField until the edition stops (i.e the textfield lose focus) and the text is then switch back to the right. 
This is rather disturbing for the user. So is it possible to have a text grow from the right when its alignment is defined as right? (I don't know, in the case of  RTL languages how it is implemented in CN1 but the default behaviour should be probably similar (the rendered text grow from right to left exept that the next character is rendered at the left of the previous one instead of beeing at its right and to push the previous ones to the left) so most of the logic is probably already implemented) 


IDE: Eclipse
Windows 10 x64
Simulator

Shai Almog

unread,
Apr 25, 2018, 1:39:08 AM4/25/18
to CodenameOne Discussions
RTL is a very different thing as the input is naturally from right to left so if you use the rtl flag instead of alignment you might get the behavior your are seeking. Notice you can enable that on a specific component only using setRTL().

Generally text field/area alignment is a problematic subject as the process of getting consistent results with native here is pretty difficult.

Thomas

unread,
Apr 25, 2018, 1:48:54 AM4/25/18
to CodenameOne Discussions
I don't think setting the RTL flag to true will fix my issue. Because in an RTL language, even if the text grow from right to left, new characters should be append left. For example, suppose I have the string abc . If I type `d`, the new string would be `dabc` with the RTL flag. Whereas what I want is `abcd` (even if my text is aligned right, I still want new characters to be append right when editing)

Thomas

unread,
Apr 25, 2018, 1:58:32 AM4/25/18
to CodenameOne Discussions
EDIT: I should have said, "if I have the displayed text `abc`" because in RTL languages the text `abc` actually matches the String `cba` and the String `cba` is displayed as the text `abc` but you probably got me there ;)

Shai Almog

unread,
Apr 25, 2018, 3:19:47 AM4/25/18
to CodenameOne Discussions
RTL is the wrong word here. It's bidi: bi-directional.
When you turn on RTL it treats the field as RTL but if you type with an LTR language it will type it correctly otherwise Hebrew speakers wouldn't be able to type numbers ;-)

Thomas

unread,
Apr 25, 2018, 1:08:14 PM4/25/18
to CodenameOne Discussions
OK. I achieved to obtain what I want on android by setting RTL to true and alignment to left. On the simulator however, the beahviour is different and impossible to get it right (so I will just hope that on iOS it is also OK cause I can't test it for now).
One thing that is quite misleading is that when setting RTL to true, TextField text alignment direction are inverted (so setting the text alignment to left would actually align the text to the right of the screen):  https://streamable.com/pvlip

Also, wanted to point out that there seems to be a bug in the CN1 GUI builder. When I check the RTL advanced property of a TextField (to set it to true), this is not transposed into the generated java code (the rTL="true" tag is correctly present in the .gui XML file generated by the GUI builder but the setRTL(true) method is never called into the generated java code (maybe because the XML rTL flag has a lowercase r ?). So I had to add it manually to make it work)

Shai Almog

unread,
Apr 26, 2018, 12:19:35 AM4/26/18
to CodenameOne Discussions
Left/right are flipped in RTL. A lot of frameworks get this wrong IMO. As an RTL language speaker (sufferer) this is the "right thing(tm)".

Thanks for the bug report, damn case sensitivity oddness.
Reply all
Reply to author
Forward
0 new messages