From d7f455f36f7b26b131ff05c28f778c4cf98782a4 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 20 Mar 2022 19:07:53 +0100 Subject: [PATCH] Backported: - Add item tooltip access to OptionButton - timothyqiu - https://github.com/godotengine/godot/commit/d537a88299ee1faa79ea81d6acd0774e59c3a288 --- doc/classes/OptionButton.xml | 15 +++++++++++++++ scene/gui/option_button.cpp | 10 ++++++++++ scene/gui/option_button.h | 2 ++ 3 files changed, 27 insertions(+) diff --git a/doc/classes/OptionButton.xml b/doc/classes/OptionButton.xml index 86cd136b5..09f7d66f4 100644 --- a/doc/classes/OptionButton.xml +++ b/doc/classes/OptionButton.xml @@ -80,6 +80,13 @@ Returns the text of the item at index [code]idx[/code]. + + + + + Returns the tooltip of the item at index [code]idx[/code]. + + @@ -161,6 +168,14 @@ Sets the text of the item at index [code]idx[/code]. + + + + + + Sets the tooltip of the item at index [code]idx[/code]. + + diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 21e7f8907..5568f279e 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -162,6 +162,10 @@ void OptionButton::set_item_disabled(int p_idx, bool p_disabled) { popup->set_item_disabled(p_idx, p_disabled); } +void OptionButton::set_item_tooltip(int p_idx, const String &p_tooltip) { + popup->set_item_tooltip(p_idx, p_tooltip); +} + String OptionButton::get_item_text(int p_idx) const { return popup->get_item_text(p_idx); } @@ -186,6 +190,10 @@ bool OptionButton::is_item_disabled(int p_idx) const { return popup->is_item_disabled(p_idx); } +String OptionButton::get_item_tooltip(int p_idx) const { + return popup->get_item_tooltip(p_idx); +} + int OptionButton::get_item_count() const { return popup->get_item_count(); } @@ -305,6 +313,8 @@ void OptionButton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_item_text", "idx", "text"), &OptionButton::set_item_text); ClassDB::bind_method(D_METHOD("set_item_icon", "idx", "texture"), &OptionButton::set_item_icon); ClassDB::bind_method(D_METHOD("set_item_disabled", "idx", "disabled"), &OptionButton::set_item_disabled); + ClassDB::bind_method(D_METHOD("get_item_tooltip", "idx"), &OptionButton::get_item_tooltip); + ClassDB::bind_method(D_METHOD("set_item_tooltip", "idx", "tooltip"), &OptionButton::set_item_tooltip); ClassDB::bind_method(D_METHOD("set_item_id", "idx", "id"), &OptionButton::set_item_id); ClassDB::bind_method(D_METHOD("set_item_metadata", "idx", "metadata"), &OptionButton::set_item_metadata); ClassDB::bind_method(D_METHOD("get_item_text", "idx"), &OptionButton::get_item_text); diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 9a8a7c051..20800ab90 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -64,6 +64,7 @@ public: void set_item_id(int p_idx, int p_id); void set_item_metadata(int p_idx, const Variant &p_metadata); void set_item_disabled(int p_idx, bool p_disabled); + void set_item_tooltip(int p_idx, const String &p_tooltip); String get_item_text(int p_idx) const; Ref get_item_icon(int p_idx) const; @@ -71,6 +72,7 @@ public: int get_item_index(int p_id) const; Variant get_item_metadata(int p_idx) const; bool is_item_disabled(int p_idx) const; + String get_item_tooltip(int p_idx) const; int get_item_count() const;