From 5e19e72a6afa8522e454deae59a50ebc98ceef35 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 1 Jan 2021 00:30:28 +0100 Subject: 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. :^) --- Libraries/LibGUI/AbstractButton.cpp | 2 +- Libraries/LibGUI/RadioButton.cpp | 16 +--------------- Libraries/LibGUI/RadioButton.h | 2 -- 3 files changed, 2 insertions(+), 18 deletions(-) (limited to 'Libraries') 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 + * Copyright (c) 2018-2021, Andreas Kling * 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 -void RadioButton::for_each_in_group(Callback callback) -{ - if (!parent()) - return; - parent()->for_each_child_of_type([&](auto& child) { - return callback(downcast(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 - void for_each_in_group(Callback); static Gfx::IntSize circle_size(); }; -- cgit v1.2.3