Move clay helper functions out of main.c
This commit is contained in:
parent
e2106d8445
commit
2ded3602a1
3 changed files with 20 additions and 22 deletions
24
main.c
24
main.c
|
@ -24,24 +24,6 @@ typedef struct app_state {
|
||||||
ecs_world_t *world;
|
ecs_world_t *world;
|
||||||
} AppState;
|
} AppState;
|
||||||
|
|
||||||
SDL_Surface *sample_image;
|
|
||||||
|
|
||||||
static inline Clay_Dimensions SDL_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
|
|
||||||
TTF_Font **fonts = userData;
|
|
||||||
TTF_Font *font = fonts[config->fontId];
|
|
||||||
int width, height;
|
|
||||||
|
|
||||||
if (!TTF_GetStringSize(font, text.chars, text.length, &width, &height)) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to measure text: %s", SDL_GetError());
|
|
||||||
}
|
|
||||||
|
|
||||||
return (Clay_Dimensions) { (float) width, (float) height };
|
|
||||||
}
|
|
||||||
|
|
||||||
void HandleClayErrors(Clay_ErrorData errorData) {
|
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Clay Error: %s", errorData.errorText.chars);
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
|
@ -100,8 +82,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||||
|
|
||||||
state->rendererData.fonts[FONT_ID] = font;
|
state->rendererData.fonts[FONT_ID] = font;
|
||||||
|
|
||||||
sample_image = IMG_Load("resources/sample.png");
|
|
||||||
|
|
||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = (Clay_Arena) {
|
Clay_Arena clayMemory = (Clay_Arena) {
|
||||||
.memory = SDL_malloc(totalMemorySize),
|
.memory = SDL_malloc(totalMemorySize),
|
||||||
|
@ -110,8 +90,8 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) {
|
||||||
|
|
||||||
int width, height;
|
int width, height;
|
||||||
SDL_GetWindowSize(state->window, &width, &height);
|
SDL_GetWindowSize(state->window, &width, &height);
|
||||||
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float) width, (float) height }, (Clay_ErrorHandler) { HandleClayErrors });
|
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float) width, (float) height }, (Clay_ErrorHandler) { SDL_Clay_HandleErrors });
|
||||||
Clay_SetMeasureTextFunction(SDL_MeasureText, state->rendererData.fonts);
|
Clay_SetMeasureTextFunction(SDL_Clay_MeasureText, state->rendererData.fonts);
|
||||||
|
|
||||||
state->demoData = ClayVideoDemo_Initialize();
|
state->demoData = ClayVideoDemo_Initialize();
|
||||||
|
|
||||||
|
|
4
vendor/clay/clay_renderer_SDL3.c
vendored
4
vendor/clay/clay_renderer_SDL3.c
vendored
|
@ -1,5 +1,9 @@
|
||||||
#include "clay_renderer_SDL3.h"
|
#include "clay_renderer_SDL3.h"
|
||||||
|
|
||||||
|
void SDL_Clay_HandleErrors(Clay_ErrorData errorData) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Clay Error: %s", errorData.errorText.chars);
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Clay_RenderCommandArray *rcommands) {
|
void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Clay_RenderCommandArray *rcommands) {
|
||||||
for (size_t i = 0; i < rcommands->length; i++) {
|
for (size_t i = 0; i < rcommands->length; i++) {
|
||||||
Clay_RenderCommand *rcmd = Clay_RenderCommandArray_Get(rcommands, i);
|
Clay_RenderCommand *rcmd = Clay_RenderCommandArray_Get(rcommands, i);
|
||||||
|
|
14
vendor/clay/clay_renderer_SDL3.h
vendored
14
vendor/clay/clay_renderer_SDL3.h
vendored
|
@ -14,6 +14,20 @@ typedef struct {
|
||||||
TTF_Font **fonts;
|
TTF_Font **fonts;
|
||||||
} Clay_SDL3RendererData;
|
} Clay_SDL3RendererData;
|
||||||
|
|
||||||
|
static inline Clay_Dimensions SDL_Clay_MeasureText(Clay_StringSlice text, Clay_TextElementConfig *config, void *userData) {
|
||||||
|
TTF_Font **fonts = userData;
|
||||||
|
TTF_Font *font = fonts[config->fontId];
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
if (!TTF_GetStringSize(font, text.chars, text.length, &width, &height)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to measure text: %s", SDL_GetError());
|
||||||
|
}
|
||||||
|
|
||||||
|
return (Clay_Dimensions) { (float) width, (float) height };
|
||||||
|
}
|
||||||
|
|
||||||
|
void SDL_Clay_HandleErrors(Clay_ErrorData errorData);
|
||||||
|
|
||||||
void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Clay_RenderCommandArray *rcommands);
|
void SDL_Clay_RenderClayCommands(Clay_SDL3RendererData *rendererData, Clay_RenderCommandArray *rcommands);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue