From 342dac77d495966bb2090e68ff7b88f3ce162236 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sat, 19 Mar 2022 13:36:10 +0100 Subject: [PATCH] Hide text and icon properties in OptionButton --- doc/classes/OptionButton.xml | 1 + scene/gui/option_button.cpp | 6 ++++++ scene/gui/option_button.h | 1 + 3 files changed, 8 insertions(+) diff --git a/doc/classes/OptionButton.xml b/doc/classes/OptionButton.xml index 69e6d4b74c5..25e41116a2e 100644 --- a/doc/classes/OptionButton.xml +++ b/doc/classes/OptionButton.xml @@ -6,6 +6,7 @@ OptionButton is a type button that provides a selectable list of items when pressed. The item selected becomes the "current" item and is displayed as the button text. See also [BaseButton] which contains common properties and methods associated with this node. + [b]Note:[/b] Properties [member Button.text] and [member Button.icon] are automatically set based on the selected item. They shouldn't be changed manually. diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 37d75cea6a1..1e8a149e11a 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -385,6 +385,12 @@ void OptionButton::get_translatable_strings(List *p_strings) const { popup->get_translatable_strings(p_strings); } +void OptionButton::_validate_property(PropertyInfo &property) const { + if (property.name == "text" || property.name == "icon") { + property.usage = PROPERTY_USAGE_NONE; + } +} + void OptionButton::_bind_methods() { ClassDB::bind_method(D_METHOD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item, DEFVAL(-1)); diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 0a3c8cdb17a..732730e0f4d 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -53,6 +53,7 @@ protected: bool _set(const StringName &p_name, const Variant &p_value); bool _get(const StringName &p_name, Variant &r_ret) const; void _get_property_list(List *p_list) const; + virtual void _validate_property(PropertyInfo &property) const override; static void _bind_methods(); public: