Sparkle 0.0.1
Loading...
Searching...
No Matches
spk::IconButton Class Reference

Button widget that displays a background and icon per state. More...

#include <spk_icon_button.hpp>

Inheritance diagram for spk::IconButton:
Inheritance graph
Collaboration diagram for spk::IconButton:
Collaboration graph

Public Types

enum class  State { Released , Pressed , Hovered , Both }
 Visual state of the button.
using Contract = spk::TContractProvider<>::Contract
 Contract type for click subscriptions.
using Job = spk::TContractProvider<>::Job
 Job type invoked on clicks.
Public Types inherited from spk::Widget
enum class  FocusType { Keyboard = 0 , Mouse = 1 }
 Types of focus a widget can own.
Public Types inherited from spk::ActivableObject
using Contract = StatefulObject<ActivationStatus>::Contract
 Subscription handle controlling callback lifetime.
using Job = StatefulObject<ActivationStatus>::Job
 Callback signature executed on activation state changes.
Public Types inherited from spk::StatefulObject< ActivationStatus >
using Contract
 Handle allowing subscribers to manage callback lifetimes.
using Job
 Callable invoked when the object transitions to a state.

Public Member Functions

 IconButton (const std::wstring &p_name, spk::Widget *p_parent)
 Builds an icon button widget.
void setVisualState (const State &p_state)
 Sets the current visual state.
void toggle (State p_state=State::Both)
 Toggles icon visibility for a state.
bool isIconVisible (State p_state=State::Released) const
 Returns icon visibility for a state.
Contract subscribe (const Job &p_job)
 Subscribes to click events.
void setTexture (const spk::SpriteSheet *p_spriteSheet, State p_state=State::Both)
 Sets the background texture for a state.
void setCornerSize (const spk::Vector2UInt &p_cornerSize, State p_state=State::Both)
 Sets the background corner size for a state.
void setIconTexture (const spk::SpriteSheet &p_spriteSheet, State p_state=State::Both)
 Sets the icon texture from a sprite sheet reference.
void setIconTexture (const spk::SpriteSheet *p_spriteSheet, State p_state=State::Both)
 Sets the icon texture from a sprite sheet pointer.
void setIconSpriteID (const spk::Vector2UInt &p_spriteID, State p_state=State::Both)
 Sets the icon sprite ID for a state.
void setIconPadding (const spk::Vector2UInt &p_padding, State p_state=State::Both)
 Sets icon padding for a state.
const spk::SpriteSheettexture (State p_state=State::Both) const
 Returns the background texture for a state.
const spk::Vector2UIntcornerSize (State p_state=State::Both) const
 Returns the background corner size for a state.
const spk::SpriteSheeticonTexture (State p_state=State::Both) const
 Returns the icon texture for a state.
const spk::Vector2UInticonSpriteID (State p_state=State::Both) const
 Returns the icon sprite ID for a state.
const spk::Vector2UInticonPadding (State p_state=State::Both) const
 Returns the icon padding for a state.
Public Member Functions inherited from spk::Widget
void takeFocus (FocusType p_focusType)
 Grants this widget ownership of the requested focus type.
void releaseFocus (FocusType p_focusType)
 Releases a previously acquired focus type.
bool hasFocus (FocusType p_focusType) const
 Checks if this widget currently owns a focus type.
void takeAllFocus ()
 Acquires both keyboard and mouse focus.
void releaseAllFocus ()
 Releases both keyboard and mouse focus types.
 Widget (const std::wstring &p_name, Widget *p_parent)
 Builds a widget optionally attached to a parent.
void addChild (Widget *p_child) override
 Adds a child widget and sorts the hierarchy by layer.
const float & layer () const
 Current rendering layer of the widget.
void setLayer (const float &p_newLayer)
 Updates the widget layer and propagates relative offsets to children.
const std::wstring & name () const
 Retrieves the widget name.
void setName (const std::wstring &p_name)
 Sets the widget name.
void setGeometry (const spk::Extend2D &p_geometry) override
 Requests a specific viewport and scissor region for the widget.
const spk::Extend2Dgeometry () const
 Returns the current widget geometry.
const spk::OpenGL::ViewRegionviewRegion () const
 Accesses the computed view region.
const spk::OpenGL::FrameBufferObjectframeBufferObject () const
 Returns the frame buffer object used for widget rendering.
const spk::OpenGL::FrameBufferObjectfbo () const
 Alias for frameBufferObject().
void requireGeometryChange ()
 Marks the widget view region as needing recomputation.
Public Member Functions inherited from spk::InherenceObject< Widget >
virtual void removeChild (Widget *p_child)
 Removes a child from this node.
Widgetparent () const
 Returns the parent pointer.
virtual std::vector< Widget * > & children ()
 Returns the children vector.
void clearChildren ()
 Clears the children list and resets each child's parent pointer.
Public Member Functions inherited from spk::ActivableObject
 ActivableObject ()
 Builds a deactivated object.
 ActivableObject (ActivationStatus p_initial)
 Builds with a custom initial activation state.
void activate ()
 Sets the state to Activated.
void deactivate ()
 Sets the state to Deactivated.
void toggle ()
 Toggles between activated and deactivated states.
bool isActive () const
 Checks whether the object is currently activated.
Contract addActivationCallback (const Job &p_callback)
 Registers a callback executed when the object activates.
Contract addDeactivationCallback (const Job &p_callback)
 Registers a callback executed when the object deactivates.
Public Member Functions inherited from spk::StatefulObject< ActivationStatus >
 StatefulObject (const ActivationStatus &p_initialState)
 Builds with an initial state.
StatefulObjectoperator= (const StatefulObject &p_other)=delete
void setState (const ActivationStatus &p_newState)
 Sets a new state and triggers callbacks registered for it.
ActivationStatus state () const
 Returns the current state.
Contract addCallback (const ActivationStatus &p_state, const Job &p_callback)
 Subscribes a callback for a specific state.
Public Member Functions inherited from spk::ResizableElement
SizeHintsizeHint ()
 Returns mutable size hint data.
const SizeHintsizeHint () const
 Returns const size hint data.

Protected Member Functions

void _setIconVisible (bool p_visible, State p_state=State::Both)
 Sets icon visibility for a state.
bool _iconVisible (State p_state=State::Released) const
 Returns icon visibility for a state.
void _onGeometryChange () override
 Updates layout geometry when size changes.
void _onPaintEvent (spk::PaintEvent &p_event) override
 Paints the button visuals.
void _onMousePressEvent (spk::MousePressEvent &p_event) override
 Handles mouse press events.
void _onMouseReleaseEvent (spk::MouseReleaseEvent &p_event) override
 Handles mouse release events.
void _onMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event) override
 Handles mouse double click events.
void _onMouseMotionEvent (spk::MouseMotionEvent &p_event) override
 Handles mouse motion events.
Protected Member Functions inherited from spk::Widget
virtual void _onKeyPressEvent (spk::KeyPressEvent &p_event)
 Keyboard press handler for derived widgets.
virtual void _onKeyReleaseEvent (spk::KeyReleaseEvent &p_event)
 Keyboard release handler for derived widgets.
virtual void _onGlyphEvent (spk::GlyphEvent &p_event)
 Text glyph input handler for derived widgets.
virtual void _onMouseWheelEvent (spk::MouseWheelEvent &p_event)
 Mouse wheel handler for derived widgets.
virtual void _onEnterResizeModeEvent (spk::EnterResizeModeEvent &p_event)
 Callback for entering resize mode.
virtual void _onResizeEvent (spk::ResizeEvent &p_event)
 Resize handling hook.
virtual void _onExitResizeModeEvent (spk::ExitResizeModeEvent &p_event)
 Callback invoked when leaving resize mode.
virtual void _onQuitEvent (spk::QuitEvent &p_event)
 Quit event handler hook.
virtual void _onMoveEvent (spk::MoveEvent &p_event)
 Window move handler hook.
virtual void _onFullScreenModeEvent (spk::FullScreenModeEvent &p_event)
 Full screen toggle handler hook.
virtual void _onMaximizedModeEvent (spk::MaximizedModeEvent &p_event)
 Maximized mode change handler.
virtual void _onFocusEvent (spk::FocusEvent &p_event)
 Focus change handler hook.
virtual void _onUpdateEvent (spk::UpdateEvent &p_event)
 Frame update handler hook.

Additional Inherited Members

Static Public Member Functions inherited from spk::Widget
static WidgetfocusedWidget (FocusType p_focusType)
 Retrieves the widget currently owning a focus type.
Static Public Attributes inherited from spk::Widget
static const size_t NbFocusType = 2
 Number of focus slots tracked at runtime.

Detailed Description

Button widget that displays a background and icon per state.

See also
IconRegion
spk::IconButton button(L"Icon", parent);
button.setIconSpriteID({0, 0});
Button widget that displays a background and icon per state.
Definition spk_icon_button.hpp:22
Widget * parent() const
Definition spk_inherence_object.hpp:85

Constructor & Destructor Documentation

◆ IconButton()

spk::IconButton::IconButton ( const std::wstring & p_name,
spk::Widget * p_parent )

Builds an icon button widget.

Parameters
p_nameWidget name.
p_parentParent widget.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _iconVisible()

bool spk::IconButton::_iconVisible ( State p_state = State::Released) const
protected

Returns icon visibility for a state.

Parameters
p_stateState to query.
Returns
true when visible.
Here is the caller graph for this function:

◆ _onGeometryChange()

void spk::IconButton::_onGeometryChange ( )
overrideprotectedvirtual

Updates layout geometry when size changes.

Reimplemented from spk::Widget.

◆ _onMouseDoubleClickEvent()

void spk::IconButton::_onMouseDoubleClickEvent ( spk::MouseDoubleClickEvent & p_event)
overrideprotectedvirtual

Handles mouse double click events.

Parameters
p_eventMouse double click event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onMouseMotionEvent()

void spk::IconButton::_onMouseMotionEvent ( spk::MouseMotionEvent & p_event)
overrideprotectedvirtual

Handles mouse motion events.

Parameters
p_eventMouse motion event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onMousePressEvent()

void spk::IconButton::_onMousePressEvent ( spk::MousePressEvent & p_event)
overrideprotectedvirtual

Handles mouse press events.

Parameters
p_eventMouse press event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onMouseReleaseEvent()

void spk::IconButton::_onMouseReleaseEvent ( spk::MouseReleaseEvent & p_event)
overrideprotectedvirtual

Handles mouse release events.

Parameters
p_eventMouse release event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onPaintEvent()

void spk::IconButton::_onPaintEvent ( spk::PaintEvent & p_event)
overrideprotectedvirtual

Paints the button visuals.

Parameters
p_eventPaint event payload.

Reimplemented from spk::Widget.

◆ _setIconVisible()

void spk::IconButton::_setIconVisible ( bool p_visible,
State p_state = State::Both )
protected

Sets icon visibility for a state.

Parameters
p_visibleVisibility flag.
p_stateState to update.
Here is the caller graph for this function:

◆ cornerSize()

const spk::Vector2UInt & spk::IconButton::cornerSize ( State p_state = State::Both) const

Returns the background corner size for a state.

Parameters
p_stateState to query.
Returns
Corner size in pixels.

◆ iconPadding()

const spk::Vector2UInt & spk::IconButton::iconPadding ( State p_state = State::Both) const

Returns the icon padding for a state.

Parameters
p_stateState to query.
Returns
Padding value.

◆ iconSpriteID()

const spk::Vector2UInt & spk::IconButton::iconSpriteID ( State p_state = State::Both) const

Returns the icon sprite ID for a state.

Parameters
p_stateState to query.
Returns
Sprite coordinates.

◆ iconTexture()

const spk::SpriteSheet * spk::IconButton::iconTexture ( State p_state = State::Both) const

Returns the icon texture for a state.

Parameters
p_stateState to query.
Returns
Sprite sheet pointer or nullptr.

◆ isIconVisible()

bool spk::IconButton::isIconVisible ( State p_state = State::Released) const

Returns icon visibility for a state.

Parameters
p_stateState to query.
Returns
true when visible.
Here is the call graph for this function:

◆ setCornerSize()

void spk::IconButton::setCornerSize ( const spk::Vector2UInt & p_cornerSize,
State p_state = State::Both )

Sets the background corner size for a state.

Parameters
p_cornerSizeCorner size in pixels.
p_stateState to update.
Here is the call graph for this function:

◆ setIconPadding()

void spk::IconButton::setIconPadding ( const spk::Vector2UInt & p_padding,
State p_state = State::Both )

Sets icon padding for a state.

Parameters
p_paddingPadding value.
p_stateState to update.
Here is the call graph for this function:

◆ setIconSpriteID()

void spk::IconButton::setIconSpriteID ( const spk::Vector2UInt & p_spriteID,
State p_state = State::Both )

Sets the icon sprite ID for a state.

Parameters
p_spriteIDSprite coordinates.
p_stateState to update.

◆ setIconTexture() [1/2]

void spk::IconButton::setIconTexture ( const spk::SpriteSheet & p_spriteSheet,
State p_state = State::Both )

Sets the icon texture from a sprite sheet reference.

Parameters
p_spriteSheetSprite sheet reference.
p_stateState to update.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setIconTexture() [2/2]

void spk::IconButton::setIconTexture ( const spk::SpriteSheet * p_spriteSheet,
State p_state = State::Both )

Sets the icon texture from a sprite sheet pointer.

Parameters
p_spriteSheetSprite sheet pointer.
p_stateState to update.

◆ setTexture()

void spk::IconButton::setTexture ( const spk::SpriteSheet * p_spriteSheet,
State p_state = State::Both )

Sets the background texture for a state.

Parameters
p_spriteSheetSprite sheet pointer.
p_stateState to update.

◆ setVisualState()

void spk::IconButton::setVisualState ( const State & p_state)

Sets the current visual state.

Parameters
p_stateNew state.

◆ subscribe()

IconButton::Contract spk::IconButton::subscribe ( const Job & p_job)

Subscribes to click events.

Parameters
p_jobCallback invoked on click.
Returns
Subscription contract.
Here is the caller graph for this function:

◆ texture()

const spk::SpriteSheet * spk::IconButton::texture ( State p_state = State::Both) const

Returns the background texture for a state.

Parameters
p_stateState to query.
Returns
Sprite sheet pointer or nullptr.

◆ toggle()

void spk::IconButton::toggle ( State p_state = State::Both)

Toggles icon visibility for a state.

Parameters
p_stateState to toggle.

The documentation for this class was generated from the following files: