Skip to content

Dynamic Text

TechnologicalTurtle edited this page Jul 19, 2026 · 8 revisions

Dynamic Text

DynamicText class is used to quickly render text on screen.

Initialization

// load font
DT_TextureAtlas roboto("roboto.ttf");

// create the text         font  | position
LibGui::DynamicText MyText(roboto, {0, 0});
// set text value
MyText.text = "Hello world!";

// you can add some parameters
//                         window  | font  | pos   | text color| back color
LibGui::DynamicText MyText(MyWindow, roboto, {0, 0}, Color::Red, Color::Blue);

Usage

After initialization, use Render() in a loop to render.

Methods

int RenderChar(char character, Vec2 add_pos)

Used to render single character, character. add_pos is literally added to MyText.pos.
Returns width of character image.

void Render()

Renders whole text.

Vec2 GetFinalSize()

Returns final size of DynamicText (final size -> minimum size of rectangle that would cover whole field + backgroundAddSize).

bool Rect_OnMouseEnter(...)

Returns if mouse cursor is on this dynamic text, ignore anchor parameter, as it's override of RectangleInput::Rect_OnMouseEnter.

int GetTouchedCharIndex()

If Rect_OnMouseEnter() then it should return mouue is on, else returns -1.

Vec2 GetPositionOnIndex(int character_index, bool left_side)

If left_side is true returns position of lower left corner of character on character_index,
else it ________________ returns position of lower right corner of character on character_index.

Properties

Type Name Description
DT_TextureAtlas* atlas Font of this text.
Vec2i pos Position of upper left corner of object.
float fontSize Multiplies with size of font.
Vec2i textFieldSize Size of smallest rectangle to cover rendered text.
Vec2 backgroundAddSize Added with textFieldSize determines background size.
Vec2 minSize Minimum background size. Set any axis to -1 to have no minimum size
Vec2 maxSize Maximum background size. Set any axis to -1 to have no maximum size
Color textColor Text color
Color backColor Background color

Limitations

To not go insane, I implemented rendering of only 256 characters (not all are printable, so actually little bit less).

DT_TextureAtlas

DynamicText_TextureAtlas handles font loading and storing. I used this name because there was older implementation of text rendering (which used Font class), that rendered into an image that was later displayed. It obviously had more cons than pros, so I removed it.

Clone this wiki locally