3#include <pu/sdl2/sdl2_Types.hpp>
4#include <pu/ui/ui_Types.hpp>
11 using FontFaceDisposingFunction =
void(*)(
void*);
17 FontFaceDisposingFunction dispose_fn;
19 FontFace(
void *buf,
const size_t buf_size, FontFaceDisposingFunction disp_fn,
const u32 font_sz,
void *font_class_ptr) : font(
nullptr), ptr(buf), ptr_sz(buf_size), dispose_fn(disp_fn) {
20 this->font = TTF_OpenFontRW(SDL_RWFromMem(
this->ptr,
this->ptr_sz), 1, font_sz);
21 if(
this->font !=
nullptr) {
28 inline bool IsSourceValid() {
30 return (
this->ptr !=
nullptr) && (
this->ptr_sz > 0);
34 if(
this->font !=
nullptr) {
42 if(
this->IsSourceValid()) {
43 (
this->dispose_fn)(
this->ptr);
54 inline sdl2::Font TryGetFirstFont() {
55 if(!
this->font_faces.empty()) {
56 return this->font_faces.begin()->second->font;
68 return index != InvalidFontFaceIndex;
79 return this->font_size;
Definition ttf_Font.hpp:9
void Unload(const i32 font_idx)
static void EmptyFontFaceDisposingFunction(void *)
Definition ttf_Font.hpp:65
i32 LoadFromMemory(void *ptr, const size_t size, FontFaceDisposingFunction disp_fn)
sdl2::Texture RenderText(const std::string &str, const ui::Color clr)
u32 GetFontSize()
Definition ttf_Font.hpp:78
static constexpr i32 InvalidFontFaceIndex
Definition ttf_Font.hpp:62
static constexpr bool IsValidFontFaceIndex(const i32 index)
Definition ttf_Font.hpp:67
Font(const u32 font_sz)
Definition ttf_Font.hpp:71
static constexpr u32 DefaultFontSize
Definition ttf_Font.hpp:63
i32 LoadFromFile(const std::string &path)
sdl2::Font FindValidFontFor(const Uint16 ch)
std::pair< u32, u32 > GetTextDimensions(const std::string &str)
Definition sdl2_Types.hpp:10
Definition ttf_Font.hpp:7
DECLSPEC void SDLCALL TTF_CloseFont(TTF_Font *font)
void TTF_CppWrap_SetCppPtrRef(TTF_Font *font, void *cpp_ptr_ref)
Definition ui_Types.hpp:44