-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Focusable Tabs and TabContainer, tabs can be changed using keyboard and gamepad #49928
Conversation
…t and ui_right actions
…to focusable_tabs
…to focusable_tabs
Rollover can be turned on and off
Updated PR:
|
I think we could leave it as-is, especially since people using custom themes will have to provide a StyleBox for this new element once this PR is merged. What do you think the custom graphic should look like? How do other applications handle this? |
By default, users cannot switch tabs on TabContainers without using a mouse. This commit adds the ability to switch tabs using either a keyboard or a controller, using the focus system. This commit is based on the Godot PR: godotengine#49928
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks for taking the time to write this PR. I'm sorry it's taken a while for the community to review.
I've provided some feedback but none of them are major blockers. Most are just my opinion, but things are working as expected for the most part. I think this PR is a good idea so I wanted to provide some feedback. I hope that by reviewing this PR we can speed up getting members of the project to consider it for the next 4.X release (4.2 since 4.1 is in feature freeze.)
If you're around and are still willing to deal with rebasing the code, let me know. Otherwise, I could help you with the rebase process if necessary.
Finally, once all of the changes are made, make sure to condense your commits down to 1 commit message following our commit message standard if possible.
Thanks!
void set_rollover(bool p_enabled); | ||
bool get_rollover() const; | ||
TabContainer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind, please try to cluster likewise functions together with a space between them. E.G:
void set_rollover(bool p_enabled); | |
bool get_rollover() const; | |
TabContainer(); | |
void set_rollover(bool p_enabled); | |
bool get_rollover() const; | |
TabContainer(); |
if (p_event->is_action_pressed("ui_right")) { | ||
int next_tab = get_current_tab() + 1; | ||
bool valid = true; | ||
while (valid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this needs to be a while
loop?
It seems to me like a for loop which acts as an offset from an origin is more appropriate and easier to read.
int origin_tab = get_current_tab();
for (int offset = 0; offset < get_tab_count(); offset++) {
int next_tab = (origin_tab + offset) % get_tab_count();
bool valid = get_tab_disabled(next_tab);
if (!rollover) {
valid &= next_tab > origin_tab;
if (!valid) {
break;
}
}
if (valid) {
set_current_tab(next_tab);
accept_event();
break;
}
}
This might not cover all use cases or compile completely as I'm writing it mostly pseudo code, but something along those lines seems a bit easier to read to me. It also doesn't require checking for self as it will naturally wrap around with the use of modulo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, I just found while loop being easiest way to implement searching for a valid tab and didn't thought of for loop.
} else if (p_event->is_action_pressed("ui_left")) { | ||
int prev_tab = get_current_tab() - 1; | ||
bool valid = true; | ||
while (valid) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the last comment but inverse direction. Modulo won't work here, so you'll have to appropriately index wrap as you see fit.
Hi, sure I can look intro rebasing/refactoring this weekend if I have time. |
Hey, so I started working on refactoring as there was actually a lot of changes in codebase between prerelease and current version. |
There are too many changes between pre-alpha and stable versions so I think the best way is to start new PR instead of trying to rebase this one. |
This PR adds support for UI focus Tabs and TabContainer so they can be navigated using keyboard and gamepad. Related issues: #25877 #46111
Changes:
Pressing ui_down when TabContainer has focus will in practice have the same effect as pressing ui_focus_next, more details in the Known issues section.(refer to my second comment for more information)Known issues: