Skip to content

Commit

Permalink
Merge pull request #91193 from timothyqiu/tab-icon-size
Browse files Browse the repository at this point in the history
Allow setting max icon width per tab for TabContainer
  • Loading branch information
akien-mga committed Apr 26, 2024
2 parents 853740e + 779426b commit f55b81b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/classes/TabContainer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@
Returns the [Texture2D] for the tab at index [param tab_idx] or [code]null[/code] if the tab has no [Texture2D].
</description>
</method>
<method name="get_tab_icon_max_width" qualifiers="const">
<return type="int" />
<param index="0" name="tab_idx" type="int" />
<description>
Returns the maximum allowed width of the icon for the tab at index [param tab_idx].
</description>
</method>
<method name="get_tab_idx_at_point" qualifiers="const">
<return type="int" />
<param index="0" name="point" type="Vector2" />
Expand Down Expand Up @@ -164,6 +171,14 @@
Sets an icon for the tab at index [param tab_idx].
</description>
</method>
<method name="set_tab_icon_max_width">
<return type="void" />
<param index="0" name="tab_idx" type="int" />
<param index="1" name="width" type="int" />
<description>
Sets the maximum allowed width of the icon for the tab at index [param tab_idx]. This limit is applied on top of the default size of the icon and on top of [theme_item icon_max_width]. The height is adjusted according to the icon's ratio.
</description>
</method>
<method name="set_tab_metadata">
<return type="void" />
<param index="0" name="tab_idx" type="int" />
Expand Down
18 changes: 18 additions & 0 deletions scene/gui/tab_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,22 @@ Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
return tab_bar->get_tab_icon(p_tab);
}

void TabContainer::set_tab_icon_max_width(int p_tab, int p_width) {
if (tab_bar->get_tab_icon_max_width(p_tab) == p_width) {
return;
}

tab_bar->set_tab_icon_max_width(p_tab, p_width);

_update_margins();
_repaint();
queue_redraw();
}

int TabContainer::get_tab_icon_max_width(int p_tab) const {
return tab_bar->get_tab_icon_max_width(p_tab);
}

void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
if (tab_bar->is_tab_disabled(p_tab) == p_disabled) {
return;
Expand Down Expand Up @@ -990,6 +1006,8 @@ void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_tooltip", "tab_idx"), &TabContainer::get_tab_tooltip);
ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
ClassDB::bind_method(D_METHOD("get_tab_icon", "tab_idx"), &TabContainer::get_tab_icon);
ClassDB::bind_method(D_METHOD("set_tab_icon_max_width", "tab_idx", "width"), &TabContainer::set_tab_icon_max_width);
ClassDB::bind_method(D_METHOD("get_tab_icon_max_width", "tab_idx"), &TabContainer::get_tab_icon_max_width);
ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &TabContainer::set_tab_disabled);
ClassDB::bind_method(D_METHOD("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled);
ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden);
Expand Down
3 changes: 3 additions & 0 deletions scene/gui/tab_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ class TabContainer : public Container {
void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon);
Ref<Texture2D> get_tab_icon(int p_tab) const;

void set_tab_icon_max_width(int p_tab, int p_width);
int get_tab_icon_max_width(int p_tab) const;

void set_tab_disabled(int p_tab, bool p_disabled);
bool is_tab_disabled(int p_tab) const;

Expand Down

0 comments on commit f55b81b

Please sign in to comment.