Loading...
Searching...
No Matches
font_slots.h
Go to the documentation of this file.
1
18#pragma once
19#include <stdbool.h>
20#include <stdint.h>
21
26
36
40typedef struct
41{
42 void **handles;
43 uint8_t *states;
44 int count;
45} FontSlots;
46
53typedef void *(*FontSlotLoad)(uint32_t resource);
54
60typedef void (*FontSlotUnload)(void *handle);
61
70void font_slots_put(const FontSlots *slots, int id, void *handle, bool owned);
71
86bool font_slots_load(const FontSlots *slots, uint32_t *resources, int id, uint32_t resource,
87 FontSlotLoad load);
88
107bool font_slots_swap(const FontSlots *slots, uint32_t *resources, int id, uint32_t resource,
108 FontSlotLoad load, FontSlotUnload unload);
109
116void font_slots_unload_all(const FontSlots *slots, FontSlotUnload unload);
117
void font_slots_unload_all(const FontSlots *slots, FontSlotUnload unload)
Frees every font the app owns, each one once, and empties every slot.
Definition font_slots.c:121
void *(*) FontSlotLoad(uint32_t resource)
Loads a font from its resource.
Definition font_slots.h:53
void(*) FontSlotUnload(void *handle)
Frees a font the app loaded.
Definition font_slots.h:60
bool font_slots_swap(const FontSlots *slots, uint32_t *resources, int id, uint32_t resource, FontSlotLoad load, FontSlotUnload unload)
Swaps a slot's font for another resource, freeing the old one when nothing else holds it.
Definition font_slots.c:102
FontSlotState
What a slot holds and who frees it. Kept in a uint8_t a slot.
Definition font_slots.h:31
bool font_slots_load(const FontSlots *slots, uint32_t *resources, int id, uint32_t resource, FontSlotLoad load)
Loads a font into a slot and records the resource it came from.
Definition font_slots.c:35
void font_slots_put(const FontSlots *slots, int id, void *handle, bool owned)
Puts a font in a slot, overwriting whatever it held without freeing it.
Definition font_slots.c:24
@ FONT_SLOT_OWNED
A font the app loaded and registered itself, freed by the registry.
Definition font_slots.h:33
@ FONT_SLOT_UNOWNED
Empty, or a system font the firmware owns and the app never frees.
Definition font_slots.h:32
@ FONT_SLOT_LOADED
A font loaded from the resource the slot records, freed by the registry.
Definition font_slots.h:34
The registry's tables, one entry a slot in each.
Definition font_slots.h:41
uint8_t * states
A FontSlotState for each slot.
Definition font_slots.h:43
int count
How many slots both tables hold.
Definition font_slots.h:44
void ** handles
The font in each slot, NULL for an empty one.
Definition font_slots.h:42