RADLib
RADical C++ application framework
RADUi::TextEditorModel Class Reference

Multi-line text editor model with derived display text and scrolling helpers. More...

#include <RADWidgets.h>

+ Inheritance diagram for RADUi::TextEditorModel:
+ Collaboration diagram for RADUi::TextEditorModel:

Public Member Functions

const std::string & text () const
 Returns raw editor text. More...
 
void setText (std::string text)
 Replaces raw editor text. More...
 
void setEditorText (std::string text)
 Replaces editor text after decoding visible whitespace when needed. More...
 
size_t insertText (size_t byteOffset, std::string_view text)
 Inserts text at a byte offset and returns the new offset. More...
 
const std::string & displayText () const
 Returns text transformed for display settings. More...
 
const std::string & lineNumberText () const
 Returns newline-separated line-number text. More...
 
size_t lineCount () const
 Returns current line count. More...
 
bool showLineNumbers () const
 Returns true when line numbers should be displayed. More...
 
void setShowLineNumbers (bool show)
 Enables or disables line-number display. More...
 
bool showWhitespace () const
 Returns true when whitespace markers should be shown. More...
 
void setShowWhitespace (bool show)
 Enables or disables visible whitespace display. More...
 
double scrollY () const
 Returns model scroll offset in logical pixels. More...
 
void setScrollY (double scrollY)
 Sets model scroll offset in logical pixels. More...
 
double slintViewportY () const
 Returns Slint-compatible viewport offset. More...
 
void setSlintViewportY (double viewportY)
 Sets scroll offset from a Slint viewport position. More...
 
void setViewportHeight (double viewportHeight)
 Sets the visible viewport height used by ensureLineVisible(). More...
 
double viewportHeight () const
 Returns the configured viewport height. More...
 
void ensureLineVisible (size_t line, double lineHeight=19.0, double padding=12.0)
 Scrolls as needed so zero-based line is visible. More...
 
void scrollToLastLine (double lineHeight=19.0, double padding=12.0)
 Scrolls so the last line is visible. More...
 
- Public Member Functions inherited from RADCore::RADObject
 RADObject ()
 Creates a RADObject bound to the current thread. More...
 
virtual ~RADObject ()
 Disconnects tracked event links and releases lifetime token. More...
 
void registerLink (const ConnectionRecord &record)
 Registers a connection for cleanup when this object is destroyed. More...
 
std::thread::id threadId () const
 Returns the thread id this object is currently associated with. More...
 
EventLoopassociatedEventLoop () const
 Returns the associated event loop, if any. More...
 
ThreadAffinity threadAffinity () const
 Returns both thread id and associated loop atomically. More...
 
std::weak_ptr< void > lifetimeToken () const
 Returns a weak token used to drop queued callbacks after destruction. More...
 
void moveToThread (std::thread::id tId, EventLoop *loop=nullptr)
 Moves the object's affinity to tId and optional loop. More...
 

Static Public Member Functions

static std::string makeWhitespaceVisible (std::string_view text)
 Converts tabs/spaces/newlines into visible display symbols. More...
 
static std::string decodeVisibleWhitespace (std::string_view text)
 Converts visible whitespace display symbols back to raw text. More...
 
static size_t countLines (std::string_view text)
 Counts text lines, treating empty text as one line. More...
 
static std::string makeLineNumberText (size_t lineCount)
 Builds newline-separated line-number text for lineCount lines. More...
 

Public Attributes

RADCore::Event< void() > changed
 Raised when editor text, display settings, or scroll state changes. More...
 

Detailed Description

Multi-line text editor model with derived display text and scrolling helpers.

Member Function Documentation

◆ countLines()

static size_t RADUi::TextEditorModel::countLines ( std::string_view  text)
static

Counts text lines, treating empty text as one line.

◆ decodeVisibleWhitespace()

static std::string RADUi::TextEditorModel::decodeVisibleWhitespace ( std::string_view  text)
static

Converts visible whitespace display symbols back to raw text.

◆ displayText()

const std::string& RADUi::TextEditorModel::displayText ( ) const

Returns text transformed for display settings.

◆ ensureLineVisible()

void RADUi::TextEditorModel::ensureLineVisible ( size_t  line,
double  lineHeight = 19.0,
double  padding = 12.0 
)

Scrolls as needed so zero-based line is visible.

◆ insertText()

size_t RADUi::TextEditorModel::insertText ( size_t  byteOffset,
std::string_view  text 
)

Inserts text at a byte offset and returns the new offset.

◆ lineCount()

size_t RADUi::TextEditorModel::lineCount ( ) const

Returns current line count.

◆ lineNumberText()

const std::string& RADUi::TextEditorModel::lineNumberText ( ) const

Returns newline-separated line-number text.

◆ makeLineNumberText()

static std::string RADUi::TextEditorModel::makeLineNumberText ( size_t  lineCount)
static

Builds newline-separated line-number text for lineCount lines.

◆ makeWhitespaceVisible()

static std::string RADUi::TextEditorModel::makeWhitespaceVisible ( std::string_view  text)
static

Converts tabs/spaces/newlines into visible display symbols.

◆ scrollToLastLine()

void RADUi::TextEditorModel::scrollToLastLine ( double  lineHeight = 19.0,
double  padding = 12.0 
)

Scrolls so the last line is visible.

◆ scrollY()

double RADUi::TextEditorModel::scrollY ( ) const

Returns model scroll offset in logical pixels.

◆ setEditorText()

void RADUi::TextEditorModel::setEditorText ( std::string  text)

Replaces editor text after decoding visible whitespace when needed.

◆ setScrollY()

void RADUi::TextEditorModel::setScrollY ( double  scrollY)

Sets model scroll offset in logical pixels.

◆ setShowLineNumbers()

void RADUi::TextEditorModel::setShowLineNumbers ( bool  show)

Enables or disables line-number display.

◆ setShowWhitespace()

void RADUi::TextEditorModel::setShowWhitespace ( bool  show)

Enables or disables visible whitespace display.

◆ setSlintViewportY()

void RADUi::TextEditorModel::setSlintViewportY ( double  viewportY)

Sets scroll offset from a Slint viewport position.

◆ setText()

void RADUi::TextEditorModel::setText ( std::string  text)

Replaces raw editor text.

◆ setViewportHeight()

void RADUi::TextEditorModel::setViewportHeight ( double  viewportHeight)

Sets the visible viewport height used by ensureLineVisible().

◆ showLineNumbers()

bool RADUi::TextEditorModel::showLineNumbers ( ) const

Returns true when line numbers should be displayed.

◆ showWhitespace()

bool RADUi::TextEditorModel::showWhitespace ( ) const

Returns true when whitespace markers should be shown.

◆ slintViewportY()

double RADUi::TextEditorModel::slintViewportY ( ) const

Returns Slint-compatible viewport offset.

◆ text()

const std::string& RADUi::TextEditorModel::text ( ) const

Returns raw editor text.

◆ viewportHeight()

double RADUi::TextEditorModel::viewportHeight ( ) const

Returns the configured viewport height.

Member Data Documentation

◆ changed

RADCore::Event<void () > RADUi::TextEditorModel::changed

Raised when editor text, display settings, or scroll state changes.


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