Loading...
Searching...
No Matches
ml::RichTextRenderer Class Reference

Rendering layer for RichTextBuffer. More...

#include <Malena/Graphics/Text/RichTextRenderer.h>

Public Member Functions

 RichTextRenderer (const RichTextBuffer &buffer, const sf::Font &defaultFont, unsigned int defaultSize, sf::Color defaultColor)
std::size_t charIndexAbove (std::size_t cursorIndex) const
std::size_t charIndexBelow (std::size_t cursorIndex) const
sf::Vector2f charIndexToPosition (std::size_t index) const
void draw (sf::RenderTarget &target, const sf::RenderStates &states) const
void drawCursor (sf::RenderTarget &target, const sf::RenderStates &states, std::size_t charIndex, const sf::Color &color, float width=2.f) const
void drawSelection (sf::RenderTarget &target, const sf::RenderStates &states, std::size_t selStart, std::size_t selEnd, const sf::Color &color) const
const std::vector< RenderedLine > & getLines () const
float getTotalHeight () const
std::size_t lineIndexForChar (std::size_t charIndex) const
std::size_t positionToCharIndex (const sf::Vector2f &pos) const
void rebuild ()
 Rebuild sf::Text objects from the current buffer content.
void reflow ()
 Reposition existing sf::Text objects to the current origin.
void setMaxWidth (float width)
 Set max line width for wrapping. 0 = no wrap.
void setOrigin (const sf::Vector2f &origin)
 Set the top-left origin and reposition segments.

Detailed Description

Rendering layer for RichTextBuffer.

Converts a RichTextBuffer into positioned sf::Text segments.

Two-phase design

  • rebuild() — recreates sf::Text objects from buffer content. Call when text or styling changes.
  • setOrigin() / reflow() — repositions existing sf::Text objects in place. Call when only scroll offset or field position changes. Never creates new sf::Text objects — safe to call every frame.
See also
RichTextBuffer, TextInput, TextArea

Definition at line 79 of file RichTextRenderer.h.

Constructor & Destructor Documentation

◆ RichTextRenderer()

ml::RichTextRenderer::RichTextRenderer ( const RichTextBuffer & buffer,
const sf::Font & defaultFont,
unsigned int defaultSize,
sf::Color defaultColor )

Member Function Documentation

◆ charIndexAbove()

std::size_t ml::RichTextRenderer::charIndexAbove ( std::size_t cursorIndex) const
nodiscard

◆ charIndexBelow()

std::size_t ml::RichTextRenderer::charIndexBelow ( std::size_t cursorIndex) const
nodiscard

◆ charIndexToPosition()

sf::Vector2f ml::RichTextRenderer::charIndexToPosition ( std::size_t index) const
nodiscard

◆ draw()

void ml::RichTextRenderer::draw ( sf::RenderTarget & target,
const sf::RenderStates & states ) const

◆ drawCursor()

void ml::RichTextRenderer::drawCursor ( sf::RenderTarget & target,
const sf::RenderStates & states,
std::size_t charIndex,
const sf::Color & color,
float width = 2.f ) const

◆ drawSelection()

void ml::RichTextRenderer::drawSelection ( sf::RenderTarget & target,
const sf::RenderStates & states,
std::size_t selStart,
std::size_t selEnd,
const sf::Color & color ) const

◆ getLines()

const std::vector< RenderedLine > & ml::RichTextRenderer::getLines ( ) const
nodiscard

◆ getTotalHeight()

float ml::RichTextRenderer::getTotalHeight ( ) const
nodiscard

◆ lineIndexForChar()

std::size_t ml::RichTextRenderer::lineIndexForChar ( std::size_t charIndex) const
nodiscard

◆ positionToCharIndex()

std::size_t ml::RichTextRenderer::positionToCharIndex ( const sf::Vector2f & pos) const
nodiscard

◆ rebuild()

void ml::RichTextRenderer::rebuild ( )

Rebuild sf::Text objects from the current buffer content.

Call when text or styling actually changes.

◆ reflow()

void ml::RichTextRenderer::reflow ( )

Reposition existing sf::Text objects to the current origin.

Never creates new objects — safe to call every frame.

◆ setMaxWidth()

void ml::RichTextRenderer::setMaxWidth ( float width)

Set max line width for wrapping. 0 = no wrap.

◆ setOrigin()

void ml::RichTextRenderer::setOrigin ( const sf::Vector2f & origin)

Set the top-left origin and reposition segments.

Calls reflow() — never recreates sf::Text objects. Safe to call every frame for scroll/position changes.


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