diff options
author | Andreas Kling <kling@serenityos.org> | 2021-01-01 00:30:28 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-01-01 00:33:44 +0100 |
commit | 5e19e72a6afa8522e454deae59a50ebc98ceef35 (patch) | |
tree | 1f65b247f587feb136f073aec8c7a8fc384ecd2f /Libraries | |
parent | f0482a4cabbffbda01e0fd68df2ad7f0d5360288 (diff) | |
download | serenity-5e19e72a6afa8522e454deae59a50ebc98ceef35.zip |
LibGUI: Simplify RadioButton by using AbstractButton exclusive mode
Making an AbstractButton exclusive means that we enforce that only one
of the exclusive buttons within the same parent widget can be checked
at a time.
RadioButton was doing exactly the same thing, except in a custom way.
So just remove the custom code and make it exclusive. :^)
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/AbstractButton.cpp | 2 | ||||
-rw-r--r-- | Libraries/LibGUI/RadioButton.cpp | 16 | ||||
-rw-r--r-- | Libraries/LibGUI/RadioButton.h | 2 |
3 files changed, 2 insertions, 18 deletions
diff --git a/Libraries/LibGUI/AbstractButton.cpp b/Libraries/LibGUI/AbstractButton.cpp index 6f839017f0..a71ab20ce0 100644 --- a/Libraries/LibGUI/AbstractButton.cpp +++ b/Libraries/LibGUI/AbstractButton.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/Libraries/LibGUI/RadioButton.cpp b/Libraries/LibGUI/RadioButton.cpp index a6bb9c636a..bafefffa07 100644 --- a/Libraries/LibGUI/RadioButton.cpp +++ b/Libraries/LibGUI/RadioButton.cpp @@ -36,6 +36,7 @@ namespace GUI { RadioButton::RadioButton(String text) : AbstractButton(move(text)) { + set_exclusive(true); set_min_width(32); set_fixed_height(22); } @@ -73,25 +74,10 @@ void RadioButton::paint_event(PaintEvent& event) painter.draw_focus_rect(text_rect.inflated(6, 6), palette().focus_outline()); } -template<typename Callback> -void RadioButton::for_each_in_group(Callback callback) -{ - if (!parent()) - return; - parent()->for_each_child_of_type<RadioButton>([&](auto& child) { - return callback(downcast<RadioButton>(child)); - }); -} - void RadioButton::click(unsigned) { if (!is_enabled()) return; - for_each_in_group([this](auto& button) { - if (&button != this) - button.set_checked(false); - return IterationDecision::Continue; - }); set_checked(true); } diff --git a/Libraries/LibGUI/RadioButton.h b/Libraries/LibGUI/RadioButton.h index 1c4c163755..aaaedd9185 100644 --- a/Libraries/LibGUI/RadioButton.h +++ b/Libraries/LibGUI/RadioButton.h @@ -49,8 +49,6 @@ private: virtual bool is_radio_button() const final { return true; } - template<typename Callback> - void for_each_in_group(Callback); static Gfx::IntSize circle_size(); }; |