XS Framework
A 3DS homebrew development framework.
 
Loading...
Searching...
No Matches
xs::text::Text Class Reference

Wrapper class for citro2d text rendering with support for custom and system fonts. More...

#include <text.hpp>

Public Member Functions

 Text (const std::string &content, Font *font)
 Constructs a Text object with a custom font.
 
 Text (const std::string &content)
 Constructs a Text object with the system font.
 
 ~Text ()
 Destructor that frees the text buffer.
 
void Draw (float x, float y, float z=0.0f, float scaleX=1.0f, float scaleY=1.0f)
 Draws text with basic parameters and left alignment.
 
void DrawWithColor (float x, float y, float z, float scaleX, float scaleY, u32 color)
 Draws text with a specified color and left alignment.
 
void DrawAligned (u32 flags, float x, float y, float z, float scaleX, float scaleY)
 Draws text with custom alignment flags.
 
void DrawWithColorAligned (u32 flags, float x, float y, float z, float scaleX, float scaleY, u32 color)
 Draws text with color and custom alignment.
 
void GetDimensions (float scaleX, float scaleY, float *outWidth, float *outHeight) const
 Gets the dimensions of the rendered text.
 
void SetContent (const std::string &newContent)
 Updates the text content and re-parses it.
 
 Text (const Text &)=delete
 Copy constructor (deleted).
 
Textoperator= (const Text &)=delete
 Copy assignment operator (deleted).
 

Detailed Description

Wrapper class for citro2d text rendering with support for custom and system fonts.

This class manages text buffers and provides convenient methods for drawing text with various options including colors, alignment, and scaling. It supports both custom fonts and the 3DS system font.

Constructor & Destructor Documentation

◆ Text() [1/3]

xs::text::Text::Text ( const std::string & content,
Font * font )

Constructs a Text object with a custom font.

Parameters
contentThe text string to render.
fontPointer to a Font object to use for rendering.

Creates a text buffer with 4096 glyph capacity and parses the provided content using the specified font. The text is automatically optimized for efficient rendering.

Note
The font pointer must remain valid for the lifetime of this Text object.
Here is the caller graph for this function:

◆ Text() [2/3]

xs::text::Text::Text ( const std::string & content)
explicit

Constructs a Text object with the system font.

Parameters
contentThe text string to render.

Creates a text buffer with 4096 glyph capacity and parses the provided content using the 3DS system font. The text is automatically optimized for efficient rendering.

Note
The default 3DS system font has a glyph height of 30px with the baseline at 25px.

◆ ~Text()

xs::text::Text::~Text ( )

Destructor that frees the text buffer.

Automatically releases the text buffer resources using C2D_TextBufDelete.

◆ Text() [3/3]

xs::text::Text::Text ( const Text & )
delete

Copy constructor (deleted).

Text objects cannot be copied to prevent issues with shared text buffers.

Here is the call graph for this function:

Member Function Documentation

◆ Draw()

void xs::text::Text::Draw ( float x,
float y,
float z = 0.0f,
float scaleX = 1.0f,
float scaleY = 1.0f )

Draws text with basic parameters and left alignment.

Parameters
xHorizontal position to draw the text.
yVertical position (top-left corner of text block).
zDepth value for z-ordering (default: 0.0f).
scaleXHorizontal scale factor (default: 1.0f, native font size).
scaleYVertical scale factor (default: 1.0f, native font size).

Renders the text at the specified position with left alignment. Use scale values > 1.0f to enlarge text, < 1.0f to shrink it.

◆ DrawAligned()

void xs::text::Text::DrawAligned ( u32 flags,
float x,
float y,
float z,
float scaleX,
float scaleY )

Draws text with custom alignment flags.

Parameters
flagsAlignment and rendering flags (e.g., C2D_AlignLeft, C2D_AlignRight, C2D_AlignCenter, C2D_AlignJustified, C2D_AtBaseline, C2D_WordWrap).
xHorizontal position to draw the text.
yVertical position. Interpretation depends on alignment flags.
zDepth value for z-ordering.
scaleXHorizontal scale factor.
scaleYVertical scale factor.

Provides full control over text alignment and rendering options:

  • C2D_AlignLeft: Align to the left (default)
  • C2D_AlignRight: Align to the right
  • C2D_AlignCenter: Center the text
  • C2D_AlignJustified: Justify the text
  • C2D_AtBaseline: Y coordinate matches the baseline instead of top
  • C2D_WordWrap: Enable word wrapping (requires additional width parameter)

Flags can be combined using the bitwise OR operator (|).

◆ DrawWithColor()

void xs::text::Text::DrawWithColor ( float x,
float y,
float z,
float scaleX,
float scaleY,
u32 color )

Draws text with a specified color and left alignment.

Parameters
xHorizontal position to draw the text.
yVertical position (top-left corner of text block).
zDepth value for z-ordering.
scaleXHorizontal scale factor.
scaleYVertical scale factor.
colorColor value in u32 RGBA8 format (0xRRGGBBAA).

Renders the text with the specified color. The color format uses 8 bits per channel (red, green, blue, alpha).

Note
Example colors: 0xFFFFFFFF (white), 0x000000FF (black), 0xFF0000FF (red), 0x00FF00FF (green), 0x0000FFFF (blue).

◆ DrawWithColorAligned()

void xs::text::Text::DrawWithColorAligned ( u32 flags,
float x,
float y,
float z,
float scaleX,
float scaleY,
u32 color )

Draws text with color and custom alignment.

Parameters
flagsAlignment and rendering flags (e.g., C2D_AlignLeft, C2D_AlignRight, C2D_AlignCenter, C2D_AlignJustified, C2D_AtBaseline, C2D_WordWrap).
xHorizontal position to draw the text.
yVertical position. Interpretation depends on alignment flags.
zDepth value for z-ordering.
scaleXHorizontal scale factor.
scaleYVertical scale factor.
colorColor value in u32 RGBA8 format (0xRRGGBBAA).

Combines color rendering with custom alignment options. See DrawAligned() for details on alignment flags and DrawWithColor() for color format.

Note
The C2D_WithColor flag is automatically added to the provided flags.

◆ GetDimensions()

void xs::text::Text::GetDimensions ( float scaleX,
float scaleY,
float * outWidth,
float * outHeight ) const

Gets the dimensions of the rendered text.

Parameters
scaleXHorizontal scale factor to calculate dimensions for.
scaleYVertical scale factor to calculate dimensions for.
outWidthPointer to store the calculated width (can be nullptr to skip).
outHeightPointer to store the calculated height (can be nullptr to skip).

Calculates the bounding box dimensions of the text when rendered with the specified scale factors. This is useful for layout calculations, centering text, or creating text boxes.

Note
Pass nullptr for outWidth or outHeight if you only need one dimension.

◆ operator=()

Text & xs::text::Text::operator= ( const Text & )
delete

Copy assignment operator (deleted).

Text objects cannot be copy-assigned to prevent issues with shared text buffers.

Here is the call graph for this function:

◆ SetContent()

void xs::text::Text::SetContent ( const std::string & newContent)

Updates the text content and re-parses it.

Parameters
newContentThe new text string to render.

Clears the existing text buffer, parses the new content, and optimizes it for rendering. This allows dynamic text updates without creating a new Text object.

Note
This operation clears and re-parses the entire text buffer, which may impact performance if called frequently. The same font (custom or system) used during construction will be used for the new content.

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