Allow setting icon max width for TabContainer

This commit is contained in:
Haoyu Qiu 2024-04-26 08:27:27 +08:00
parent 11d3768132
commit 779426b2fa
3 changed files with 36 additions and 0 deletions

View File

@ -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]. Returns the [Texture2D] for the tab at index [param tab_idx] or [code]null[/code] if the tab has no [Texture2D].
</description> </description>
</method> </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"> <method name="get_tab_idx_at_point" qualifiers="const">
<return type="int" /> <return type="int" />
<param index="0" name="point" type="Vector2" /> <param index="0" name="point" type="Vector2" />
@ -164,6 +171,14 @@
Sets an icon for the tab at index [param tab_idx]. Sets an icon for the tab at index [param tab_idx].
</description> </description>
</method> </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"> <method name="set_tab_metadata">
<return type="void" /> <return type="void" />
<param index="0" name="tab_idx" type="int" /> <param index="0" name="tab_idx" type="int" />

View File

@ -794,6 +794,22 @@ Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const {
return tab_bar->get_tab_icon(p_tab); 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) { void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) {
if (tab_bar->is_tab_disabled(p_tab) == p_disabled) { if (tab_bar->is_tab_disabled(p_tab) == p_disabled) {
return; return;
@ -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("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("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("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("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("is_tab_disabled", "tab_idx"), &TabContainer::is_tab_disabled);
ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden); ClassDB::bind_method(D_METHOD("set_tab_hidden", "tab_idx", "hidden"), &TabContainer::set_tab_hidden);

View File

@ -161,6 +161,9 @@ public:
void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon); void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon);
Ref<Texture2D> get_tab_icon(int p_tab) const; 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); void set_tab_disabled(int p_tab, bool p_disabled);
bool is_tab_disabled(int p_tab) const; bool is_tab_disabled(int p_tab) const;