-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Improve height limit of PopupMenu of OptionButton/MenuButton #46583
Improve height limit of PopupMenu of OptionButton/MenuButton #46583
Conversation
I think you're talking about #40227. |
@Riteo Yeah, you're right. |
Also, I think that there's no need for an extra property. After all, you have to compute its value still one way or the other. IMO we should change the way |
scene/gui/popup_menu.cpp
Outdated
void PopupMenu::set_extra_height_limit(int p_limit) { | ||
extra_height_limit = p_limit; | ||
} | ||
|
||
int PopupMenu::get_extra_height_limit() const { | ||
return extra_height_limit; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the name "set extra height limit". For someone coming to this code in 1 year's time, they would need to look into where the extra_height_limit
property was used to understand what it actually did.
"Height Limit" implies that if it was set to say, 50, the maximum height of the popup would be 50. But that is not what this does. This extra_height_limit
is subtracted from the actual height limit (usable parent rect). Essentially what it does is set a maximum Y position (highest allowable point) for the popup menu.
As a result, perhaps changing the name to something like set_highest_allowable_point(int p_value)
would represent it better. I still don't think that set_highest_allowable_point
is necessarily the best name, but I just want to get the idea of a name change out there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree.
scene/gui/menu_button.cpp
Outdated
@@ -60,7 +60,7 @@ void MenuButton::pressed() { | |||
gp.y += get_size().y; | |||
|
|||
popup->set_position(gp); | |||
|
|||
popup->set_extra_height_limit(popup->get_position().y); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you put the MenuButton down really low on the screen, wouldn't it essentially make the popup miniscule and unusable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EricEzaM We can make the menu go above the button in that case, just like what the auto-completion panel does in the script editor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EricEzaM Or we leave height_limit
as it is, and just make PopupMenu not respond to the mouse release too fast after the mouse press just activates it as it does in 3.2
.
@Riteo I also thought of changing how height_limit is calculated. However, that happens inside PopupMenu, so accessing the position of its parent (OptionButton or MenuButton) cannot be done in a clean way. But you are right, adding an extra property for this is not very desirable. I will think of a more reasonable way. |
5e82706
to
c4dc297
Compare
I just realized adding one line of code |
@floppyhammer yeah I agree. It was discussed before (see #45201 (comment)) and I think that the popup should just try to fit the window the best it can before having to resize. |
c4dc297
to
1f4ed8b
Compare
@floppyhammer you requested a review but the latest commit is 6 days old. I think you forgot to push |
@Riteo It says I pushed yesterday. |
@floppyhammer oh now it does. Since I looked at this PR from octodroid it probably messed up something on my side, sorry 😅 |
MenuButton pressed and OptionButton pressed have lots of popup-related duplicate code that could probably be moved to Popup Menu class as a new method. |
1c0643c
to
21cfa80
Compare
@KoBeWi I agree. Should we do it in this PR or leave it to another one? |
Refactoring could be done in another PR. |
21cfa80
to
139ed4d
Compare
Lines 1095 to 1108 in c334989
Is it designed to return the screen rect when calling Window::get_usable_parent_rect()? Isn't it more intuitive to return the parent window rect by the method's name? |
This PR has been devised to fix the menu item selection issue #46545. But since it has already been fixed, this PR seems quite unnecessary. Besides, it's flawed from the beginning anyway. |
Fixes #46545. The issue has been there for a while (since I started using Godot 4.0 actually). I solved the issue by adding an additional property
extra_height_limit
to PopupMenu (not exposed to users). I don't know if this is acceptable or if there are more appropriate solutions, so any suggestions are welcome.Result:
Along the way I made this fix, I found another bug related to PopupMenu in Project Settings and Editor Settings when Single Window Mode is enabled. But that isn't caused by this PR.