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

Allow multiple SubViewports within a Window to have a focused Control #79480

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 17 additions & 10 deletions scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2555,22 +2555,31 @@ Window *Viewport::get_base_window() const {
return w;
}

void Viewport::_gui_remove_focus_for_window(Node *p_window) {
if (get_base_window() == p_window) {
gui_release_focus();
}
}

bool Viewport::_gui_control_has_focus(const Control *p_control) {
return gui.key_focus == p_control;
}

void Viewport::_gui_control_grab_focus(Control *p_control) {
if (gui.key_focus && gui.key_focus == p_control) {
// Release previous focus.
if (gui.key_focus && gui.key_focus != p_control) {
gui_release_focus();
}

// Ensure chain of SubViewportContainer focus in parent Viewport. Needs to happen, even if control has focus in this Viewport.
Viewport *vp = this;
if (Object::cast_to<SubViewport>(vp)) {
SubViewportContainer *p = Object::cast_to<SubViewportContainer>(get_parent());
if (p) {
p->grab_focus();
}
}

if (gui.key_focus == p_control) {
// No need for change.
return;
}
get_tree()->call_group("_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window());

// Perform necessary adjustments for focuschange.
if (p_control->is_inside_tree() && p_control->get_viewport() == this) {
gui.key_focus = p_control;
emit_signal(SNAME("gui_focus_changed"), p_control);
Expand Down Expand Up @@ -4625,8 +4634,6 @@ void Viewport::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);

ClassDB::bind_method(D_METHOD("_gui_remove_focus_for_window"), &Viewport::_gui_remove_focus_for_window);

ClassDB::bind_method(D_METHOD("set_positional_shadow_atlas_size", "size"), &Viewport::set_positional_shadow_atlas_size);
ClassDB::bind_method(D_METHOD("get_positional_shadow_atlas_size"), &Viewport::get_positional_shadow_atlas_size);

Expand Down
1 change: 0 additions & 1 deletion scene/main/viewport.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ class Viewport : public Node {
void _gui_set_drag_preview(Control *p_base, Control *p_control);
Control *_gui_get_drag_preview();

void _gui_remove_focus_for_window(Node *p_window);
void _gui_unfocus_control(Control *p_control);
bool _gui_control_has_focus(const Control *p_control);
void _gui_control_grab_focus(Control *p_control);
Expand Down
Loading