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

Improve height limit of PopupMenu of OptionButton/MenuButton #46583

Conversation

floppyhammer
Copy link
Contributor

@floppyhammer floppyhammer commented Mar 2, 2021

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:
popup_menu_3
popup_menu_4

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.
popup_menu_5

@floppyhammer floppyhammer requested a review from a team as a code owner March 2, 2021 04:32
@EricEzaM EricEzaM self-requested a review March 2, 2021 05:45
@Riteo
Copy link
Contributor

Riteo commented Mar 2, 2021

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.

I think you're talking about #40227.

@floppyhammer
Copy link
Contributor Author

@Riteo Yeah, you're right.

@Riteo
Copy link
Contributor

Riteo commented Mar 2, 2021

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 height_limit is computed in the first place, although I can't investigate right now.

Comment on lines 110 to 117
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;
}

Copy link
Contributor

@EricEzaM EricEzaM Mar 2, 2021

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree.

@@ -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);
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.
popup_menu_6

@floppyhammer
Copy link
Contributor Author

@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.

@floppyhammer floppyhammer changed the title Add an extra height limit to PopupMenu of OptionButton and MenuButton Improve height limit of PopupMenu of OptionButton/MenuButton Mar 2, 2021
@floppyhammer floppyhammer force-pushed the improve-popup-menu-height-limit branch 2 times, most recently from 5e82706 to c4dc297 Compare March 2, 2021 09:16
@floppyhammer
Copy link
Contributor Author

I just realized adding one line of code height_limit -= get_position().y; is enough. Absolutely no need for a new property. Though the scenario mentioned by @EricEzaM in which OptionButton/MenuButton goes down really low on the screen still causes problems. That needs more consideration.

@Riteo
Copy link
Contributor

Riteo commented Mar 2, 2021

@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.

@Calinou Calinou added this to the 4.0 milestone Mar 2, 2021
@floppyhammer floppyhammer force-pushed the improve-popup-menu-height-limit branch from c4dc297 to 1f4ed8b Compare March 7, 2021 08:07
@floppyhammer
Copy link
Contributor Author

floppyhammer commented Mar 7, 2021

popup_menu_7

@Riteo
Copy link
Contributor

Riteo commented Mar 7, 2021

@floppyhammer you requested a review but the latest commit is 6 days old. I think you forgot to push

@floppyhammer
Copy link
Contributor Author

@Riteo It says I pushed yesterday.

@Riteo
Copy link
Contributor

Riteo commented Mar 9, 2021

@floppyhammer oh now it does. Since I looked at this PR from octodroid it probably messed up something on my side, sorry 😅

scene/gui/popup_menu.cpp Outdated Show resolved Hide resolved
@KoBeWi
Copy link
Member

KoBeWi commented Mar 12, 2021

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.

@floppyhammer floppyhammer force-pushed the improve-popup-menu-height-limit branch 2 times, most recently from 1c0643c to 21cfa80 Compare March 12, 2021 02:02
@floppyhammer
Copy link
Contributor Author

@KoBeWi I agree. Should we do it in this PR or leave it to another one?

@KoBeWi
Copy link
Member

KoBeWi commented Mar 12, 2021

Refactoring could be done in another PR.

@floppyhammer floppyhammer force-pushed the improve-popup-menu-height-limit branch from 21cfa80 to 139ed4d Compare July 17, 2021 04:43
@floppyhammer
Copy link
Contributor Author

godot/scene/main/window.cpp

Lines 1095 to 1108 in c334989

Rect2i Window::get_usable_parent_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
Rect2i parent;
if (is_embedded()) {
parent = _get_embedder()->get_visible_rect();
} else {
const Window *w = is_visible() ? this : get_parent_visible_window();
//find a parent that can contain us
ERR_FAIL_COND_V(!w, Rect2());
parent = DisplayServer::get_singleton()->screen_get_usable_rect(DisplayServer::get_singleton()->window_get_current_screen(w->get_window_id()));
}
return parent;
}

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?

@floppyhammer
Copy link
Contributor Author

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.

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.

PopupMenu has incorrect height limit
6 participants