5#ifndef MALENA_RICHTEXTRENDERER_H
6#define MALENA_RICHTEXTRENDERER_H
84 unsigned int defaultSize,
120 std::size_t selStart,
126 std::size_t charIndex,
128 float width = 2.f)
const;
141 [[nodiscard]]
const std::vector<RenderedLine>&
getLines()
const;
146 unsigned int _defaultSize;
150 float _maxWidth = 0.f;
151 std::vector<RenderedLine> _lines;
153 void buildSegments();
Pure data layer for rich text editing.
float getTotalHeight() const
sf::Vector2f charIndexToPosition(std::size_t index) const
void drawCursor(sf::RenderTarget &target, const sf::RenderStates &states, std::size_t charIndex, const sf::Color &color, float width=2.f) const
std::size_t charIndexAbove(std::size_t cursorIndex) const
std::size_t charIndexBelow(std::size_t cursorIndex) const
void draw(sf::RenderTarget &target, const sf::RenderStates &states) const
const std::vector< RenderedLine > & getLines() const
void setMaxWidth(float width)
Set max line width for wrapping. 0 = no wrap.
std::size_t lineIndexForChar(std::size_t charIndex) const
void reflow()
Reposition existing sf::Text objects to the current origin.
std::size_t positionToCharIndex(const sf::Vector2f &pos) const
void rebuild()
Rebuild sf::Text objects from the current buffer content.
void setOrigin(const sf::Vector2f &origin)
Set the top-left origin and reposition segments.
RichTextRenderer(const RichTextBuffer &buffer, const sf::Font &defaultFont, unsigned int defaultSize, sf::Color defaultColor)
void drawSelection(sf::RenderTarget &target, const sf::RenderStates &states, std::size_t selStart, std::size_t selEnd, const sf::Color &color) const
Vector2< float > Vector2f
One visual line of text made up of RenderedSegment objects.
float height
Total height including word-wrap rows.
std::vector< RenderedSegment > segments
float rowHeight
Single visual row height (for cursor/selection).
sf::Text sfText
SFML text object, positioned and styled.
sf::Vector2f position
Top-left position.
std::size_t bufEnd
Last char index in the buffer (exclusive).
std::size_t bufStart
First char index in the buffer (inclusive).
RenderedSegment(sf::Text &&text, std::size_t start, std::size_t end, sf::Vector2f pos)
A styled attribute range applied to a span of characters.