-
-
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
Allow to focus individual tabs in TabBar
/TabContainer
#79104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,6 +99,18 @@ | |
Returns [code]true[/code] if the tab at index [param tab_idx] is hidden. | ||
</description> | ||
</method> | ||
<method name="select_next_available"> | ||
<return type="bool" /> | ||
<description> | ||
Selects the first available tab with greater index than the currently selected. Returns [code]true[/code] if tab selection changed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here in that case |
||
</description> | ||
</method> | ||
<method name="select_previous_available"> | ||
<return type="bool" /> | ||
<description> | ||
Selects the first available tab with lower index than the currently selected. Returns [code]true[/code] if tab selection changed. | ||
</description> | ||
</method> | ||
<method name="set_popup"> | ||
<return type="void" /> | ||
<param index="0" name="popup" type="Node" /> | ||
|
@@ -171,6 +183,9 @@ | |
<member name="tab_alignment" type="int" setter="set_tab_alignment" getter="get_tab_alignment" enum="TabBar.AlignmentMode" default="0"> | ||
Sets the position at which tabs will be placed. See [enum TabBar.AlignmentMode] for details. | ||
</member> | ||
<member name="tab_focus_mode" type="int" setter="set_tab_focus_mode" getter="get_tab_focus_mode" enum="Control.FocusMode" default="2"> | ||
The focus access mode for the internal [TabBar] node. | ||
</member> | ||
<member name="tabs_rearrange_group" type="int" setter="set_tabs_rearrange_group" getter="get_tabs_rearrange_group" default="-1"> | ||
[TabContainer]s with the same rearrange group ID will allow dragging the tabs between them. Enable drag with [member drag_to_rearrange_enabled]. | ||
Setting this to [code]-1[/code] will disable rearranging between [TabContainer]s. | ||
|
@@ -291,6 +306,9 @@ | |
<theme_item name="tab_disabled" data_type="style" type="StyleBox"> | ||
The style of disabled tabs. | ||
</theme_item> | ||
<theme_item name="tab_focus" data_type="style" type="StyleBox"> | ||
[StyleBox] used when the [TabBar] is focused. The [theme_item tab_focus] [StyleBox] is displayed [i]over[/i] the base [StyleBox] of the selected tab, so a partially transparent [StyleBox] should be used to ensure the base [StyleBox] remains visible. A [StyleBox] that represents an outline or an underline works well for this purpose. To disable the focus visual effect, assign a [StyleBoxEmpty] resource. Note that disabling the focus visual effect will harm keyboard/controller navigation usability, so this is not recommended for accessibility reasons. | ||
</theme_item> | ||
<theme_item name="tab_hovered" data_type="style" type="StyleBox"> | ||
The style of the currently hovered tab. | ||
</theme_item> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,6 +107,10 @@ class TabBar : public Control { | |
bool scroll_to_selected = true; | ||
int tabs_rearrange_group = -1; | ||
|
||
const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5; | ||
const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20; | ||
float gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS; | ||
Comment on lines
+110
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the third control to implement this behavior and define these values. We should unify it somehow (but this is not necessarily a task for this PR). |
||
|
||
struct ThemeCache { | ||
int h_separation = 0; | ||
int icon_max_width = 0; | ||
|
@@ -115,6 +119,7 @@ class TabBar : public Control { | |
Ref<StyleBox> tab_hovered_style; | ||
Ref<StyleBox> tab_selected_style; | ||
Ref<StyleBox> tab_disabled_style; | ||
Ref<StyleBox> tab_focus_style; | ||
|
||
Ref<Texture2D> increment_icon; | ||
Ref<Texture2D> increment_hl_icon; | ||
|
@@ -148,7 +153,7 @@ class TabBar : public Control { | |
void _on_mouse_exited(); | ||
|
||
void _shape(int p_tab); | ||
void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x); | ||
void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x, bool p_focus); | ||
|
||
protected: | ||
virtual void gui_input(const Ref<InputEvent> &p_event) override; | ||
|
@@ -214,6 +219,9 @@ class TabBar : public Control { | |
int get_previous_tab() const; | ||
int get_hovered_tab() const; | ||
|
||
bool select_previous_available(); | ||
bool select_next_available(); | ||
|
||
int get_tab_offset() const; | ||
bool get_offset_buttons_visible() const; | ||
|
||
|
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.
Just potential nitpick, higher/lower are more complementary
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.
Sorry I missed your review comment while merging my last batch.