Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_checkable_icon_button.hpp
1#pragma once
2
3#include "structure/design_pattern/spk_stateful_object.hpp"
4#include "structure/widget/spk_icon_button.hpp"
5
6namespace spk
7{
19 {
20 public:
29
35 explicit CheckableIconButton(const std::wstring &p_name, spk::Widget *p_parent);
36
41 bool checked() const;
46 void setChecked(bool p_checked);
50 void toggle();
55 void setCheckedIconSpriteID(const spk::Vector2UInt &p_spriteID);
62 StateContract addStateCallback(bool p_state, const StateJob &p_callback);
63
64 private:
66
67 spk::StatefulObject<bool> _state{false};
68 spk::Vector2UInt _checkedSpriteID{8, 0};
69 IconButton::Contract _toggleContract;
70 };
71}
StateContract addStateCallback(bool p_state, const StateJob &p_callback)
Adds a callback for a specific state value.
Definition spk_checkable_icon_button.cpp:46
bool checked() const
Returns whether the button is checked.
Definition spk_checkable_icon_button.cpp:16
spk::StatefulObject< bool >::Job StateJob
Job type invoked when state changes.
Definition spk_checkable_icon_button.hpp:28
void setChecked(bool p_checked)
Sets the checked state.
Definition spk_checkable_icon_button.cpp:21
spk::StatefulObject< bool >::Contract StateContract
Contract type for state change subscriptions.
Definition spk_checkable_icon_button.hpp:24
void setCheckedIconSpriteID(const spk::Vector2UInt &p_spriteID)
Sets the sprite ID used when checked.
Definition spk_checkable_icon_button.cpp:37
void toggle()
Toggles the checked state.
Definition spk_checkable_icon_button.cpp:32
CheckableIconButton(const std::wstring &p_name, spk::Widget *p_parent)
Builds a checkable icon button.
Definition spk_checkable_icon_button.cpp:5
Button widget that displays a background and icon per state.
Definition spk_icon_button.hpp:22
spk::TContractProvider<>::Contract Contract
Contract type for click subscriptions.
Definition spk_icon_button.hpp:27
void setIconSpriteID(const spk::Vector2UInt &p_spriteID, State p_state=State::Both)
Sets the icon sprite ID for a state.
Definition spk_icon_button.cpp:252
Tracks a state value and triggers callbacks per-state.
Definition spk_stateful_object.hpp:19
ContractProvider::Job Job
Callable invoked when the object transitions to a state.
Definition spk_stateful_object.hpp:24
ContractProvider::Contract Contract
Handle allowing subscribers to manage callback lifetimes.
Definition spk_stateful_object.hpp:22
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52