Skip to content

Commit 04608fa

Browse files
committed
[GUI] Fix an issue where setting a control's recursive mode to disabled does not work on ready.
1 parent 2303ce8 commit 04608fa

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

scene/gui/control.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,16 +1880,20 @@ void Control::set_mouse_recursive_behavior(RecursiveBehavior p_recursive_mouse_b
18801880
if (data.mouse_recursive_behavior == p_recursive_mouse_behavior) {
18811881
return;
18821882
}
1883+
_set_mouse_recursive_behavior_ignore_cache(p_recursive_mouse_behavior);
1884+
}
1885+
1886+
void Control::_set_mouse_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_mouse_behavior) {
18831887
data.mouse_recursive_behavior = p_recursive_mouse_behavior;
18841888
if (p_recursive_mouse_behavior == RECURSIVE_BEHAVIOR_INHERITED) {
18851889
Control *parent = get_parent_control();
18861890
if (parent) {
1887-
_apply_mouse_behavior_recursively(parent->data.parent_mouse_recursive_behavior, false);
1891+
_propagate_mouse_behavior_recursively(parent->data.parent_mouse_recursive_behavior, false);
18881892
} else {
1889-
_apply_mouse_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
1893+
_propagate_mouse_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
18901894
}
18911895
} else {
1892-
_apply_mouse_behavior_recursively(p_recursive_mouse_behavior, false);
1896+
_propagate_mouse_behavior_recursively(p_recursive_mouse_behavior, false);
18931897
}
18941898

18951899
if (get_viewport()) {
@@ -2064,16 +2068,20 @@ void Control::set_focus_recursive_behavior(RecursiveBehavior p_recursive_focus_b
20642068
if (data.focus_recursive_behavior == p_recursive_focus_behavior) {
20652069
return;
20662070
}
2071+
_set_focus_recursive_behavior_ignore_cache(p_recursive_focus_behavior);
2072+
}
2073+
2074+
void Control::_set_focus_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_focus_behavior) {
20672075
data.focus_recursive_behavior = p_recursive_focus_behavior;
20682076
if (p_recursive_focus_behavior == RECURSIVE_BEHAVIOR_INHERITED) {
20692077
Control *parent = get_parent_control();
20702078
if (parent) {
2071-
_apply_focus_behavior_recursively(parent->data.parent_focus_recursive_behavior, false);
2079+
_propagate_focus_behavior_recursively(parent->data.parent_focus_recursive_behavior, false);
20722080
} else {
2073-
_apply_focus_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
2081+
_propagate_focus_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
20742082
}
20752083
} else {
2076-
_apply_focus_behavior_recursively(p_recursive_focus_behavior, false);
2084+
_propagate_focus_behavior_recursively(p_recursive_focus_behavior, false);
20772085
}
20782086
}
20792087

@@ -2449,7 +2457,7 @@ bool Control::_is_focus_disabled_recursively() const {
24492457
return false;
24502458
}
24512459

2452-
void Control::_apply_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_skip_non_inherited) {
2460+
void Control::_propagate_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_skip_non_inherited) {
24532461
if (is_inside_tree() && (data.focus_recursive_behavior == RECURSIVE_BEHAVIOR_DISABLED || (data.focus_recursive_behavior == RECURSIVE_BEHAVIOR_INHERITED && p_focus_recursive_behavior == RECURSIVE_BEHAVIOR_DISABLED)) && has_focus()) {
24542462
release_focus();
24552463
}
@@ -2463,7 +2471,7 @@ void Control::_apply_focus_behavior_recursively(RecursiveBehavior p_focus_recurs
24632471
for (int i = 0; i < get_child_count(); i++) {
24642472
Control *control = Object::cast_to<Control>(get_child(i));
24652473
if (control) {
2466-
control->_apply_focus_behavior_recursively(p_focus_recursive_behavior, true);
2474+
control->_propagate_focus_behavior_recursively(p_focus_recursive_behavior, true);
24672475
}
24682476
}
24692477
}
@@ -2480,7 +2488,7 @@ bool Control::_is_parent_mouse_disabled() const {
24802488
return false;
24812489
}
24822490

2483-
void Control::_apply_mouse_behavior_recursively(RecursiveBehavior p_mouse_recursive_behavior, bool p_skip_non_inherited) {
2491+
void Control::_propagate_mouse_behavior_recursively(RecursiveBehavior p_mouse_recursive_behavior, bool p_skip_non_inherited) {
24842492
if (p_skip_non_inherited && data.mouse_recursive_behavior != RECURSIVE_BEHAVIOR_INHERITED) {
24852493
return;
24862494
}
@@ -2490,7 +2498,7 @@ void Control::_apply_mouse_behavior_recursively(RecursiveBehavior p_mouse_recurs
24902498
for (int i = 0; i < get_child_count(); i++) {
24912499
Control *control = Object::cast_to<Control>(get_child(i));
24922500
if (control) {
2493-
control->_apply_mouse_behavior_recursively(p_mouse_recursive_behavior, true);
2501+
control->_propagate_mouse_behavior_recursively(p_mouse_recursive_behavior, true);
24942502
}
24952503
}
24962504
}
@@ -3450,8 +3458,8 @@ void Control::_notification(int p_notification) {
34503458

34513459
_update_layout_mode();
34523460

3453-
set_focus_recursive_behavior(data.focus_recursive_behavior);
3454-
set_mouse_recursive_behavior(data.mouse_recursive_behavior);
3461+
_set_focus_recursive_behavior_ignore_cache(data.focus_recursive_behavior);
3462+
_set_mouse_recursive_behavior_ignore_cache(data.mouse_recursive_behavior);
34553463
} break;
34563464

34573465
case NOTIFICATION_UNPARENTED: {

scene/gui/control.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,10 @@ class Control : public CanvasItem {
330330
void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Rect2 &p_rect, const Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist_squared, Control **r_closest);
331331
Control *_get_focus_neighbor(Side p_side, int p_count = 0);
332332
bool _is_focus_disabled_recursively() const;
333-
void _apply_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_force);
334-
void _apply_mouse_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_force);
333+
void _propagate_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_force);
334+
void _propagate_mouse_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_force);
335+
void _set_mouse_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_mouse_behavior);
336+
void _set_focus_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_mouse_behavior);
335337

336338
// Theming.
337339

0 commit comments

Comments
 (0)