Aegis2D
Modular C++26 2D game engine for networked games
Loading...
Searching...
No Matches
aegis2d::render::TextSize Struct Reference

Size of the HUD and menu text chosen by the player, from 100% to 200%. More...

#include <aegis2d/render/text_layout.hpp>

Public Member Functions

float scale () const noexcept
 The factor, brought into [smallest, largest]; not-a-number gives 1.
 
int percent () const noexcept
 The size as shown in a menu.
 
void larger () noexcept
 One step larger, up to largest.
 
void smaller () noexcept
 One step smaller, down to smallest.
 
TextStyle apply (TextStyle style) const noexcept
 Applies the size to a text style.
 
void save (core::Config &settings, std::string_view path) const
 Writes the size into the player's settings.
 
void load (const core::Config &settings, std::string_view path)
 Reads the size written by save().
 

Public Attributes

float factor = 1.0F
 Factor applied to every text: 1 for 100%, 1.5 for 150%.
 

Static Public Attributes

static constexpr float smallest = 1.0F
 Smallest scale, the size the game was designed for.
 
static constexpr float largest = 2.0F
 Largest scale.
 
static constexpr float step = 0.25F
 Change of one larger() or smaller() step.
 

Detailed Description

Size of the HUD and menu text chosen by the player, from 100% to 200%.

Players with low vision, or far from the screen, make the text larger. The game multiplies the scale of each text by scale() (see apply()), and lays its texts out with flow_layout() and BitmapFont::wrap(), so larger text moves to the next row or line instead of overlapping.

Member Function Documentation

◆ apply()

TextStyle aegis2d::render::TextSize::apply ( TextStyle  style) const
noexcept

Applies the size to a text style.

Parameters
styleStyle designed at 100%.
Returns
style with its scale multiplied by scale().

◆ larger()

void aegis2d::render::TextSize::larger ( )
noexcept

One step larger, up to largest.

◆ load()

void aegis2d::render::TextSize::load ( const core::Config &  settings,
std::string_view  path 
)

Reads the size written by save().

A missing value keeps the size; one that is not a number is logged and kept; values out of range are clamped.

Parameters
settingsSettings read with platform::read_settings() or core::Config.
pathDotted path given to save().

◆ percent()

int aegis2d::render::TextSize::percent ( ) const
noexcept

The size as shown in a menu.

Returns
scale() in percent, such as 150.

◆ save()

void aegis2d::render::TextSize::save ( core::Config &  settings,
std::string_view  path 
) const

Writes the size into the player's settings.

Parameters
settingsSettings to update, then saved with core::Config::save().
pathDotted path of the value, such as "accessibility.text_size".

◆ scale()

float aegis2d::render::TextSize::scale ( ) const
noexcept

The factor, brought into [smallest, largest]; not-a-number gives 1.

Returns
The scale to multiply text by.

◆ smaller()

void aegis2d::render::TextSize::smaller ( )
noexcept

One step smaller, down to smallest.

Member Data Documentation

◆ factor

float aegis2d::render::TextSize::factor = 1.0F

Factor applied to every text: 1 for 100%, 1.5 for 150%.

◆ largest

constexpr float aegis2d::render::TextSize::largest = 2.0F
staticconstexpr

Largest scale.

◆ smallest

constexpr float aegis2d::render::TextSize::smallest = 1.0F
staticconstexpr

Smallest scale, the size the game was designed for.

◆ step

constexpr float aegis2d::render::TextSize::step = 0.25F
staticconstexpr

Change of one larger() or smaller() step.


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