Merge pull request #78476 from Sauermann/fix-embedded-safe-area
Embedded Popups store their safe_rect in their embedder
This commit is contained in:
commit
631d51c46c
3 changed files with 27 additions and 4 deletions
|
@ -244,7 +244,12 @@ void PopupMenu::_activate_submenu(int p_over, bool p_by_keyboard) {
|
||||||
Rect2 safe_area = this_rect;
|
Rect2 safe_area = this_rect;
|
||||||
safe_area.position.y += items[p_over]._ofs_cache + scroll_offset + theme_cache.panel_style->get_offset().height - theme_cache.v_separation / 2;
|
safe_area.position.y += items[p_over]._ofs_cache + scroll_offset + theme_cache.panel_style->get_offset().height - theme_cache.v_separation / 2;
|
||||||
safe_area.size.y = items[p_over]._height_cache + theme_cache.v_separation;
|
safe_area.size.y = items[p_over]._height_cache + theme_cache.v_separation;
|
||||||
DisplayServer::get_singleton()->window_set_popup_safe_rect(submenu_popup->get_window_id(), safe_area);
|
Viewport *vp = submenu_popup->get_embedder();
|
||||||
|
if (vp) {
|
||||||
|
vp->subwindow_set_popup_safe_rect(submenu_popup, safe_area);
|
||||||
|
} else {
|
||||||
|
DisplayServer::get_singleton()->window_set_popup_safe_rect(submenu_popup->get_window_id(), safe_area);
|
||||||
|
}
|
||||||
|
|
||||||
// Make the position of the parent popup relative to submenu popup.
|
// Make the position of the parent popup relative to submenu popup.
|
||||||
this_rect.position = this_rect.position - submenu_pum->get_position();
|
this_rect.position = this_rect.position - submenu_pum->get_position();
|
||||||
|
@ -273,7 +278,7 @@ void PopupMenu::_parent_focused() {
|
||||||
window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
|
window_parent = Object::cast_to<Window>(window_parent->get_parent()->get_viewport());
|
||||||
}
|
}
|
||||||
|
|
||||||
Rect2 safe_area = DisplayServer::get_singleton()->window_get_popup_safe_rect(get_window_id());
|
Rect2 safe_area = get_embedder()->subwindow_get_popup_safe_rect(this);
|
||||||
Point2 pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
|
Point2 pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
|
||||||
if (safe_area == Rect2i() || !safe_area.has_point(pos)) {
|
if (safe_area == Rect2i() || !safe_area.has_point(pos)) {
|
||||||
Popup::_parent_focused();
|
Popup::_parent_focused();
|
||||||
|
|
|
@ -464,7 +464,7 @@ void Viewport::_sub_window_remove(Window *p_window) {
|
||||||
RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, p_window->parent ? p_window->parent->viewport : RID());
|
RenderingServer::get_singleton()->viewport_set_parent_viewport(p_window->viewport, p_window->parent ? p_window->parent->viewport : RID());
|
||||||
}
|
}
|
||||||
|
|
||||||
int Viewport::_sub_window_find(Window *p_window) {
|
int Viewport::_sub_window_find(Window *p_window) const {
|
||||||
for (int i = 0; i < gui.sub_windows.size(); i++) {
|
for (int i = 0; i < gui.sub_windows.size(); i++) {
|
||||||
if (gui.sub_windows[i].window == p_window) {
|
if (gui.sub_windows[i].window == p_window) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -3485,6 +3485,21 @@ bool Viewport::is_embedding_subwindows() const {
|
||||||
return gui.embed_subwindows_hint;
|
return gui.embed_subwindows_hint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) {
|
||||||
|
int index = _sub_window_find(p_window);
|
||||||
|
ERR_FAIL_COND(index == -1);
|
||||||
|
|
||||||
|
SubWindow sw = gui.sub_windows[index];
|
||||||
|
sw.parent_safe_rect = p_rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect2i Viewport::subwindow_get_popup_safe_rect(Window *p_window) const {
|
||||||
|
int index = _sub_window_find(p_window);
|
||||||
|
ERR_FAIL_COND_V(index == -1, Rect2i());
|
||||||
|
|
||||||
|
return gui.sub_windows[index].parent_safe_rect;
|
||||||
|
}
|
||||||
|
|
||||||
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
|
void Viewport::pass_mouse_focus_to(Viewport *p_viewport, Control *p_control) {
|
||||||
ERR_MAIN_THREAD_GUARD;
|
ERR_MAIN_THREAD_GUARD;
|
||||||
ERR_FAIL_NULL(p_viewport);
|
ERR_FAIL_NULL(p_viewport);
|
||||||
|
|
|
@ -338,6 +338,7 @@ private:
|
||||||
struct SubWindow {
|
struct SubWindow {
|
||||||
Window *window = nullptr;
|
Window *window = nullptr;
|
||||||
RID canvas_item;
|
RID canvas_item;
|
||||||
|
Rect2i parent_safe_rect;
|
||||||
};
|
};
|
||||||
|
|
||||||
// VRS
|
// VRS
|
||||||
|
@ -461,7 +462,7 @@ private:
|
||||||
void _sub_window_update(Window *p_window);
|
void _sub_window_update(Window *p_window);
|
||||||
void _sub_window_grab_focus(Window *p_window);
|
void _sub_window_grab_focus(Window *p_window);
|
||||||
void _sub_window_remove(Window *p_window);
|
void _sub_window_remove(Window *p_window);
|
||||||
int _sub_window_find(Window *p_window);
|
int _sub_window_find(Window *p_window) const;
|
||||||
bool _sub_windows_forward_input(const Ref<InputEvent> &p_event);
|
bool _sub_windows_forward_input(const Ref<InputEvent> &p_event);
|
||||||
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
|
SubWindowResize _sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point);
|
||||||
|
|
||||||
|
@ -644,6 +645,8 @@ public:
|
||||||
|
|
||||||
void set_embedding_subwindows(bool p_embed);
|
void set_embedding_subwindows(bool p_embed);
|
||||||
bool is_embedding_subwindows() const;
|
bool is_embedding_subwindows() const;
|
||||||
|
void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect);
|
||||||
|
Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;
|
||||||
|
|
||||||
Viewport *get_parent_viewport() const;
|
Viewport *get_parent_viewport() const;
|
||||||
Window *get_base_window() const;
|
Window *get_base_window() const;
|
||||||
|
|
Loading…
Reference in a new issue