mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 03:05:07 +00:00
LibGUI: Add GActionGroup, a way to group a bunch of GActions.
This can be used to make a bunch of actions mutually exclusive. This patch only implements the exclusivity behavior for buttons.
This commit is contained in:
parent
2ae0333f5d
commit
7083a0104a
9 changed files with 97 additions and 6 deletions
|
@ -1,7 +1,8 @@
|
|||
#include "GButton.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GAction.h>
|
||||
#include <LibGUI/GActionGroup.h>
|
||||
#include <LibGUI/GButton.h>
|
||||
#include <LibGUI/GPainter.h>
|
||||
#include <SharedGraphics/StylePainter.h>
|
||||
|
||||
|
@ -60,8 +61,11 @@ void GButton::click()
|
|||
{
|
||||
if (!is_enabled())
|
||||
return;
|
||||
if (is_checkable())
|
||||
if (is_checkable()) {
|
||||
if (is_checked() && !is_uncheckable())
|
||||
return;
|
||||
set_checked(!is_checked());
|
||||
}
|
||||
if (on_click)
|
||||
on_click(*this);
|
||||
}
|
||||
|
@ -88,3 +92,12 @@ void GButton::set_icon(RefPtr<GraphicsBitmap>&& icon)
|
|||
m_icon = move(icon);
|
||||
update();
|
||||
}
|
||||
|
||||
bool GButton::is_uncheckable() const
|
||||
{
|
||||
if (!m_action)
|
||||
return true;
|
||||
if (!m_action->group())
|
||||
return true;
|
||||
return m_action->group()->is_unchecking_allowed();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue