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

Adjust OptionButton icon sizes in PopupMenu automatically #71826

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rsubtil
Copy link
Contributor

@rsubtil rsubtil commented Jan 21, 2023

Added a max_item_height property to PopupMenus which limits the height of each item. In practice this is used to shrink icons to an acceptable size. OptionButton sets this value automatically to it's current height. (edit: implemented by #75472)

OptionButton nodes now automatically adjust icon sizes from the internal PopupMenu to match the existing icon size when overrided.

Peek 2023-01-21 22-38

Closes #58283 and godotengine/godot-proposals#6139

@KoBeWi
Copy link
Member

KoBeWi commented Apr 29, 2023

Needs rebase. I have a bug with stretched icon, but maybe I messed something when trying to fix conflicts
image

doc/classes/PopupMenu.xml Outdated Show resolved Hide resolved
scene/gui/popup_menu.cpp Outdated Show resolved Hide resolved
@rsubtil
Copy link
Contributor Author

rsubtil commented May 6, 2023

#75472 added a icon_max_width field, and since this also adjusts the height automatically, I don't think this PR is necessary anymore. The only change in behavior is the OptionButton automatically adjust the width of PopupMenu icons, so I'll change it to only add that.

This needs to trigger some update if the value is different than the current one.

BTW, I wasn't sure how to do this, was it just calling control->queue_redraw()?

@rsubtil rsubtil force-pushed the popupmenu_max_item_height branch from c65c4b3 to 3a7435f Compare May 6, 2023 16:57
@rsubtil rsubtil changed the title Added maximum item height for PopupMenu Adjust OptionButton icon sizes in PopupMenu automatically May 6, 2023
@rsubtil rsubtil force-pushed the popupmenu_max_item_height branch from 3a7435f to 60a4f7e Compare May 6, 2023 17:56
@KoBeWi
Copy link
Member

KoBeWi commented May 6, 2023

BTW, I wasn't sure how to do this, was it just calling control->queue_redraw()?

Not only. It probably needed something like what's done in set_item_icon_max_width().

Comment on lines 507 to 509
if (get_icon().is_valid() && is_expand_icon()) {
Size2 _size = get_size() - theme_cache.normal->get_offset() * 2;
float icon_width = get_icon()->get_width() * _size.height / get_icon()->get_height();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this logic is entirely correct. Button's own icon max size, for example, is applied regardless of the expand mode. This code seems to replicate a small part of the size resolution logic from button.cpp's NOTIFICATION_DRAW handler.

I think we should instead extract that part of the Button's code into a dedicated method and use that method here as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I extracted the way the icons were resized when rendered on the NOTIFICATION_DRAW portion. I've implemented your suggestion by moving that math into functions (get_icon_width_with_aspect_ratio(...)) and refactored to use these new methods.

Sorry for the delay, I've been busy the last month, I only had some free time to look at this again now.

@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 14, 2023
@AThousandShips AThousandShips modified the milestones: 4.2, 4.3 Oct 27, 2023
@akien-mga akien-mga modified the milestones: 4.3, 4.x Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OptionButton expand_icon does not affect popup
5 participants