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

Editable text field with validation and cursor handling. More...

#include <spk_text_edit.hpp>

Inheritance diagram for spk::TextEdit:
Inheritance graph
Collaboration diagram for spk::TextEdit:
Collaboration graph

Public Types

enum class  ValidationState { Valid , Invalid , Undefined }
 Validation state of the text content.
using ValidationStatus = spk::TaskResult<ValidationState>
 Validation status result type.
using ValidationCallback = std::function<ValidationStatus(const std::wstring &)>
 Validation callback signature.
using EditionContract = spk::ObservableValue<std::wstring>::Contract
 Edition contract type for text changes.
using EditionJob = spk::ObservableValue<std::wstring>::Job
 Edition job type for text changes.
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

 TextEdit (const std::wstring &p_name, spk::Widget *p_parent)
 Builds a text edit widget.
void setCornerSize (const spk::Vector2UInt &p_cornerSize)
 Sets background corner size.
const spk::Vector2UIntcornerSize () const
 Returns background corner size.
void setTexture (const spk::SpriteSheet *p_spriteSheet)
 Sets the background texture.
const spk::SpriteSheettexture () const
 Returns the background texture.
void setFont (spk::Font *p_font)
 Sets the font used for text rendering.
spk::Fontfont () const
 Returns the font used for text rendering.
void setFontSize (const spk::Font::Size &p_size)
 Sets the font size used for text rendering.
const spk::Font::SizefontSize () const
 Returns the font size used for text rendering.
void setColors (const spk::Color &p_glyphColor, const spk::Color &p_outlineColor)
 Sets glyph and outline colors.
const spk::ColorglyphColor () const
 Returns the glyph color.
const spk::ColoroutlineColor () const
 Returns the outline color.
void setPlaceholder (const std::wstring &p_placeholder)
 Sets the placeholder text.
const std::wstring & placeholder () const
 Returns the placeholder text.
void setValidationCallback (ValidationCallback p_callback)
 Sets the validation callback.
const ValidationCallbackvalidationCallback () const
 Returns the validation callback.
ValidationStatus checkTextValidity (const std::wstring &p_text) const
 Checks text validity with the current callback.
const std::wstring & text () const
 Returns the current text.
ValidationStatus setText (const std::wstring &p_text)
 Sets the text content.
EditionContract subscribeToEdition (const EditionJob &p_job)
 Subscribes to text edition notifications.
void setAlignment (HorizontalAlignment p_horizontalAlignment, VerticalAlignment p_verticalAlignment)
 Sets text alignment.
void placeCursor (size_t p_position)
 Places the cursor at a position.
void moveCursor (int p_delta)
 Moves the cursor by a delta.
size_t cursorPosition () const
 Returns the cursor position.
void clear ()
 Clears the text content.
void setObscured (bool p_obscured)
 Enables or disables obscured rendering.
bool obscured () const
 Returns whether text is obscured.
void setCursorBlinkDuration (const spk::Duration &p_duration)
 Sets the cursor blink duration.
const spk::DurationcursorBlinkDuration () const
 Returns the cursor blink duration.
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 layout when geometry changes.
void _onPaintEvent (spk::PaintEvent &p_event) override
 Paints the text edit visuals.
void _onMouseMotionEvent (spk::MouseMotionEvent &p_event) override
 Handles mouse motion events.
void _onMousePressEvent (spk::MousePressEvent &p_event) override
 Handles mouse press events.
void _onMouseReleaseEvent (spk::MouseReleaseEvent &p_event) override
 Handles mouse release events.
void _onGlyphEvent (spk::GlyphEvent &p_event) override
 Handles glyph input events.
void _onKeyPressEvent (spk::KeyPressEvent &p_event) override
 Handles key press events.
void _onFocusEvent (spk::FocusEvent &p_event) override
 Handles focus events.
Protected Member Functions inherited from spk::Widget
virtual void _onKeyReleaseEvent (spk::KeyReleaseEvent &p_event)
 Keyboard release handler for derived widgets.
virtual void _onMouseDoubleClickEvent (spk::MouseDoubleClickEvent &p_event)
 Mouse double click 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 _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

Editable text field with validation and cursor handling.

spk::TextEdit edit(L"Input", parent);
edit.setPlaceholder(L"Type...");
Widget * parent() const
Definition spk_inherence_object.hpp:85
Editable text field with validation and cursor handling.
Definition spk_text_edit.hpp:29

Constructor & Destructor Documentation

◆ TextEdit()

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

Builds a text edit widget.

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

Member Function Documentation

◆ _onFocusEvent()

void spk::TextEdit::_onFocusEvent ( spk::FocusEvent & p_event)
overrideprotectedvirtual

Handles focus events.

Parameters
p_eventFocus event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onGeometryChange()

void spk::TextEdit::_onGeometryChange ( )
overrideprotectedvirtual

Updates layout when geometry changes.

Reimplemented from spk::Widget.

◆ _onGlyphEvent()

void spk::TextEdit::_onGlyphEvent ( spk::GlyphEvent & p_event)
overrideprotectedvirtual

Handles glyph input events.

Parameters
p_eventGlyph event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onKeyPressEvent()

void spk::TextEdit::_onKeyPressEvent ( spk::KeyPressEvent & p_event)
overrideprotectedvirtual

Handles key press events.

Parameters
p_eventKey press event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ _onMouseMotionEvent()

void spk::TextEdit::_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::TextEdit::_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::TextEdit::_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::TextEdit::_onPaintEvent ( spk::PaintEvent & p_event)
overrideprotectedvirtual

Paints the text edit visuals.

Parameters
p_eventPaint event payload.

Reimplemented from spk::Widget.

Here is the call graph for this function:

◆ checkTextValidity()

TextEdit::ValidationStatus spk::TextEdit::checkTextValidity ( const std::wstring & p_text) const

Checks text validity with the current callback.

Parameters
p_textText to validate.
Returns
Validation status.

◆ cornerSize()

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

Returns background corner size.

Returns
Corner size in pixels.

◆ cursorBlinkDuration()

const spk::Duration & spk::TextEdit::cursorBlinkDuration ( ) const

Returns the cursor blink duration.

Returns
Blink duration.

◆ cursorPosition()

size_t spk::TextEdit::cursorPosition ( ) const

Returns the cursor position.

Returns
Cursor position.

◆ font()

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

Returns the font used for text rendering.

Returns
Font pointer.

◆ fontSize()

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

Returns the font size used for text rendering.

Returns
Font size.

◆ glyphColor()

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

Returns the glyph color.

Returns
Glyph color.

◆ moveCursor()

void spk::TextEdit::moveCursor ( int p_delta)

Moves the cursor by a delta.

Parameters
p_deltaDelta amount.
Here is the caller graph for this function:

◆ obscured()

bool spk::TextEdit::obscured ( ) const

Returns whether text is obscured.

Returns
true when obscured.

◆ outlineColor()

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

Returns the outline color.

Returns
Outline color.

◆ placeCursor()

void spk::TextEdit::placeCursor ( size_t p_position)

Places the cursor at a position.

Parameters
p_positionCursor position.
Here is the caller graph for this function:

◆ placeholder()

const std::wstring & spk::TextEdit::placeholder ( ) const

Returns the placeholder text.

Returns
Placeholder text.

◆ setAlignment()

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

Sets text alignment.

Parameters
p_horizontalAlignmentHorizontal alignment.
p_verticalAlignmentVertical alignment.

◆ setColors()

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

Sets glyph and outline colors.

Parameters
p_glyphColorGlyph color.
p_outlineColorOutline color.

◆ setCornerSize()

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

Sets background corner size.

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

◆ setCursorBlinkDuration()

void spk::TextEdit::setCursorBlinkDuration ( const spk::Duration & p_duration)

Sets the cursor blink duration.

Parameters
p_durationBlink duration.

◆ setFont()

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

Sets the font used for text rendering.

Parameters
p_fontFont pointer.
Here is the call graph for this function:

◆ setFontSize()

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

Sets the font size used for text rendering.

Parameters
p_sizeFont size.
Here is the call graph for this function:

◆ setObscured()

void spk::TextEdit::setObscured ( bool p_obscured)

Enables or disables obscured rendering.

Parameters
p_obscuredWhether to obscure text.
Here is the call graph for this function:

◆ setPlaceholder()

void spk::TextEdit::setPlaceholder ( const std::wstring & p_placeholder)

Sets the placeholder text.

Parameters
p_placeholderPlaceholder text.
Here is the call graph for this function:

◆ setText()

TextEdit::ValidationStatus spk::TextEdit::setText ( const std::wstring & p_text)

Sets the text content.

Parameters
p_textText string.
Returns
Validation status.
Here is the call graph for this function:

◆ setTexture()

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

Sets the background texture.

Parameters
p_spriteSheetSprite sheet pointer.

◆ setValidationCallback()

void spk::TextEdit::setValidationCallback ( ValidationCallback p_callback)

Sets the validation callback.

Parameters
p_callbackValidation callback.

◆ subscribeToEdition()

TextEdit::EditionContract spk::TextEdit::subscribeToEdition ( const EditionJob & p_job)

Subscribes to text edition notifications.

Parameters
p_jobCallback invoked on text changes.
Returns
Subscription contract.

◆ text()

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

Returns the current text.

Returns
Text string.

◆ texture()

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

Returns the background texture.

Returns
Sprite sheet pointer or nullptr.

◆ validationCallback()

const TextEdit::ValidationCallback & spk::TextEdit::validationCallback ( ) const

Returns the validation callback.

Returns
Validation callback.

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