mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-26 11:20:03 +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:
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user