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

Base class for interactive UI elements handling focus and events. More...

#include <spk_widget.hpp>

Inheritance diagram for spk::Widget:
Inheritance graph
Collaboration diagram for spk::Widget:
Collaboration graph

Classes

struct  Style
 Collection of default assets used by widgets when no overrides are supplied. More...

Public Types

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

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.

Static Public Member Functions

static WidgetfocusedWidget (FocusType p_focusType)
 Retrieves the widget currently owning a focus type.

Static Public Attributes

static const size_t NbFocusType = 2
 Number of focus slots tracked at runtime.

Protected Member Functions

virtual void _onPaintEvent (spk::PaintEvent &p_event)
 Paint event hook for derived widgets.
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 _onMousePressEvent (spk::MousePressEvent &p_event)
 Mouse button press handler for derived widgets.
virtual void _onMouseReleaseEvent (spk::MouseReleaseEvent &p_event)
 Mouse button release handler for derived widgets.
virtual void _onMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event)
 Mouse double click handler for derived widgets.
virtual void _onMouseMotionEvent (spk::MouseMotionEvent &p_event)
 Mouse motion 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.
virtual void _onGeometryChange ()
 Notifies derived widgets that the view region changed.

Friends

class Module::KeyboardModule
class Module::MouseModule
class Module::SystemModule
class Module::UpdateModule
class Module::PaintModule

Detailed Description

Base class for interactive UI elements handling focus and events.

See also
spk::Module::KeyboardModule, spk::Module::MouseModule
spk::Widget button{L"button", nullptr};
button.takeFocus(spk::Widget::FocusType::Keyboard);
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52
void takeFocus(FocusType p_focusType)
Grants this widget ownership of the requested focus type.
Definition spk_widget.cpp:29

Constructor & Destructor Documentation

◆ Widget()

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

Builds a widget optionally attached to a parent.

Parameters
p_nameDisplay name of the widget.
p_parentParent widget to attach to; can be nullptr.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _onEnterResizeModeEvent()

void spk::Widget::_onEnterResizeModeEvent ( spk::EnterResizeModeEvent & p_event)
protectedvirtual

Callback for entering resize mode.

Parameters
p_eventEvent carrying the current window metrics when resizing starts.

Reimplemented in spk::GameEngineWidget.

◆ _onExitResizeModeEvent()

void spk::Widget::_onExitResizeModeEvent ( spk::ExitResizeModeEvent & p_event)
protectedvirtual

Callback invoked when leaving resize mode.

Parameters
p_eventEvent carrying the final window metrics after resizing.

Reimplemented in spk::GameEngineWidget.

◆ _onFocusEvent()

void spk::Widget::_onFocusEvent ( spk::FocusEvent & p_event)
protectedvirtual

Focus change handler hook.

Parameters
p_eventEvent containing the new focus state.

Reimplemented in spk::GameEngineWidget, and spk::TextEdit.

◆ _onFullScreenModeEvent()

void spk::Widget::_onFullScreenModeEvent ( spk::FullScreenModeEvent & p_event)
protectedvirtual

Full screen toggle handler hook.

Parameters
p_eventEvent describing the new full screen state.

Reimplemented in spk::GameEngineWidget.

◆ _onGeometryChange()

◆ _onGlyphEvent()

void spk::Widget::_onGlyphEvent ( spk::GlyphEvent & p_event)
protectedvirtual

Text glyph input handler for derived widgets.

Parameters
p_eventUnicode glyph information for text entry.

Reimplemented in spk::GameEngineWidget, and spk::TextEdit.

◆ _onKeyPressEvent()

void spk::Widget::_onKeyPressEvent ( spk::KeyPressEvent & p_event)
protectedvirtual

Keyboard press handler for derived widgets.

Parameters
p_eventKey code and modifiers associated with the press.

Reimplemented in spk::GameEngineWidget, and spk::TextEdit.

◆ _onKeyReleaseEvent()

void spk::Widget::_onKeyReleaseEvent ( spk::KeyReleaseEvent & p_event)
protectedvirtual

Keyboard release handler for derived widgets.

Parameters
p_eventKey code and modifiers associated with the release.

Reimplemented in spk::GameEngineWidget.

◆ _onMaximizedModeEvent()

void spk::Widget::_onMaximizedModeEvent ( spk::MaximizedModeEvent & p_event)
protectedvirtual

Maximized mode change handler.

Parameters
p_eventEvent describing the new maximized state.

Reimplemented in spk::GameEngineWidget.

◆ _onMouseDoubleClickEvent()

void spk::Widget::_onMouseDoubleClickEvent ( spk::MouseDoubleClickEvent & p_event)
protectedvirtual

Mouse double click handler for derived widgets.

Parameters
p_eventButton identifier and cursor position for the double click.

Reimplemented in spk::GameEngineWidget, spk::IconButton, and spk::PushButton.

◆ _onMouseMotionEvent()

void spk::Widget::_onMouseMotionEvent ( spk::MouseMotionEvent & p_event)
protectedvirtual

Mouse motion handler for derived widgets.

Parameters
p_eventCursor position delta and absolute coordinates.

Reimplemented in spk::GameEngineWidget, spk::IconButton, spk::PushButton, spk::Slider, and spk::TextEdit.

◆ _onMousePressEvent()

void spk::Widget::_onMousePressEvent ( spk::MousePressEvent & p_event)
protectedvirtual

Mouse button press handler for derived widgets.

Parameters
p_eventButton identifier and cursor position for the press.

Reimplemented in spk::GameEngineWidget, spk::IconButton, spk::PushButton, spk::Slider, and spk::TextEdit.

◆ _onMouseReleaseEvent()

void spk::Widget::_onMouseReleaseEvent ( spk::MouseReleaseEvent & p_event)
protectedvirtual

Mouse button release handler for derived widgets.

Parameters
p_eventButton identifier and cursor position for the release.

Reimplemented in spk::GameEngineWidget, spk::IconButton, spk::PushButton, spk::Slider, and spk::TextEdit.

◆ _onMouseWheelEvent()

void spk::Widget::_onMouseWheelEvent ( spk::MouseWheelEvent & p_event)
protectedvirtual

Mouse wheel handler for derived widgets.

Parameters
p_eventScrolling delta and cursor position.

Reimplemented in spk::GameEngineWidget, spk::ScrolableArea< TContent >, and spk::ScrolableArea< ListContent >.

◆ _onMoveEvent()

void spk::Widget::_onMoveEvent ( spk::MoveEvent & p_event)
protectedvirtual

Window move handler hook.

Parameters
p_eventNew window position.

Reimplemented in spk::GameEngineWidget.

◆ _onPaintEvent()

void spk::Widget::_onPaintEvent ( spk::PaintEvent & p_event)
protectedvirtual

Paint event hook for derived widgets.

Parameters
p_eventEvent describing the paint request region and target.

Reimplemented in spk::Frame, spk::GameEngineWidget, spk::IconButton, spk::PromptPanel, spk::PushButton, spk::Slider, spk::TextEdit, and spk::TextLabel.

◆ _onQuitEvent()

void spk::Widget::_onQuitEvent ( spk::QuitEvent & p_event)
protectedvirtual

Quit event handler hook.

Parameters
p_eventEvent signifying shutdown.

Reimplemented in spk::GameEngineWidget.

◆ _onResizeEvent()

void spk::Widget::_onResizeEvent ( spk::ResizeEvent & p_event)
protectedvirtual

Resize handling hook.

Parameters
p_eventNew viewport dimensions.

Reimplemented in spk::GameEngineWidget.

◆ _onUpdateEvent()

void spk::Widget::_onUpdateEvent ( spk::UpdateEvent & p_event)
protectedvirtual

Frame update handler hook.

Parameters
p_eventEvent emitted each frame for logic updates.

Reimplemented in spk::ColorPicker, spk::DynamicTextLabel, and spk::GameEngineWidget.

Here is the caller graph for this function:

◆ addChild()

void spk::Widget::addChild ( Widget * p_child)
overridevirtual

Adds a child widget and sorts the hierarchy by layer.

Parameters
p_childChild widget to insert.

Reimplemented from spk::InherenceObject< Widget >.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fbo()

const spk::OpenGL::FrameBufferObject & spk::Widget::fbo ( ) const

Alias for frameBufferObject().

Returns
Frame buffer object bound to the widget.
See also
frameBufferObject
Here is the call graph for this function:

◆ focusedWidget()

Widget * spk::Widget::focusedWidget ( FocusType p_focusType)
static

Retrieves the widget currently owning a focus type.

Parameters
p_focusTypeFocus lane to inspect.
Returns
Widget owning the focus, or nullptr when none.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ frameBufferObject()

const spk::OpenGL::FrameBufferObject & spk::Widget::frameBufferObject ( ) const

Returns the frame buffer object used for widget rendering.

Returns
Frame buffer object bound to the widget.
See also
fbo
Here is the caller graph for this function:

◆ geometry()

const spk::Extend2D & spk::Widget::geometry ( ) const

Returns the current widget geometry.

Returns
Widget geometry in parent coordinates.
Here is the caller graph for this function:

◆ hasFocus()

bool spk::Widget::hasFocus ( FocusType p_focusType) const

Checks if this widget currently owns a focus type.

Parameters
p_focusTypeFocus lane to test.
Returns
true when this widget owns the focus.
Here is the caller graph for this function:

◆ layer()

const float & spk::Widget::layer ( ) const

Current rendering layer of the widget.

Returns
Layer value used for ordering.
Here is the caller graph for this function:

◆ name()

const std::wstring & spk::Widget::name ( ) const

Retrieves the widget name.

Returns
Reference to the internal name string.
Here is the caller graph for this function:

◆ releaseFocus()

void spk::Widget::releaseFocus ( FocusType p_focusType)

Releases a previously acquired focus type.

Parameters
p_focusTypeFocus lane to free.
Exceptions
std::runtime_errorWhen the widget does not own the focus.
Here is the caller graph for this function:

◆ setGeometry()

void spk::Widget::setGeometry ( const spk::Extend2D & p_geometry)
overridevirtual

Requests a specific viewport and scissor region for the widget.

Parameters
p_geometryDesired view region in parent coordinates.
Note
Updates internal ViewRegion immediately; view update callbacks are deferred to the render thread.

Implements spk::ResizableElement.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLayer()

void spk::Widget::setLayer ( const float & p_newLayer)

Updates the widget layer and propagates relative offsets to children.

Parameters
p_newLayerNew layer value to apply.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setName()

void spk::Widget::setName ( const std::wstring & p_name)

Sets the widget name.

Parameters
p_nameNew label for the widget.

◆ takeFocus()

void spk::Widget::takeFocus ( FocusType p_focusType)

Grants this widget ownership of the requested focus type.

Parameters
p_focusTypeFocus lane to occupy.
Here is the caller graph for this function:

◆ viewRegion()

const spk::OpenGL::ViewRegion & spk::Widget::viewRegion ( ) const

Accesses the computed view region.

Returns
Current OpenGL view region used for rendering.

The documentation for this class was generated from the following files:
  • includes/structure/widget/spk_widget.hpp
  • srcs/structure/widget/spk_widget.cpp