Sparkle 0.0.1
Loading...
Searching...
No Matches
spk_text_area.hpp
1#pragma once
2
3#include <cstdint>
4#include <string>
5
6#include "structure/graphics/spk_color.hpp"
7#include "structure/graphics/spk_sprite_sheet.hpp"
8#include "structure/math/spk_vector2.hpp"
9#include "structure/widget/components/spk_nine_slice_background.hpp"
10#include "structure/widget/components/spk_text_region.hpp"
11#include "structure/widget/spk_widget.hpp"
12
13namespace spk
14{
24 class TextArea : public spk::Widget
25 {
26 private:
27 spk::NineSliceBackground _background;
28 spk::TextRegion _textRegion;
29 std::wstring _text;
30 size_t _minimalWidth = 0;
31 size_t _currentWrapWidth = 0;
32
33 void _onGeometryChange() override;
34 void _onPaintEvent(spk::PaintEvent &p_event) override;
35
36 std::wstring _wrapText(uint32_t p_availableWidth) const;
37 spk::Vector2UInt _computeMinimalSize() const;
38
39 public:
45 TextArea(const std::wstring &p_name, spk::Widget *p_parent);
46
51 void setCornerSize(const spk::Vector2UInt &p_cornerSize);
56 const spk::Vector2UInt &cornerSize() const;
57
62 void setTexture(const spk::SpriteSheet *p_spriteSheet);
67 const spk::SpriteSheet *texture() const;
68
73 void setFont(spk::Font *p_font);
78 spk::Font *font() const;
79
84 void setFontSize(const spk::Font::Size &p_size);
89 const spk::Font::Size &fontSize() const;
90
96 void setColors(const spk::Color &p_glyphColor, const spk::Color &p_outlineColor);
101 const spk::Color &glyphColor() const;
106 const spk::Color &outlineColor() const;
107
112 void setText(const std::wstring &p_text);
117 const std::wstring &text() const;
118
123 void setMinimalWidth(size_t p_width);
128 size_t minimalWidth() const;
129
135 void setAlignment(spk::HorizontalAlignment p_horizontalAlignment, spk::VerticalAlignment p_verticalAlignment);
140 spk::HorizontalAlignment horizontalAlignment() const;
145 spk::VerticalAlignment verticalAlignment() const;
146 };
147}
Loads font data and provides cached bitmap atlases per size.
Definition spk_font.hpp:33
Renders a scalable nine-slice background using a sprite sheet.
Definition spk_nine_slice_background.hpp:25
Loads an image and exposes individual sprite regions.
Definition spk_sprite_sheet.hpp:21
void setColors(const spk::Color &p_glyphColor, const spk::Color &p_outlineColor)
Sets glyph and outline colors.
Definition spk_text_area.cpp:131
const spk::Font::Size & fontSize() const
Returns the font size used for text rendering.
Definition spk_text_area.cpp:126
void setAlignment(spk::HorizontalAlignment p_horizontalAlignment, spk::VerticalAlignment p_verticalAlignment)
Sets text alignment.
Definition spk_text_area.cpp:171
spk::VerticalAlignment verticalAlignment() const
Returns the vertical alignment.
Definition spk_text_area.cpp:182
size_t minimalWidth() const
Returns the minimal width for wrapping.
Definition spk_text_area.cpp:161
spk::Font * font() const
Returns the font used for text rendering.
Definition spk_text_area.cpp:114
TextArea(const std::wstring &p_name, spk::Widget *p_parent)
Builds a text area widget.
Definition spk_text_area.cpp:70
const spk::Color & glyphColor() const
Returns the glyph color.
Definition spk_text_area.cpp:136
spk::HorizontalAlignment horizontalAlignment() const
Returns the horizontal alignment.
Definition spk_text_area.cpp:177
const spk::Color & outlineColor() const
Returns the outline color.
Definition spk_text_area.cpp:141
void setText(const std::wstring &p_text)
Sets the text content.
Definition spk_text_area.cpp:146
void setMinimalWidth(size_t p_width)
Sets the minimal width for wrapping.
Definition spk_text_area.cpp:153
void setCornerSize(const spk::Vector2UInt &p_cornerSize)
Sets background corner size.
Definition spk_text_area.cpp:85
const spk::Vector2UInt & cornerSize() const
Returns background corner size.
Definition spk_text_area.cpp:92
const spk::SpriteSheet * texture() const
Returns the background texture.
Definition spk_text_area.cpp:102
void setFont(spk::Font *p_font)
Sets the font used for text rendering.
Definition spk_text_area.cpp:107
const std::wstring & text() const
Returns the text content.
Definition spk_text_area.cpp:166
void setFontSize(const spk::Font::Size &p_size)
Sets the font size used for text rendering.
Definition spk_text_area.cpp:119
void setTexture(const spk::SpriteSheet *p_spriteSheet)
Sets the background texture.
Definition spk_text_area.cpp:97
Renders formatted text within a geometry region.
Definition spk_text_region.hpp:24
Base class for interactive UI elements handling focus and events.
Definition spk_widget.hpp:52
virtual void _onGeometryChange()
Notifies derived widgets that the view region changed.
Definition spk_widget.cpp:292
RGBA color utility storing normalized floating components.
Definition spk_color.hpp:18
Defines glyph and outline sizes for a font bitmap.
Definition spk_font.hpp:40
Event emitted when a drawable region needs repainting.
Definition spk_paint_event.hpp:19