mirror of
https://github.com/nicbarker/clay.git
synced 2025-01-23 01:46:02 +00:00
Fix quick start in README to include error handler
This commit is contained in:
parent
ebeef93c34
commit
5f7176cdcc
20
README.md
20
README.md
@ -28,17 +28,31 @@ _An example GUI application built with clay_
|
|||||||
#include "clay.h"
|
#include "clay.h"
|
||||||
```
|
```
|
||||||
|
|
||||||
2. Ask clay for how much static memory it needs using [Clay_MinMemorySize()](#clay_minmemorysize), create an Arena for it to use with [Clay_CreateArenaWithCapacityAndMemory(size, void *memory)](#clay_createarenawithcapacityandmemory), and initialize it with [Clay_Initialize(arena, dimensions)](#clay_initialize).
|
2. Ask clay for how much static memory it needs using [Clay_MinMemorySize()](#clay_minmemorysize), create an Arena for it to use with [Clay_CreateArenaWithCapacityAndMemory(size, void *memory)](#clay_createarenawithcapacityandmemory).
|
||||||
|
|
||||||
```C
|
```C
|
||||||
// Note: malloc is only used here as an example, any allocator that provides
|
// Note: malloc is only used here as an example, any allocator that provides
|
||||||
// a pointer to addressable memory of at least totalMemorySize will work
|
// a pointer to addressable memory of at least totalMemorySize will work
|
||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
Clay_Arena arena = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
Clay_Initialize(arena, (Clay_Dimensions) { screenWidth, screenHeight });
|
|
||||||
```
|
```
|
||||||
|
|
||||||
3. Provide a `MeasureText(text, config)` function pointer with [Clay_SetMeasureTextFunction(function)](#clay_setmeasuretextfunction) so that clay can measure and wrap text.
|
3. Create an [ErrorHandler](#clay_errorhandler) for Clay to call when an internal error occurs, and initialize Clay with the Arena and handler by calling [Clay_Initialize(arena, dimensions, errorHandler)](#clay_initialize).
|
||||||
|
|
||||||
|
```C
|
||||||
|
void HandleClayErrors(Clay_ErrorData errorData) {
|
||||||
|
// See the Clay_ErrorData struct for more information
|
||||||
|
printf("%s", errorData.errorText.chars);
|
||||||
|
switch(errorData.errorType) {
|
||||||
|
// etc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// In your startup function
|
||||||
|
Clay_Initialize(arena, (Clay_Dimensions) { screenWidth, screenHeight }, (Clay_ErrorHandler) { HandleClayErrors });
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Provide a `MeasureText(text, config)` function pointer with [Clay_SetMeasureTextFunction(function)](#clay_setmeasuretextfunction) so that clay can measure and wrap text.
|
||||||
|
|
||||||
```C
|
```C
|
||||||
// Example measure text function
|
// Example measure text function
|
||||||
|
Loading…
Reference in New Issue
Block a user