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

Widget that renders a text region over a nine-slice background. More...

#include <spk_text_label.hpp>

Inheritance diagram for spk::TextLabel:
Inheritance graph
Collaboration diagram for spk::TextLabel:
Collaboration graph

Public Member Functions

 TextLabel (const std::wstring &p_name, spk::Widget *p_parent)
 Creates a text label widget.
void setCornerSize (const spk::Vector2UInt &p_cornerSize)
 Sets the corner size for the nine-slice background.
const spk::Vector2UIntcornerSize () const
 Returns the current corner size for the background.
void setTexture (const spk::SpriteSheet *p_spriteSheet)
 Assigns the sprite sheet used for the background.
const spk::SpriteSheettexture () const
 Returns the sprite sheet used for the background.
void setFont (spk::Font *p_font)
 Sets the font used for the label text.
spk::Fontfont () const
 Returns the font used for the label text.
void setFontSize (const spk::Font::Size &p_size)
 Sets the font size for the label text.
const spk::Font::SizefontSize () const
 Returns the current font size for the label text.
void setColors (const spk::Color &p_glyphColor, const spk::Color &p_outlineColor)
 Sets the glyph and outline colors for the label text.
const spk::ColorglyphColor () const
 Returns the current glyph color.
const spk::ColoroutlineColor () const
 Returns the current outline color.
void setText (const std::wstring &p_text)
 Updates the label text.
const std::wstring & text () const
 Returns the current label text.
void setAlignment (HorizontalAlignment p_horizontalAlignment, VerticalAlignment p_verticalAlignment)
 Sets the horizontal and vertical alignment for the text.
HorizontalAlignment horizontalAlignment () const
 Returns the current horizontal alignment.
VerticalAlignment verticalAlignment () const
 Returns the current vertical alignment.
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 _onGeometryChange () override
 Updates background and text geometry when the widget size changes.
void _onPaintEvent (spk::PaintEvent &p_event) override
 Paints the background and text regions.
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 _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.

Additional Inherited Members

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.
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

Widget that renders a text region over a nine-slice background.

See also
spk::NineSliceBackground, spk::TextRegion, spk::Widget
spk::TextLabel label{L"Title", parent};
label.setText(L"Hello World");
Widget * parent() const
Definition spk_inherence_object.hpp:85
Widget that renders a text region over a nine-slice background.
Definition spk_text_label.hpp:20
void setText(const std::wstring &p_text)
Updates the label text.
Definition spk_text_label.cpp:77

Constructor & Destructor Documentation

◆ TextLabel()

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

Creates a text label widget.

Parameters
p_nameWidget name used for hierarchy identification.
p_parentParent widget; can be nullptr for a root widget.
Here is the call graph for this function:
Here is the caller graph for this function:

Member Function Documentation

◆ _onGeometryChange()

void spk::TextLabel::_onGeometryChange ( )
overrideprotectedvirtual

Updates background and text geometry when the widget size changes.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onPaintEvent()

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

Paints the background and text regions.

Parameters
p_eventPaint event describing the render target.

Reimplemented from spk::Widget.

◆ cornerSize()

const spk::Vector2UInt & spk::TextLabel::cornerSize ( ) const

Returns the current corner size for the background.

Returns
Corner size used by the nine-slice background.

◆ font()

spk::Font * spk::TextLabel::font ( ) const

Returns the font used for the label text.

Returns
Pointer to the current font.

◆ fontSize()

const spk::Font::Size & spk::TextLabel::fontSize ( ) const

Returns the current font size for the label text.

Returns
Font size configuration.

◆ glyphColor()

const spk::Color & spk::TextLabel::glyphColor ( ) const

Returns the current glyph color.

Returns
Color used to draw glyphs.

◆ horizontalAlignment()

HorizontalAlignment spk::TextLabel::horizontalAlignment ( ) const

Returns the current horizontal alignment.

Returns
Horizontal alignment value.

◆ outlineColor()

const spk::Color & spk::TextLabel::outlineColor ( ) const

Returns the current outline color.

Returns
Color used to draw glyph outlines.

◆ setAlignment()

void spk::TextLabel::setAlignment ( HorizontalAlignment p_horizontalAlignment,
VerticalAlignment p_verticalAlignment )

Sets the horizontal and vertical alignment for the text.

Parameters
p_horizontalAlignmentHorizontal alignment value.
p_verticalAlignmentVertical alignment value.

◆ setColors()

void spk::TextLabel::setColors ( const spk::Color & p_glyphColor,
const spk::Color & p_outlineColor )

Sets the glyph and outline colors for the label text.

Parameters
p_glyphColorColor used to render glyphs.
p_outlineColorColor used to render outlines.

◆ setCornerSize()

void spk::TextLabel::setCornerSize ( const spk::Vector2UInt & p_cornerSize)

Sets the corner size for the nine-slice background.

Parameters
p_cornerSizeSize of the fixed corners in pixels.
Here is the call graph for this function:

◆ setFont()

void spk::TextLabel::setFont ( spk::Font * p_font)

Sets the font used for the label text.

Parameters
p_fontFont instance used to render glyphs.
Here is the call graph for this function:

◆ setFontSize()

void spk::TextLabel::setFontSize ( const spk::Font::Size & p_size)

Sets the font size for the label text.

Parameters
p_sizeGlyph and outline sizes to apply.
Here is the call graph for this function:

◆ setText()

void spk::TextLabel::setText ( const std::wstring & p_text)

Updates the label text.

Parameters
p_textUTF-16 text to display.
Here is the call graph for this function:

◆ setTexture()

void spk::TextLabel::setTexture ( const spk::SpriteSheet * p_spriteSheet)

Assigns the sprite sheet used for the background.

Parameters
p_spriteSheetSprite sheet containing background sprites.

◆ text()

const std::wstring & spk::TextLabel::text ( ) const

Returns the current label text.

Returns
Reference to the stored text.

◆ texture()

const spk::SpriteSheet * spk::TextLabel::texture ( ) const

Returns the sprite sheet used for the background.

Returns
Pointer to the assigned sprite sheet.

◆ verticalAlignment()

VerticalAlignment spk::TextLabel::verticalAlignment ( ) const

Returns the current vertical alignment.

Returns
Vertical alignment value.

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