CRM64Pro GDK v0.18.0
A free cross-platform game development kit built on top of SDL 3.0
Loading...
Searching...
No Matches
CRM64Pro::WidgetTextEdit

TextEdit widget for editable text input. More...

Detailed Description

TextEdit widget for editable text input.

Supports text selection, clipboard shortcuts, undo/redo, scrolling, single-line mode and multiline mode. Text rendering depends on the active bitmap Font module.

Inheritance diagram for CRM64Pro::WidgetTextEdit:

Public Member Functions

bool info (Sint32 iMode=0) override
 Request TextEdit widget information.
Sint32 setSize (Sint32 iWidth, Sint32 iHeight) override
 Set the text edit size.
bool setMargin (Sint32 iTop, Sint32 iRight, Sint32 iBottom, Sint32 iLeft) override
 Set text-edit content margins.
bool setText (const string &sText)
 Set the text content.
bool getText (string &sText) const
 Get the text content.
Sint32 getCursorLine () const
 Get the current cursor line.
Sint32 setScroll (Sint32 iUnits, bool *bChanged=nullptr)
 Modify the text-edit scroll.
bool getScroll (Sint32 *iUnits) const
 Get the current text-edit scroll.
bool getVisibleItems (Sint32 *iUnits) const
 Get the visible text-edit area.
Sint32 setFont (Sint32 idFont, eWidgetState eWS=WS_DEFAULT) override
 Set the text-edit font.
Sint32 setMultiline (bool bEnable=true)
 Enable or disable multiline editing.
bool isMultiline () const
 Check whether multiline editing is enabled.
Sint32 setReadOnly (bool bEnable=true)
 Enable or disable read-only mode.
bool isReadOnly () const
 Check whether read-only mode is enabled.
Sint32 appendText (const string &sText)
 Append text to the current stream/cursor position.
Sint32 getLineCount () const
 Get the total number of lines.
string getLine (Sint32 iLineIndex) const
 Get a specific line of text.
Sint32 appendLine (const string &sText)
 Add a new line at the bottom.
Sint32 setLine (Sint32 iLineIndex, const string &sText)
 Replace a specific line.
Sint32 insertLine (Sint32 iLineIndex, const string &sText)
 Insert a new line at a specific index.
Sint32 removeLine (Sint32 iLineIndex)
 Remove a specific line.
Public Member Functions inherited from CRM64Pro::Widget
const string & getName () const
 Get the widget name.
Sint32 getID () const
 Get the widget ID.
eWidgetType getType () const
 Get the widget type.
bool disable ()
 Disable a widget.
bool enable ()
 Enable a widget.
bool show ()
 Show a widget.
bool hide ()
 Hide a widget.
eGeneralStatus status () const
 Get the widget status.
bool setFeatures (eWidgetFeature eWF, bool bEnable)
 Set widget feature flags.
eWidgetFeature getFeatures () const
 Get widget feature flags.
Sint32 getWidth () const
 Get the widget width.
Sint32 getHeight () const
 Get the widget height.
Sint32 setPosition (const Position &rPosX=Position(PH_CENTER), const Position &rPosY=Position(PH_CENTER))
 Set the position.
const PositiongetPositionX () const
 Get the widget X position.
const PositiongetPositionY () const
 Get the widget Y position.
bool getMargin (Sint32 *iTop, Sint32 *iRight, Sint32 *iBottom, Sint32 *iLeft)
 Get the margins.
bool setAlphaMod (Uint8 iAlpha)
 Set alpha modulation used for rendering this widget.
Uint8 getAlphaMod () const
 Get alpha modulation used for rendering this widget.
eWidgetState getState () const
 Get the widget state.
Sint32 getFont (eWidgetState eWS=WS_NORMAL) const
 Get the font.
Sint32 setBorderWidth (Sint32 iWidth, eWidgetState eWS=WS_DEFAULT)
 Set the border width.
Sint32 getBorderWidth (eWidgetState eWS=WS_NORMAL) const
 Get the border width.
Sint32 setBorderCorner (Sint32 iRad, eWidgetState eWS=WS_DEFAULT)
 Set the border corner radius.
Sint32 getBorderCorner (eWidgetState eWS=WS_NORMAL) const
 Get the border corner radius.
Sint32 setBorderColor (Uint8 iR, Uint8 iG, Uint8 iB, Uint8 iA, eWidgetState eWS=WS_DEFAULT)
 Set the border color.
Sint32 getBorderColor (Uint8 *iR, Uint8 *iG, Uint8 *iB, Uint8 *iA, eWidgetState eWS=WS_NORMAL) const
 Get the effective border color.
Sint32 setBackgroundColor (Uint8 iR, Uint8 iG, Uint8 iB, eWidgetState eWS=WS_DEFAULT)
 Set the background color.
Sint32 getBackgroundColor (Uint8 *iR, Uint8 *iG, Uint8 *iB, eWidgetState eWS=WS_NORMAL) const
 Get the effective background color.
Sint32 setSelectionColor (Uint8 iR, Uint8 iG, Uint8 iB, Uint8 iA, eWidgetState eWS=WS_DEFAULT)
 Set the selection highlight color.
Sint32 getSelectionColor (Uint8 *iR, Uint8 *iG, Uint8 *iB, Uint8 *iA, eWidgetState eWS=WS_NORMAL) const
 Get the effective selection highlight color.
Sint32 resetSkin (eWidgetState eWS=WS_DEFAULT)
 Clear custom skin overrides and custom background resources.
Uint32 getSkinOverrideMask (eWidgetState eWS=WS_NORMAL) const
 Get the custom skin override mask for one state.
Sint32 clearBackground (eWidgetState eWS=WS_DEFAULT)
 Clear custom background resources for one state.
Sint32 setBackgroundImage (const string &sCDCFile, const string &sName, eWidgetState eWS=WS_NORMAL)
 Set the background image.
Sint32 setBackgroundImage (Sint32 idCDC, const string &sName, eWidgetState eWS=WS_NORMAL)
 Set the background image.
Sint32 setBackgroundImage (Sint32 idImage, eWidgetState eWS=WS_NORMAL)
 Set the background image.
Sint32 getBackgroundImage (eWidgetState eWS=WS_NORMAL) const
 Get the background image.
Sint32 setBackgroundSprite (const string &sCDCFile, const string &sName, eWidgetState eWS=WS_DEFAULT, Sint32 iAnim=0)
 Set the background sprite.
Sint32 setBackgroundSprite (Sint32 idCDC, const string &sName, eWidgetState eWS=WS_DEFAULT, Sint32 iAnim=0)
 Set the background sprite.
Sint32 setBackgroundSprite (Sint32 idSprite, eWidgetState eWS=WS_DEFAULT, Sint32 iAnim=0)
 Set the background sprite.
Sint32 getBackgroundSprite (eWidgetState eWS=WS_NORMAL, Sint32 *iAnim=nullptr) const
 Get the background sprite.
bool setOnAction (function< void(Widget &)> fnCallback)
 Set a callback fired when the widget triggers an action.
bool setOnHoverEnter (function< void(Widget &)> fnCallback)
 Set a callback fired when the widget starts being hovered.
bool setOnHoverExit (function< void(Widget &)> fnCallback)
 Set a callback fired when mouse hover exits the widget.
bool setOnPressed (function< void(Widget &)> fnCallback)
 Set a callback fired when the widget is pressed.
bool setOnFocusLost (function< void(Widget &)> fnCallback)
 Set a callback fired when the widget loses focus.
bool setOnValueCommitted (function< void(Widget &)> fnCallback)
 Set a callback fired when an edit widget commits a changed value.
bool setOnSelectionChanged (function< void(Widget &)> fnCallback)
 Set a callback fired when a selection widget changes selection.
bool setOnValueChanged (function< void(Widget &)> fnCallback)
 Set a callback fired when a live value widget changes value.
bool setOnToggled (function< void(Widget &)> fnCallback)
 Set a callback fired when a toggle widget changes state.
Sint32 setTooltip (const string &sText)
 Set the tooltip text.
const string & getTooltip () const
 Get the tooltip text.
Sint32 setTooltipTTL (Sint32 iMS)
 Set the tooltip auto-hide time.
Sint32 getTooltipTTL () const
 Get the tooltip auto-hide time.
Sint32 setTooltipFollowCursor (bool bEnable=true)
 Set whether the tooltip follows the cursor.
bool isTooltipFollowingCursor () const
 Check whether the tooltip follows the cursor.
bool setTooltipBackgroundColor (Uint8 iR, Uint8 iG, Uint8 iB, Uint8 iA)
 Set the widget-local tooltip background color override.
bool getTooltipBackgroundColor (Uint8 *iR, Uint8 *iG, Uint8 *iB, Uint8 *iA) const
 Get the effective tooltip background color.
bool setTooltipBorderColor (Uint8 iR, Uint8 iG, Uint8 iB, Uint8 iA)
 Set the widget-local tooltip border color override.
bool getTooltipBorderColor (Uint8 *iR, Uint8 *iG, Uint8 *iB, Uint8 *iA) const
 Get the effective tooltip border color.
Sint32 setTooltipFontName (const string &sFontName)
 Set the widget-local tooltip font name override.
Sint32 setTooltipFont (Sint32 idFont)
 Set the widget-local runtime tooltip font id override.
Sint32 getTooltipFont () const
 Get the effective tooltip font id.
Uint32 getTooltipOverrideMask () const
 Get the widget-local tooltip style override mask.
Sint32 resetTooltipStyle ()
 Reset widget-local tooltip style overrides.

Member Function Documentation

◆ info()

bool CRM64Pro::WidgetTextEdit::info ( Sint32 iMode = 0)
overridevirtual

Request TextEdit widget information.

Writes information to the default log.

Parameters
iModecurrently forwarded to the common widget info path.
Returns
true on success, or false on failure.

Reimplemented from CRM64Pro::Widget.

◆ setSize()

Sint32 CRM64Pro::WidgetTextEdit::setSize ( Sint32 iWidth,
Sint32 iHeight )
overridevirtual

Set the text edit size.

Ensures the widget is tall enough to display at least one full line of text using the current font and vertical margins.

Parameters
iWidthWidget width in pixels.
iHeightRequested widget height in pixels.
Returns
0 on success, or a negative error code on failure.

Reimplemented from CRM64Pro::Widget.

◆ setMargin()

bool CRM64Pro::WidgetTextEdit::setMargin ( Sint32 iTop,
Sint32 iRight,
Sint32 iBottom,
Sint32 iLeft )
overridevirtual

Set text-edit content margins.

Parameters
iTopTop margin.
iRightRight margin.
iBottomBottom margin.
iLeftLeft margin.
Returns
true on success, or false on failure.

Reimplemented from CRM64Pro::Widget.

◆ setText()

bool CRM64Pro::WidgetTextEdit::setText ( const string & sText)

Set the text content.

Replaces the current content with a single line containing sText. Clicking inside the widget gives it keyboard focus. While focused, the widget supports mouse selection plus: Ctrl/Cmd+A select all, Ctrl/Cmd+C copy selection, Ctrl/Cmd+X cut selection, Ctrl/Cmd+V paste, Ctrl/Cmd+Z undo, and Ctrl/Cmd+Y redo. Press Esc or click another widget to release focus.

Parameters
sTextNew text content.
Returns
true on success, or false on failure.

◆ getText()

bool CRM64Pro::WidgetTextEdit::getText ( string & sText) const

Get the text content.

Parameters
sTextString reference receiving the text.
Returns
true on success, or false on failure.

◆ getCursorLine()

Sint32 CRM64Pro::WidgetTextEdit::getCursorLine ( ) const

Get the current cursor line.

Returns
Current line [1,n], or 0 when no active line is selected.

◆ setScroll()

Sint32 CRM64Pro::WidgetTextEdit::setScroll ( Sint32 iUnits,
bool * bChanged = nullptr )

Modify the text-edit scroll.

Parameters
iUnitsunits to move scroll vertically. Negative moves up, 0 no change, positive moves down.
bChangedoptional pointer filled with true when the scroll position changed, or false otherwise.
Returns
0 on success, or a negative error code on failure.

◆ getScroll()

bool CRM64Pro::WidgetTextEdit::getScroll ( Sint32 * iUnits) const

Get the current text-edit scroll.

Parameters
iUnitspointer to receive vertical scroll units, or nullptr to skip.
Returns
true on success, or false on failure.

◆ getVisibleItems()

bool CRM64Pro::WidgetTextEdit::getVisibleItems ( Sint32 * iUnits) const

Get the visible text-edit area.

Parameters
iUnitspointer to receive visible line count, or nullptr to skip.
Returns
true on success, or false on failure.

◆ setFont()

Sint32 CRM64Pro::WidgetTextEdit::setFont ( Sint32 idFont,
eWidgetState eWS = WS_DEFAULT )
overridevirtual

Set the text-edit font.

Parameters
idFontFont id.
eWSWidget state. Only WS_DEFAULT is used by TextEdit.
Returns
0 on success, or a negative error code on failure.

Reimplemented from CRM64Pro::Widget.

◆ setMultiline()

Sint32 CRM64Pro::WidgetTextEdit::setMultiline ( bool bEnable = true)

Enable or disable multiline editing.

When disabled, the control behaves as a single-line editor. Existing text is kept on the first line.

Parameters
bEnabletrue to allow multiple lines, false for single-line mode.
Returns
0 on success, or a negative error code on failure.

◆ isMultiline()

bool CRM64Pro::WidgetTextEdit::isMultiline ( ) const

Check whether multiline editing is enabled.

Returns
true when multiline editing is enabled, or false when this widget is single-line only.

◆ setReadOnly()

Sint32 CRM64Pro::WidgetTextEdit::setReadOnly ( bool bEnable = true)

Enable or disable read-only mode.

In read-only mode the widget keeps selection, focus and copy support, but text modifications are blocked.

Parameters
bEnabletrue to enable read-only mode, false to allow editing.
Returns
0 on success, or a negative error code on failure.

◆ isReadOnly()

bool CRM64Pro::WidgetTextEdit::isReadOnly ( ) const

Check whether read-only mode is enabled.

Returns
true when read-only mode is enabled, or false otherwise.

◆ appendText()

Sint32 CRM64Pro::WidgetTextEdit::appendText ( const string & sText)

Append text to the current stream/cursor position.

Parameters
sTextText string to append.
Returns
0 on success, or a negative error code on failure.
Note
For Single-line: Appends to the end of the text.
For Multi-line: Appends to the end of the current cursor line (or last line if no cursor logic).

◆ getLineCount()

Sint32 CRM64Pro::WidgetTextEdit::getLineCount ( ) const

Get the total number of lines.

Returns
The total number of lines.
Note
For Single-line: Always returns 1.

◆ getLine()

string CRM64Pro::WidgetTextEdit::getLine ( Sint32 iLineIndex) const

Get a specific line of text.

Parameters
iLineIndexLine index [1,n] to retrieve.
Returns
The text string of the specified line, or empty string on failure/invalid index.
Note
For Single-line: Ignores iLineIndex and returns the current text.

◆ appendLine()

Sint32 CRM64Pro::WidgetTextEdit::appendLine ( const string & sText)

Add a new line at the bottom.

Parameters
sTextText string for the new line.
Returns
The index of the new line (1-based), or a negative error code.
Note
For Single-line: Returns -1 (Operation not supported).
For Multi-line: Pushes a new line to the end of the list.

◆ setLine()

Sint32 CRM64Pro::WidgetTextEdit::setLine ( Sint32 iLineIndex,
const string & sText )

Replace a specific line.

Parameters
iLineIndexLine index [1,n] to replace.
sTextNew text string.
Returns
0 on success, or a negative error code.
Note
For Single-line: Ignores iLineIndex and replaces current text.

◆ insertLine()

Sint32 CRM64Pro::WidgetTextEdit::insertLine ( Sint32 iLineIndex,
const string & sText )

Insert a new line at a specific index.

Parameters
iLineIndexLine index [1,n] where the new line will be inserted.
sTextText string for the new line.
Returns
0 on success, or a negative error code.
Note
For Single-line: Returns -1 (Operation not supported).
For Multi-line: Inserts at specified index, shifting subsequent lines down.

◆ removeLine()

Sint32 CRM64Pro::WidgetTextEdit::removeLine ( Sint32 iLineIndex)

Remove a specific line.

Parameters
iLineIndexLine index [1,n] to remove.
Returns
0 on success, or a negative error code.
Note
For Single-line: Clears the text (sets to empty string).
For Multi-line: Removes the line. If it was the last line, resets it to empty.