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

Expose finding valid focus neighbors of a Control by side #76027

Merged
merged 1 commit into from
Sep 25, 2023
Merged
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
9 changes: 9 additions & 0 deletions doc/classes/Control.xml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@
Finds the previous (above in the tree) [Control] that can receive the focus.
</description>
</method>
<method name="find_valid_focus_neighbor" qualifiers="const">
<return type="Control" />
<param index="0" name="side" type="int" enum="Side" />
<description>
Finds the next [Control] that can receive the focus on the specified [enum Side].
[b]Note:[/b] This is different from [method get_focus_neighbor], which returns the path of a specified focus neighbor.
</description>
</method>
<method name="force_drag">
<return type="void" />
<param index="0" name="data" type="Variant" />
Expand Down Expand Up @@ -389,6 +397,7 @@
<param index="0" name="side" type="int" enum="Side" />
<description>
Returns the focus neighbor for the specified [enum Side]. A getter method for [member focus_neighbor_bottom], [member focus_neighbor_left], [member focus_neighbor_right] and [member focus_neighbor_top].
[b]Note:[/b] To find the next [Control] on the specific [enum Side], even if a neighbor is not assigned, use [method find_valid_focus_neighbor].
</description>
</method>
<method name="get_global_rect" qualifiers="const">
Expand Down
5 changes: 5 additions & 0 deletions scene/gui/control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2303,6 +2303,10 @@ Control *Control::_get_focus_neighbor(Side p_side, int p_count) {
return result;
}

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) {
if (Object::cast_to<Viewport>(p_at)) {
return; //bye
Expand Down Expand Up @@ -3326,6 +3330,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("release_focus"), &Control::release_focus);
ClassDB::bind_method(D_METHOD("find_prev_valid_focus"), &Control::find_prev_valid_focus);
ClassDB::bind_method(D_METHOD("find_next_valid_focus"), &Control::find_next_valid_focus);
ClassDB::bind_method(D_METHOD("find_valid_focus_neighbor", "side"), &Control::find_valid_focus_neighbor);

ClassDB::bind_method(D_METHOD("set_h_size_flags", "flags"), &Control::set_h_size_flags);
ClassDB::bind_method(D_METHOD("get_h_size_flags"), &Control::get_h_size_flags);
Expand Down
1 change: 1 addition & 0 deletions scene/gui/control.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ class Control : public CanvasItem {

Control *find_next_valid_focus() const;
Control *find_prev_valid_focus() const;
Control *find_valid_focus_neighbor(Side p_size) const;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 🙃

Suggested change
Control *find_valid_focus_neighbor(Side p_size) const;
Control *find_valid_focus_neighbor(Side p_side) const;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh dang 🙃


void set_focus_neighbor(Side p_side, const NodePath &p_neighbor);
NodePath get_focus_neighbor(Side p_side) const;
Expand Down
Loading