Skip to content

Commit ba34829

Browse files
committed
Merge pull request #104444 from Delsin-Yu/fix-disabled-recursive-behavior-not-applied-on-ready
[GUI] Fix reparenting control does not update recursive mode cache properly
2 parents 152c14b + 04608fa commit ba34829

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
@@ -1872,16 +1872,20 @@ void Control::set_mouse_recursive_behavior(RecursiveBehavior p_recursive_mouse_b
18721872
if (data.mouse_recursive_behavior == p_recursive_mouse_behavior) {
18731873
return;
18741874
}
1875+
_set_mouse_recursive_behavior_ignore_cache(p_recursive_mouse_behavior);
1876+
}
1877+
1878+
void Control::_set_mouse_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_mouse_behavior) {
18751879
data.mouse_recursive_behavior = p_recursive_mouse_behavior;
18761880
if (p_recursive_mouse_behavior == RECURSIVE_BEHAVIOR_INHERITED) {
18771881
Control *parent = get_parent_control();
18781882
if (parent) {
1879-
_apply_mouse_behavior_recursively(parent->data.parent_mouse_recursive_behavior, false);
1883+
_propagate_mouse_behavior_recursively(parent->data.parent_mouse_recursive_behavior, false);
18801884
} else {
1881-
_apply_mouse_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
1885+
_propagate_mouse_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
18821886
}
18831887
} else {
1884-
_apply_mouse_behavior_recursively(p_recursive_mouse_behavior, false);
1888+
_propagate_mouse_behavior_recursively(p_recursive_mouse_behavior, false);
18851889
}
18861890

18871891
if (get_viewport()) {
@@ -2056,16 +2060,20 @@ void Control::set_focus_recursive_behavior(RecursiveBehavior p_recursive_focus_b
20562060
if (data.focus_recursive_behavior == p_recursive_focus_behavior) {
20572061
return;
20582062
}
2063+
_set_focus_recursive_behavior_ignore_cache(p_recursive_focus_behavior);
2064+
}
2065+
2066+
void Control::_set_focus_recursive_behavior_ignore_cache(RecursiveBehavior p_recursive_focus_behavior) {
20592067
data.focus_recursive_behavior = p_recursive_focus_behavior;
20602068
if (p_recursive_focus_behavior == RECURSIVE_BEHAVIOR_INHERITED) {
20612069
Control *parent = get_parent_control();
20622070
if (parent) {
2063-
_apply_focus_behavior_recursively(parent->data.parent_focus_recursive_behavior, false);
2071+
_propagate_focus_behavior_recursively(parent->data.parent_focus_recursive_behavior, false);
20642072
} else {
2065-
_apply_focus_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
2073+
_propagate_focus_behavior_recursively(RECURSIVE_BEHAVIOR_ENABLED, false);
20662074
}
20672075
} else {
2068-
_apply_focus_behavior_recursively(p_recursive_focus_behavior, false);
2076+
_propagate_focus_behavior_recursively(p_recursive_focus_behavior, false);
20692077
}
20702078
}
20712079

@@ -2441,7 +2449,7 @@ bool Control::_is_focus_disabled_recursively() const {
24412449
return false;
24422450
}
24432451

2444-
void Control::_apply_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_skip_non_inherited) {
2452+
void Control::_propagate_focus_behavior_recursively(RecursiveBehavior p_focus_recursive_behavior, bool p_skip_non_inherited) {
24452453
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()) {
24462454
release_focus();
24472455
}
@@ -2455,7 +2463,7 @@ void Control::_apply_focus_behavior_recursively(RecursiveBehavior p_focus_recurs
24552463
for (int i = 0; i < get_child_count(); i++) {
24562464
Control *control = Object::cast_to<Control>(get_child(i));
24572465
if (control) {
2458-
control->_apply_focus_behavior_recursively(p_focus_recursive_behavior, true);
2466+
control->_propagate_focus_behavior_recursively(p_focus_recursive_behavior, true);
24592467
}
24602468
}
24612469
}
@@ -2472,7 +2480,7 @@ bool Control::_is_parent_mouse_disabled() const {
24722480
return false;
24732481
}
24742482

2475-
void Control::_apply_mouse_behavior_recursively(RecursiveBehavior p_mouse_recursive_behavior, bool p_skip_non_inherited) {
2483+
void Control::_propagate_mouse_behavior_recursively(RecursiveBehavior p_mouse_recursive_behavior, bool p_skip_non_inherited) {
24762484
if (p_skip_non_inherited && data.mouse_recursive_behavior != RECURSIVE_BEHAVIOR_INHERITED) {
24772485
return;
24782486
}
@@ -2482,7 +2490,7 @@ void Control::_apply_mouse_behavior_recursively(RecursiveBehavior p_mouse_recurs
24822490
for (int i = 0; i < get_child_count(); i++) {
24832491
Control *control = Object::cast_to<Control>(get_child(i));
24842492
if (control) {
2485-
control->_apply_mouse_behavior_recursively(p_mouse_recursive_behavior, true);
2493+
control->_propagate_mouse_behavior_recursively(p_mouse_recursive_behavior, true);
24862494
}
24872495
}
24882496
}
@@ -3442,8 +3450,8 @@ void Control::_notification(int p_notification) {
34423450

34433451
_update_layout_mode();
34443452

3445-
set_focus_recursive_behavior(data.focus_recursive_behavior);
3446-
set_mouse_recursive_behavior(data.mouse_recursive_behavior);
3453+
_set_focus_recursive_behavior_ignore_cache(data.focus_recursive_behavior);
3454+
_set_mouse_recursive_behavior_ignore_cache(data.mouse_recursive_behavior);
34473455
} break;
34483456

34493457
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)