Util
General utility functions.
Header: #include <asw/modules/util.h>
Namespace: asw::util
Functions
abort_on_error
[[noreturn]] void abort_on_error(const std::string& message);Abort the program and display an error message.
get_texture_size
asw::Vec2<float> get_texture_size(const asw::Texture& tex);Get the width and height of a texture as a Vec2<float>.
get_text_size
asw::Vec2<int> get_text_size(const asw::Font& font, std::string_view text);Get the rendered size of a string with the given font. Results are cached. When the cache is full, the least recently used sizes are removed.
get_font_height
int get_font_height(const asw::Font& font);Get the height of one line of text in a font, in pixels. Returns 0 if the font is not loaded.
open_url
bool open_url(const std::string& url);Open a web page in the player's browser, e.g. a login or store page. Web builds open it in a new tab. Returns true if the browser was asked to open it.
clear_text_size_cache
void clear_text_size_cache();Clear the cached text sizes. Call this when you unload fonts.
lerp
template <typename T>
T lerp(const T& a, const T& b, float t);Linearly interpolate between two values. The t parameter is clamped to 0.0 - 1.0.
| Parameter | Type | Description |
|---|---|---|
a | const T& | Start value |
b | const T& | End value |
t | float | Interpolation factor (0.0 - 1.0) |
Works with any type that supports +, -, and * with a float (e.g., float, Vec2<float>). Integer types are calculated in floating point, so a falling unsigned range does not wrap. The result is clamped to the range of the type.
Example
// Get texture dimensions
auto size = asw::util::get_texture_size(texture);
float width = size.x;
float height = size.y;
// Smooth interpolation
float smoothed = asw::util::lerp(current_value, target_value, 0.1f);
// Interpolate positions
asw::Vec2<float> pos = asw::util::lerp(start_pos, end_pos, progress);