Skip to content

Commit

Permalink
Fix getting wrong focus neighbor when the control is in `ScrollContai…
Browse files Browse the repository at this point in the history
…ner`

Exclude controls inside a `ScrollContainer` that are outside the visible area of ​​
the `ScrollContainer` when looking for focus neighbors.
  • Loading branch information
Rindbee committed Dec 31, 2024
1 parent 2582793 commit da54ca9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
19 changes: 15 additions & 4 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2327,7 +2327,9 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
return nullptr;
}

_window_find_focus_neighbor(vdir, base, points, maxd, dist, &result);
Rect2 clamp = Rect2(Point2(-1e7, -1e7), Size2(2e7, 2e7));

_window_find_focus_neighbor(vdir, base, points, clamp, maxd, dist, &result);

return result;
}
Expand All @@ -2336,14 +2338,14 @@ Control *Control::find_valid_focus_neighbor(Side p_side) const {
return const_cast<Control *>(this)->_get_focus_neighbor(p_side);
}

void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest) {
void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist, Control **r_closest) {
if (Object::cast_to<Viewport>(p_at)) {
return; //bye
}

Control *c = Object::cast_to<Control>(p_at);

if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree()) {
if (c && c != this && c->get_focus_mode() == FOCUS_ALL && c->is_visible_in_tree() && p_clamp.encloses(c->get_global_rect())) {
Point2 points[4];

Transform2D xform = c->get_global_transform();
Expand Down Expand Up @@ -2406,13 +2408,22 @@ void Control::_window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, cons
}
}

ScrollContainer *sc = Object::cast_to<ScrollContainer>(c);

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🍏 iOS / Template (target=template_release)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm32 (target=template_release, arch=arm32)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🍎 macOS / Template (target=template_release, tests=yes)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🤖 Android / Template arm64 (target=template_release, arch=arm64)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/ threads (target=template_release, threads=yes)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

unknown type name 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🌐 Web / Template w/o threads (target=template_release, threads=no)

use of undeclared identifier 'ScrollContainer'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

'ScrollContainer' was not declared in this scope

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

'sc' was not declared in this scope; did you mean 'c'?

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Template w/ Mono (target=template_release, tests=yes)

no matching function for call to 'Control::cast_to<ScrollContainer>(Control*&)'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

'ScrollContainer' was not declared in this scope

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

'sc' was not declared in this scope; did you mean 'c'?

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🐧 Linux / Minimal template (target=template_release, tests=yes, everything disabled)

no matching function for call to 'Control::cast_to<ScrollContainer>(Control*&)'

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'ScrollContainer': undeclared identifier

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'sc': undeclared identifier

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'ScrollContainer': undeclared identifier

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'Object::cast_to': no matching overloaded function found

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

'ScrollContainer' was not declared in this scope

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

'sc' was not declared in this scope; did you mean 'c'?

Check failure on line 2411 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template w/ GCC (target=template_release, tests=yes, use_mingw=yes)

no matching function for call to 'Control::cast_to<ScrollContainer>(Control*&)'
Rect2 intersection = p_clamp;
if (sc && !sc->is_following_focus()) {

Check failure on line 2413 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'sc': undeclared identifier

Check failure on line 2413 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'sc': undeclared identifier
intersection = p_clamp.intersection(sc->get_global_rect());

Check failure on line 2414 in scene/gui/control.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release, tests=yes)

'sc': undeclared identifier
if (!intersection.has_area()) {
return;
}
}

for (int i = 0; i < p_at->get_child_count(); i++) {
Node *child = p_at->get_child(i);
Control *childc = Object::cast_to<Control>(child);
if (childc && childc->data.RI) {
continue; //subwindow, ignore
}
_window_find_focus_neighbor(p_dir, p_at->get_child(i), p_points, p_min, r_closest_dist, r_closest);
_window_find_focus_neighbor(p_dir, p_at->get_child(i), p_points, intersection, p_min, r_closest_dist, r_closest);
}
}

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class Control : public CanvasItem {

// Focus.

void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest);
void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, Rect2 &p_clamp, real_t p_min, real_t &r_closest_dist, Control **r_closest);
Control *_get_focus_neighbor(Side p_side, int p_count = 0);

// Theming.
Expand Down

0 comments on commit da54ca9

Please sign in to comment.