LibGUI: Add an "exclusive" property to GAbstractButtons.

This makes checkable buttons exclusive with other checkable buttons in the
same parent widget. Basically like radio buttons. This should probably be
used to implement GRadioButton once it's a bit more mature.
This commit is contained in:
Andreas Kling 2019-06-12 05:57:26 +02:00
commit d7756fc09f
Notes: sideshowbarker 2024-07-19 13:39:16 +09:00
4 changed files with 31 additions and 0 deletions

View file

@ -29,6 +29,20 @@ void GAbstractButton::set_checked(bool checked)
if (m_checked == checked)
return;
m_checked = checked;
if (is_exclusive() && checked) {
parent_widget()->for_each_child_of_type<GAbstractButton>([&] (auto& sibling) {
if (!sibling.is_exclusive() || !sibling.is_checkable() || !sibling.is_checked())
return IterationDecision::Continue;
sibling.m_checked = false;
sibling.update();
if (sibling.on_checked)
sibling.on_checked(false);
return IterationDecision::Continue;
});
m_checked = true;
}
update();
if (on_checked)
on_checked(checked);