mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-29 04:37:55 +00:00
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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user