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 popup window/menu handling. #58490

Merged
merged 1 commit into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion doc/classes/DisplayServer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,12 @@
<description>
</description>
</method>
<method name="window_get_active_popup" qualifiers="const">
<return type="int" />
<description>
Returns ID of the active popup window, or [constant INVALID_WINDOW_ID] if there is none.
</description>
</method>
<method name="window_get_attached_instance_id" qualifiers="const">
<return type="int" />
<argument index="0" name="window_id" type="int" default="0" />
Expand Down Expand Up @@ -592,6 +598,13 @@
[b]Note:[/b] This method is implemented on Android, Linux, macOS and Windows.
</description>
</method>
<method name="window_get_popup_safe_rect" qualifiers="const">
<return type="Rect2i" />
<argument index="0" name="window" type="int" />
<description>
Returns the bounding box of control, or menu item that was used to open the popup window, in the screen coordinate system.
</description>
</method>
<method name="window_get_position" qualifiers="const">
<return type="Vector2i" />
<argument index="0" name="window_id" type="int" default="0" />
Expand Down Expand Up @@ -749,6 +762,14 @@
[b]Note:[/b] This method is implemented on Linux, macOS and Windows.
</description>
</method>
<method name="window_set_popup_safe_rect">
<return type="void" />
<argument index="0" name="window" type="int" />
<argument index="1" name="rect" type="Rect2i" />
<description>
Sets the bounding box of control, or menu item that was used to open the popup window, in the screen coordinate system. Clicking this area will not auto-close this popup.
</description>
</method>
<method name="window_set_position">
<return type="void" />
<argument index="0" name="position" type="Vector2i" />
Expand Down Expand Up @@ -930,16 +951,24 @@
Regardless of the platform, enabling fullscreen will change the window size to match the monitor's size. Therefore, make sure your project supports [url=$DOCS_URL/tutorials/rendering/multiple_resolutions.html]multiple resolutions[/url] when enabling fullscreen mode.
</constant>
<constant name="WINDOW_FLAG_RESIZE_DISABLED" value="0" enum="WindowFlags">
Window can't be resizing by dragging its resize grip. It's still possible to resize the window using [method window_set_size]. This flag is ignored for full screen windows.
</constant>
<constant name="WINDOW_FLAG_BORDERLESS" value="1" enum="WindowFlags">
Window do not have native title bar and other decorations. This flag is ignored for full-screen windows.
</constant>
<constant name="WINDOW_FLAG_ALWAYS_ON_TOP" value="2" enum="WindowFlags">
Window is floating above other regular windows. This flag is ignored for full-screen windows.
</constant>
<constant name="WINDOW_FLAG_TRANSPARENT" value="3" enum="WindowFlags">
Window is will be destroyed with its transient parent and displayed on top of non-exclusive full-screen parent window. Transient windows can't enter full-screen mode.
</constant>
<constant name="WINDOW_FLAG_NO_FOCUS" value="4" enum="WindowFlags">
Window can't be focused. No-focus window will ignore all input, except mouse clicks.
</constant>
<constant name="WINDOW_FLAG_POPUP" value="5" enum="WindowFlags">
Window is part of menu or [OptionButton] dropdown. This flag can't be changed when window is visible. An active popup window will exclusivly receive all input, without stealing focus from its parent. Popup windows are automatically closed when uses click outside it, or when an application is switched. Popup window must have [constant WINDOW_FLAG_TRANSPARENT] set.
</constant>
<constant name="WINDOW_FLAG_MAX" value="5" enum="WindowFlags">
<constant name="WINDOW_FLAG_MAX" value="6" enum="WindowFlags">
</constant>
<constant name="WINDOW_EVENT_MOUSE_ENTER" value="0" enum="WindowEvent">
</constant>
Expand Down
6 changes: 2 additions & 4 deletions doc/classes/Popup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
Popup is a base window container for popup-like subwindows.
</brief_description>
<description>
Popup is a base window container for popup-like subwindows. It's a modal by default (see [member close_on_parent_focus]) and has helpers for custom popup behavior.
Popup is a base window container for popup-like subwindows. It's a modal by default (see [member popup_window]) and has helpers for custom popup behavior.
</description>
<tutorials>
</tutorials>
<members>
<member name="borderless" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
<member name="close_on_parent_focus" type="bool" setter="set_close_on_parent_focus" getter="get_close_on_parent_focus" default="true">
If true, the [Popup] will close when its parent [Window] is focused.
</member>
<member name="popup_window" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
<member name="transient" type="bool" setter="set_transient" getter="is_transient" overrides="Window" default="true" />
<member name="unresizable" type="bool" setter="set_flag" getter="get_flag" overrides="Window" default="true" />
<member name="visible" type="bool" setter="set_visible" getter="is_visible" overrides="Window" default="false" />
Expand Down
6 changes: 5 additions & 1 deletion doc/classes/Window.xml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@
Set's the window's current mode.
[b]Note:[/b] Fullscreen mode is not exclusive fullscreen on Windows and Linux.
</member>
<member name="popup_window" type="bool" setter="set_flag" getter="get_flag" default="false">
</member>
<member name="position" type="Vector2i" setter="set_position" getter="get_position" default="Vector2i(0, 0)">
The window's position in pixels.
</member>
Expand Down Expand Up @@ -416,7 +418,9 @@
</constant>
<constant name="FLAG_NO_FOCUS" value="4" enum="Flags">
</constant>
<constant name="FLAG_MAX" value="5" enum="Flags">
<constant name="FLAG_POPUP" value="5" enum="Flags">
</constant>
<constant name="FLAG_MAX" value="6" enum="Flags">
</constant>
<constant name="CONTENT_SCALE_MODE_DISABLED" value="0" enum="ContentScaleMode">
</constant>
Expand Down
2 changes: 1 addition & 1 deletion editor/plugins/tiles/tile_map_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4024,7 +4024,7 @@ TileMapEditor::TileMapEditor() {
// Layer selector.
layers_selection_popup = memnew(PopupMenu);
layers_selection_popup->connect("id_pressed", callable_mp(this, &TileMapEditor::_layers_selection_id_pressed));
layers_selection_popup->set_close_on_parent_focus(false);
layers_selection_popup->set_flag(Window::FLAG_POPUP, false);

layers_selection_button = memnew(Button);
layers_selection_button->set_toggle_mode(true);
Expand Down
Loading