Class TextRenderer

#include <Geode/ui/TextRenderer.hpp>
classTextRenderer:publiccocos2d::CCObject{ ... }

Utility class for creating rich text content. Use to incrementally render strings, and push variables to modify the renderer’s state. Use begin to start rendering to a target and end to finish rendering.

Works for any type of label, although relies heavily on content sizes for labels and nodes.

Not too well-performant and the rendering is done linearly without so this is not suitable for dynamic content. For something like a static rich text -area though this can prove useful. Used in MDTextArea.

Examples0
Public static methods1
staticgeode::TextRenderer*create()

Create a TextRenderer

Return value
Created TextRenderer
Public member functions43
voidbegin(,,)

Initialize renderer

Parameters

target

Target node to render to. If nullptr, a new CCNode will be created.

pos

Position to render to

size

Size of the render area. Needed for text wrapping & alignment
cocos2d::CCNode*end(
boolfitToContent
,
geode::TextAlignmenthorizontalAlign
,)

Finish rendering and clean up renderer

Parameters

fitToContent

Resize the target's content size to match the rendered content

horizontalAlign

Horizontal alignment of the rendered text

verticalAlign

Vertical alignment of the rendered text
Return value
Target that was rendered onto
intrenderStringEx(,,
floatscale
,,
GLubyteopacity
,
intstyle
,
intdeco
,,
booladdToTarget
,
boolisButton
,
cocos2d::CCObject*buttonTarget
,)

Render a string with specific settings, bypassing current variable stacks.

Parameters

str

String to render

font

Font function to use

scale

Scale of label

color

Label color

opacity

Label opacity

style

Label style (TextStyle enum)

deco

Label decorations (TextDecoration enum)

caps

String capitalization

addToTarget

Whether to add the created label(s) onto the target

isButton

If the label should be created as an interactive linked button

buttonTarget

Target for the label if isButton is true, defaults to current renderer target

callback

Callback for the label if isButton is true
Return value
Vector of rendered labels. The label may be split on multiple lines if it exceeds bounds
intrenderString()

Render a string to target. Uses current variable stacks for styling and parameters

Parameters

str

String to render
Return value
Vector of rendered labels. The label may be split on multiple lines if it exceeds bounds
intrenderStringInteractive(,
cocos2d::CCObject*buttonTarget
,)

Render a string to target as a button. Note that the target should be a CCMenu for the button to do anything. Uses current variable stacks for styling and parameters

Parameters

str

String to render

buttonTarget

Target for the label if isButton is true, defaults to current renderer target

callback

Callback for the label if isButton is true
Return value
Vector of rendered labels. The label may be split on multiple lines if it exceeds bounds
cocos2d::CCNode*renderNode()

Render a node to the current target, use for adding images & other content in the middle of text

Parameters

node

Node to render
Return value
Rendered node
voidbreakLine()

Start next line

Parameters

y

Y offset amount from previous line. If 0, will dynamically figure out based on content size
voidpushBMFont()

Helper for pushing a CCLabelBMFont. Make sure the const char* outlives the renderer.

voidpushFont()
No description provided
voidpopFont()
No description provided
geode::TextRenderer::FontgetCurrentFont()const
No description provided
voidpushScale(
floatscale
)
No description provided
voidpopScale()
No description provided
floatgetCurrentScale()const
No description provided
voidpushStyleFlags(
intstyle
)
No description provided
voidpopStyleFlags()
No description provided
intgetCurrentStyle()const
No description provided
voidpushColor()
No description provided
voidpopColor()
No description provided
cocos2d::ccColor3BgetCurrentColor()const
No description provided
voidpushOpacity(
GLubyteopacity
)
No description provided
voidpopOpacity()
No description provided
GLubytegetCurrentOpacity()const
No description provided
voidpushDecoFlags(
intdeco
)
No description provided
voidpopDecoFlags()
No description provided
intgetCurrentDeco()const
No description provided
voidpushCaps()
No description provided
voidpopCaps()
No description provided
geode::TextCapitalizationgetCurrentCaps()const
No description provided
voidpushIndent(
floatindent
)
No description provided
voidpopIndent()
No description provided
floatgetCurrentIndent()const
No description provided
voidpushWrapOffset(
floatwrapOffset
)
No description provided
voidpopWrapOffset()
No description provided
floatgetCurrentWrapOffset()const
No description provided
voidpushVerticalAlign()
No description provided
voidpopVerticalAlign()
No description provided
geode::TextAlignmentgetCurrentVerticalAlign()const
No description provided
voidpushHorizontalAlign()
No description provided
voidpopHorizontalAlign()
No description provided
geode::TextAlignmentgetCurrentHorizontalAlign()const
No description provided
voidmoveCursor()
No description provided
cocos2d::CCPointgetCursorPos()
No description provided
Fields0
Protected member functions4
boolinit()
No description provided
geode::TextRenderer::LabeladdWrappers(,
boolisButton
,,)
No description provided
boolrender(,,)
No description provided
floatadjustLineAlignment()
No description provided
Protected fields18
;
No description provided
;
No description provided
;
No description provided
;
No description provided
intm_fontStack
;
No description provided
intm_scaleStack
;
No description provided
intm_styleStack
;
No description provided
intm_colorStack
;
No description provided
intm_opacityStack
;
No description provided
intm_decorationStack
;
No description provided
intm_capsStack
;
No description provided
intm_lastRendered
;
No description provided
intm_indentationStack
;
No description provided
intm_wrapOffsetStack
;
No description provided
intm_hAlignmentStack
;
No description provided
intm_vAlignmentStack
;
No description provided
intm_renderedLine
;
No description provided
cocos2d::CCNode*m_lastRenderedNode
;
No description provided