Add Tab Metadata

This commit is contained in:
ShadyChibinko 2023-04-11 20:24:52 -04:00
parent b14a759fb3
commit 7af43733e1
6 changed files with 72 additions and 0 deletions

View file

@ -72,6 +72,13 @@
Returns the index of the tab at local coordinates [code]point[/code]. Returns [code]-1[/code] if the point is outside the control boundaries or if there's no tab at the queried position. Returns the index of the tab at local coordinates [code]point[/code]. Returns [code]-1[/code] if the point is outside the control boundaries or if there's no tab at the queried position.
</description> </description>
</method> </method>
<method name="get_tab_metadata" qualifiers="const">
<return type="Variant" />
<argument index="0" name="tab_idx" type="int" />
<description>
Returns the metadata value set to the tab at index [code]tab_idx[/code]. If no metadata was previously set, returns [code]null[/code] by default.
</description>
</method>
<method name="get_tab_title" qualifiers="const"> <method name="get_tab_title" qualifiers="const">
<return type="String" /> <return type="String" />
<argument index="0" name="tab_idx" type="int" /> <argument index="0" name="tab_idx" type="int" />
@ -116,6 +123,14 @@
Sets an icon for the tab at index [code]tab_idx[/code]. Sets an icon for the tab at index [code]tab_idx[/code].
</description> </description>
</method> </method>
<method name="set_tab_metadata">
<return type="void" />
<argument index="0" name="tab_idx" type="int" />
<argument index="1" name="metadata" type="Variant" />
<description>
Sets the metadata value for the tab at index [code]tab_idx[/code].
</description>
</method>
<method name="set_tab_title"> <method name="set_tab_title">
<return type="void" /> <return type="void" />
<argument index="0" name="tab_idx" type="int" /> <argument index="0" name="tab_idx" type="int" />

View file

@ -69,6 +69,13 @@
Returns the [Texture] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture]. Returns the [Texture] for the tab at index [code]tab_idx[/code] or [code]null[/code] if the tab has no [Texture].
</description> </description>
</method> </method>
<method name="get_tab_metadata" qualifiers="const">
<return type="Variant" />
<argument index="0" name="tab_idx" type="int" />
<description>
Returns the metadata value set to the tab at index [code]tab_idx[/code]. If no metadata was previously set, returns [code]null[/code] by default.
</description>
</method>
<method name="get_tab_offset" qualifiers="const"> <method name="get_tab_offset" qualifiers="const">
<return type="int" /> <return type="int" />
<description> <description>
@ -141,6 +148,14 @@
Sets an [code]icon[/code] for the tab at index [code]tab_idx[/code]. Sets an [code]icon[/code] for the tab at index [code]tab_idx[/code].
</description> </description>
</method> </method>
<method name="set_tab_metadata">
<return type="void" />
<argument index="0" name="tab_idx" type="int" />
<argument index="1" name="metadata" type="Variant" />
<description>
Sets the metadata value for the tab at index [code]tab_idx[/code].
</description>
</method>
<method name="set_tab_title"> <method name="set_tab_title">
<return type="void" /> <return type="void" />
<argument index="0" name="tab_idx" type="int" /> <argument index="0" name="tab_idx" type="int" />

View file

@ -931,6 +931,22 @@ bool TabContainer::get_tab_hidden(int p_tab) const {
} }
} }
void TabContainer::set_tab_metadata(int p_tab, const Variant &p_metadata) {
Control *child = get_tab_control(p_tab);
ERR_FAIL_COND(!child);
child->set_meta("_tab_metadata", p_metadata);
}
Variant TabContainer::get_tab_metadata(int p_tab) const {
Control *child = get_tab_control(p_tab);
ERR_FAIL_COND_V(!child, Variant());
if (child->has_meta("_tab_metadata")) {
return child->get_meta("_tab_metadata");
} else {
return Variant();
}
}
void TabContainer::get_translatable_strings(List<String> *p_strings) const { void TabContainer::get_translatable_strings(List<String> *p_strings) const {
Vector<Control *> tabs = _get_tabs(); Vector<Control *> tabs = _get_tabs();
for (int i = 0; i < tabs.size(); i++) { for (int i = 0; i < tabs.size(); i++) {
@ -1047,6 +1063,8 @@ void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &TabContainer::get_tab_disabled); ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &TabContainer::get_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);
ClassDB::bind_method(D_METHOD("get_tab_hidden", "tab_idx"), &TabContainer::get_tab_hidden); ClassDB::bind_method(D_METHOD("get_tab_hidden", "tab_idx"), &TabContainer::get_tab_hidden);
ClassDB::bind_method(D_METHOD("set_tab_metadata", "tab_idx", "metadata"), &TabContainer::set_tab_metadata);
ClassDB::bind_method(D_METHOD("get_tab_metadata", "tab_idx"), &TabContainer::get_tab_metadata);
ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point); ClassDB::bind_method(D_METHOD("get_tab_idx_at_point", "point"), &TabContainer::get_tab_idx_at_point);
ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup); ClassDB::bind_method(D_METHOD("set_popup", "popup"), &TabContainer::set_popup);
ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup); ClassDB::bind_method(D_METHOD("get_popup"), &TabContainer::get_popup);

View file

@ -107,6 +107,9 @@ public:
void set_tab_hidden(int p_tab, bool p_hidden); void set_tab_hidden(int p_tab, bool p_hidden);
bool get_tab_hidden(int p_tab) const; bool get_tab_hidden(int p_tab) const;
void set_tab_metadata(int p_tab, const Variant &p_metadata);
Variant get_tab_metadata(int p_tab) const;
int get_tab_count() const; int get_tab_count() const;
void set_current_tab(int p_current); void set_current_tab(int p_current);
int get_current_tab() const; int get_current_tab() const;

View file

@ -472,6 +472,21 @@ bool Tabs::get_tab_disabled(int p_tab) const {
return tabs[p_tab].disabled; return tabs[p_tab].disabled;
} }
void Tabs::set_tab_metadata(int p_tab, const Variant &p_metadata) {
ERR_FAIL_INDEX(p_tab, tabs.size());
if (tabs[p_tab].metadata == p_metadata) {
return;
}
tabs.write[p_tab].metadata = p_metadata;
}
Variant Tabs::get_tab_metadata(int p_tab) const {
ERR_FAIL_INDEX_V(p_tab, tabs.size(), Variant());
return tabs[p_tab].metadata;
}
void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) { void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) {
ERR_FAIL_INDEX(p_tab, tabs.size()); ERR_FAIL_INDEX(p_tab, tabs.size());
tabs.write[p_tab].right_button = p_right_button; tabs.write[p_tab].right_button = p_right_button;
@ -961,6 +976,8 @@ void Tabs::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &Tabs::get_tab_right_button); ClassDB::bind_method(D_METHOD("get_tab_button_icon", "tab_idx"), &Tabs::get_tab_right_button);
ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &Tabs::set_tab_disabled); ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &Tabs::set_tab_disabled);
ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &Tabs::get_tab_disabled); ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &Tabs::get_tab_disabled);
ClassDB::bind_method(D_METHOD("set_tab_metadata", "tab_idx", "metadata"), &Tabs::set_tab_metadata);
ClassDB::bind_method(D_METHOD("get_tab_metadata", "tab_idx"), &Tabs::get_tab_metadata);
ClassDB::bind_method(D_METHOD("remove_tab", "tab_idx"), &Tabs::remove_tab); ClassDB::bind_method(D_METHOD("remove_tab", "tab_idx"), &Tabs::remove_tab);
ClassDB::bind_method(D_METHOD("add_tab", "title", "icon"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture>())); ClassDB::bind_method(D_METHOD("add_tab", "title", "icon"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture>()));
ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &Tabs::set_tab_align); ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &Tabs::set_tab_align);

View file

@ -60,6 +60,7 @@ private:
Ref<Texture> icon; Ref<Texture> icon;
int ofs_cache; int ofs_cache;
bool disabled; bool disabled;
Variant metadata;
int size_cache; int size_cache;
int size_text; int size_text;
int x_cache; int x_cache;
@ -124,6 +125,9 @@ public:
void set_tab_disabled(int p_tab, bool p_disabled); void set_tab_disabled(int p_tab, bool p_disabled);
bool get_tab_disabled(int p_tab) const; bool get_tab_disabled(int p_tab) const;
void set_tab_metadata(int p_tab, const Variant &p_metadata);
Variant get_tab_metadata(int p_tab) const;
void set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button); void set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button);
Ref<Texture> get_tab_right_button(int p_tab) const; Ref<Texture> get_tab_right_button(int p_tab) const;