Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineEdit last characters disappear with text align=right and using a Dynamic font with char_space>0 #34951

Open
Kritjan opened this issue Jan 9, 2020 · 6 comments

Comments

@Kritjan
Copy link

Kritjan commented Jan 9, 2020

Godot version:
Godot 3.1 release / 3.2-beta 5

OS/device including version:
Windows 10 / GTX 1060

Issue description:
I have used a DynamicFont with char_space=2 in a LineEdit.
If you set the alignment to left, center, or fill everything works fine, but after changing the aligment of the LineEdit text to right aligned the last characters of the text disappear.
After setting the char_space of the font back to 0 the full text of the LineEdit visible using right alignment.

Steps to reproduce:
Create a LineEdit control which has the text right aligned.
Add a DynamicFont to the LineEdit and change the char_space to any value bigger zero.

Minimal reproduction project:
LineEditCharSpaceBug.zip

@kyleguarco
Copy link

kyleguarco commented Jan 9, 2020

I think this has something to do with ofs_max being incorrectly set when the character spacing changes. Using your minimal reproduction project, some rubber-duck debugging was done to discover this.

The sample text used is "Hello!"
Setting the character spacing back to zero yielding the following print, which I set at the offset check on line 815 of scene/gui/line_edit.cpp (commit 76678b2 on master):

x_ofs passed ofs_max... ofs_max:97 x_ofs:95 char_width:7
x_ofs passed ofs_max... ofs_max:97 x_ofs:95 char_width:7

However, setting the character spacing to anything above one (negatives won't trigger this) will yield a different result (numbers vary depending on the character spacing, 1 in this case):

x_ofs passed ofs_max... ofs_max:168 x_ofs:168 char_width:5
x_ofs passed ofs_max... ofs_max:168 x_ofs:168 char_width:5
x_ofs passed ofs_max... ofs_max:97 x_ofs:95 char_width:7
x_ofs passed ofs_max... ofs_max:97 x_ofs:95 char_width:7

Shouldn't the maximum offset (ofs_max) stay the same? I'm a Junior, so I don't know much about the code-base yet. Will test further in previous versions to see if this bug is present.

Update_1 This bug is present in 3.0.7.devel.custom_build.5bfb10f (commit 5bfb10f on 3.0)
Update_2 This bug is present in 3.0.stable.custom_build.9bd4026 (commit 9bd4026 on 3.0)

@kyleguarco
Copy link

kyleguarco commented Jan 12, 2020

So after constant testing, I've come up with a possible solution. Calculate the x_ofs using the following formula:

x_ofs = MAX(style->get_margin(MARGIN_LEFT), int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_text_width)));
// Above code is already present in source.

// x_ofs -= (text_length * char_space()) - font_size();

This solution is a hacky one, and doesn't account for text longer than the widget. Can I get some help?

edit Nevermind, this doesn't account for font sizes less than 4.

@Paulb23
Copy link
Member

Paulb23 commented Jan 13, 2020

@FlashDaggerX I would take a guess that it's also happening on centre alignment as well, due to cached_width not taking into account char spacing.

@kyleguarco
Copy link

@FlashDaggerX I would take a guess that it's also happening on centre alignment as well, due to cached_width not taking into account char spacing.

Thank you for the suggestion. I'm quite new at this.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 27, 2020

Still valid in 3.2.4 beta3

@MikeSchulze
Copy link

MikeSchulze commented Jan 23, 2022

Hello, I found out that the problem is more related to the scale used.
This problem also occurs with the default font and a scale of 150%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants