1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Add configuration warning when ButtonGroup is used with non-toggleable buttons

Also fix ambiguous documentation of ButtonGroup.
This commit is contained in:
Markus Sauermann
2022-12-20 07:08:42 +01:00
parent dcb3754db0
commit e4e13a404d
3 changed files with 16 additions and 2 deletions

View File

@@ -4,8 +4,8 @@
Group of Buttons. Group of Buttons.
</brief_description> </brief_description>
<description> <description>
Group of [Button]. All direct and indirect children buttons become radios. Only one allows being pressed. Group of [BaseButton]. The members of this group are treated like radio buttons in the sense that only one button can be pressed at the same time.
[member BaseButton.toggle_mode] should be [code]true[/code]. Every member of the ButtonGroup should have [member BaseButton.toggle_mode] set to [code]true[/code].
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@@ -300,6 +300,7 @@ void BaseButton::set_toggle_mode(bool p_on) {
} }
toggle_mode = p_on; toggle_mode = p_on;
update_configuration_warnings();
} }
bool BaseButton::is_toggle_mode() const { bool BaseButton::is_toggle_mode() const {
@@ -381,6 +382,7 @@ void BaseButton::set_button_group(const Ref<ButtonGroup> &p_group) {
} }
queue_redraw(); //checkbox changes to radio if set a buttongroup queue_redraw(); //checkbox changes to radio if set a buttongroup
update_configuration_warnings();
} }
Ref<ButtonGroup> BaseButton::get_button_group() const { Ref<ButtonGroup> BaseButton::get_button_group() const {
@@ -399,6 +401,16 @@ bool BaseButton::is_shortcut_feedback() const {
return shortcut_feedback; return shortcut_feedback;
} }
PackedStringArray BaseButton::get_configuration_warnings() const {
PackedStringArray warnings = Control::get_configuration_warnings();
if (get_button_group().is_valid() && !is_toggle_mode()) {
warnings.push_back(RTR("ButtonGroup is intended to be used only with buttons that have toggle_mode set to true."));
}
return warnings;
}
void BaseButton::_bind_methods() { void BaseButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed); ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &BaseButton::set_pressed);
ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed); ClassDB::bind_method(D_METHOD("is_pressed"), &BaseButton::is_pressed);

View File

@@ -136,6 +136,8 @@ public:
void set_shortcut_feedback(bool p_feedback); void set_shortcut_feedback(bool p_feedback);
bool is_shortcut_feedback() const; bool is_shortcut_feedback() const;
PackedStringArray get_configuration_warnings() const override;
BaseButton(); BaseButton();
~BaseButton(); ~BaseButton();
}; };