[Core] Implement Error Handler / Callback (#105)

This commit is contained in:
Nic Barker 2024-12-26 19:58:59 +13:00 committed by GitHub
parent 6a9b723dcc
commit 04694b0da2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 368 additions and 231 deletions

View file

@ -109,6 +109,10 @@ void Layout() {
}
}
void HandleClayErrors(Clay_ErrorData errorData) {
printf("%s", errorData.errorText.chars);
}
int main(void) {
// First we set up our cairo surface.
// In this example we will use the PDF backend,
@ -131,11 +135,11 @@ int main(void) {
Clay_Cairo_Initialize(cr);
uint64_t totalMemorySize = Clay_MinMemorySize();
Clay_Arena clayMemory = (Clay_Arena) { .label = CLAY_STRING("Clay Memory Arena"), .memory = malloc(totalMemorySize), .capacity = totalMemorySize };
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
Clay_SetMeasureTextFunction(Clay_Cairo_MeasureText);
// We initialize Clay with the same size
Clay_Initialize(clayMemory, (Clay_Dimensions) { width, height });
Clay_Initialize(clayMemory, (Clay_Dimensions) { width, height }, (Clay_ErrorHandler) { HandleClayErrors });
Clay_BeginLayout();