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

OptionButton expand_icon breaks the layout #59202

Open
KoBeWi opened this issue Mar 16, 2022 · 8 comments · May be fixed by #59340
Open

OptionButton expand_icon breaks the layout #59202

KoBeWi opened this issue Mar 16, 2022 · 8 comments · May be fixed by #59340

Comments

@KoBeWi
Copy link
Member

@KoBeWi KoBeWi commented Mar 16, 2022

Godot version

4.0 9d732aa / 3.x

System information

Windows 10 x64

Issue description

image
Text overlaps arrow

Steps to reproduce

  1. Add OptionButton
  2. Add some icon and text
  3. Enable expand_icon property
  4. Shrink the button to minimal size

Minimal reproduction project

No response

@nickhachmer
Copy link

@nickhachmer nickhachmer commented Mar 17, 2022

Hey! If possible I'd like to try and tackle this bug. This will be my first time trying to contribute to an open source, so I'm, excited to try it out.

@Calinou
Copy link
Member

@Calinou Calinou commented Mar 18, 2022

Hey! If possible I'd like to try and tackle this bug. This will be my first time trying to contribute to an open source, so I'm, excited to try it out.

Sure, go ahead 🙂

@rtarun9
Copy link

@rtarun9 rtarun9 commented Mar 18, 2022

Hey! I have faced same bug earlier however the solution might be a bit tricky since the actual size of the OptionButton remains the same whether the ExpandIcon option is selected or not. What would be a good solution to this bug ? The options I can think of are both un optimal -> Limiting size of icon (or) changing size of OptionButton when the ExpandIcon option is selected.

@KoBeWi
Copy link
Member Author

@KoBeWi KoBeWi commented Mar 18, 2022

changing size of OptionButton when the ExpandIcon option is selected.

This. Minimum size should properly use the final icon size. Right now it's probably ignored, like with most expand properties. The icon's width seems to depend on the height, so it should be possible to calculate it.

@AtlaStar
Copy link

@AtlaStar AtlaStar commented Mar 18, 2022

This. Minimum size should properly use the final icon size. Right now it's probably ignored, like with most expand properties. The icon's width seems to depend on the height, so it should be possible to calculate it.

The oddity here is that the code is functionally identical between the master and 3.x branch outside of some function renames or refactors for the get_minimum_size() methods in both OptionButton and Button, yet the master branch has no issues. It suggests a possibly deeper issue, but I am not yet familiar enough with the internals to even know quite where to look.

My trail currently has ended at trying to look at how the margins themselves get set, and looking into the diff of texture_region_editor_plugin.cpp across branches, which appear to be functionally the same outside of some updated semantics in for loops and usage of SNAME. Everything in OptionButton is identical in how it updates margins outside of the master branch having some localization stuff for right to left layouts, and everything appears to be logically identical in Button as well other than master using a more verbose means of getting the font dimensions for the minimum size.

So I believe that any submission that only changes the way the minimum size is calculated is marked with a big TODO or FIXME because it is probable that such a fix may just mask a deeper bug that could pop up later down the development process.

@KoBeWi
Copy link
Member Author

@KoBeWi KoBeWi commented Mar 19, 2022

yet the master branch has no issues.

The issue does exist in master. As I said in my previous comment, the problematic part is this code:

if (!expand_icon) {
Ref<Texture2D> _icon;
if (icon.is_null() && has_theme_icon(SNAME("icon"))) {
_icon = Control::get_theme_icon(SNAME("icon"));
} else {
_icon = icon;
}
if (!_icon.is_null()) {
minsize.height = MAX(minsize.height, _icon->get_height());
if (icon_alignment != HORIZONTAL_ALIGNMENT_CENTER) {
minsize.width += _icon->get_width();
if (!xl_text.is_empty()) {
minsize.width += get_theme_constant(SNAME("hseparation"));
}
} else {
minsize.width = MAX(minsize.width, _icon->get_width());
}
}
}

If expand_icon is true, this whole block is ignored, which is incorrect.

@AtlaStar
Copy link

@AtlaStar AtlaStar commented Mar 19, 2022

yet the master branch has no issues.

The issue does exist in master. As I said in my previous comment, the problematic part is this code:

Hmm, I must be mistaken in my memory then, because I was sure that I tested a build of both master and 3.x and only saw the behavior on the 3.x branch. Not just that but neither 3.4 or 3.3 branches do an explicit calculation of the icon size when expand_icon is true either. I haven't tested whether the issue exists in those branches or not, but if it doesn't that would be odd no?

That is mostly why I believe that there is something deeper going on and made the comments that I did, as if it works as expected on those other branches but not 3.x or master, then something else has to be going on suggesting a deeper issue.

EDIT: yeah, so I don't know how I convinced myself I tested both builds originally, but I definitely did not. Going to test the older branches too to see if those versions had this issue as well as it seems highly likely that they also exhibit the same issue

@Rindbee
Copy link
Contributor

@Rindbee Rindbee commented Mar 21, 2022

Hello everyone, I think it may be caused by the following three reasons:

  1. In the function Button::get_minimum_size, the minimum size is calculated without actually considering the icon size, as the icon in Button can be hidden when the button size is smallest;
  2. The size of the icon (not the icon_arrow) to draw, that seems to be computed in the function Button::_notification. And It does consider the new properties in OptionButton;
  3. In the function OptionButton::get_minimum_size, it takes the arrow_icon into the minimum size computing (theme_override_constants/arrow_margin should also be considered). It will make the width of the minimum size be larger.

So, when enable the property expand_icon in OptionButton, the icon will expand. The drawing actual width of icon becomes wider than it should be.

Rindbee added a commit to Rindbee/godot that referenced this issue Mar 21, 2022
Rindbee added a commit to Rindbee/godot that referenced this issue Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants