mirror of
https://github.com/nicbarker/clay.git
synced 2025-01-23 01:46:02 +00:00
Add a function to reset text measurement cache (#181)
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 14s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 14s
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 14s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 14s
This commit is contained in:
parent
3a4455aa83
commit
afba9f0de6
15
README.md
15
README.md
@ -173,9 +173,12 @@ For help starting out or to discuss clay, considering joining [the discord serve
|
|||||||
- [Clay_MinMemorySize](#clay_minmemorysize)
|
- [Clay_MinMemorySize](#clay_minmemorysize)
|
||||||
- [Clay_CreateArenaWithCapacityAndMemory](#clay_createarenawithcapacityandmemory)
|
- [Clay_CreateArenaWithCapacityAndMemory](#clay_createarenawithcapacityandmemory)
|
||||||
- [Clay_SetMeasureTextFunction](#clay_setmeasuretextfunction)
|
- [Clay_SetMeasureTextFunction](#clay_setmeasuretextfunction)
|
||||||
|
- [Clay_ResetMeasureTextCache](#clau_resetmeasuretextcache)
|
||||||
- [Clay_SetMaxElementCount](clay_setmaxelementcount)
|
- [Clay_SetMaxElementCount](clay_setmaxelementcount)
|
||||||
- [Clay_SetMaxMeasureTextCacheWordCount](#clay_setmaxmeasuretextcachewordcount)
|
- [Clay_SetMaxMeasureTextCacheWordCount](#clay_setmaxmeasuretextcachewordcount)
|
||||||
- [Clay_Initialize](#clay_initialize)
|
- [Clay_Initialize](#clay_initialize)
|
||||||
|
- [Clay_GetCurrentContext](#clay_getcurrentcontext)
|
||||||
|
- [Clay_SetCurrentContext](#clay_setcurrentcontext)
|
||||||
- [Clay_SetLayoutDimensions](#clay_setlayoutdimensions)
|
- [Clay_SetLayoutDimensions](#clay_setlayoutdimensions)
|
||||||
- [Clay_SetPointerState](#clay_setpointerstate)
|
- [Clay_SetPointerState](#clay_setpointerstate)
|
||||||
- [Clay_UpdateScrollContainers](#clay_updatescrollcontainers)
|
- [Clay_UpdateScrollContainers](#clay_updatescrollcontainers)
|
||||||
@ -575,6 +578,14 @@ Takes a pointer to a function that can be used to measure the `width, height` di
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
### Clay_ResetMeasureTextCache
|
||||||
|
|
||||||
|
`void Clay_ResetMeasureTextCache(void)`
|
||||||
|
|
||||||
|
Clay caches measurements from the provided MeasureTextFunction, and this will be sufficient for the majority of use-cases. However, if the measurements can depend on external factors that clay does not know about, like DPI changes, then the cached values may be incorrect. When one of these external factors changes, Clay_ResetMeasureTextCache can be called to force clay to recalculate all string measurements in the next frame.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Clay_SetMaxElementCount
|
### Clay_SetMaxElementCount
|
||||||
|
|
||||||
`void Clay_SetMaxElementCount(uint32_t maxElementCount)`
|
`void Clay_SetMaxElementCount(uint32_t maxElementCount)`
|
||||||
@ -603,12 +614,16 @@ Initializes the internal memory mapping, sets the internal dimensions for layout
|
|||||||
|
|
||||||
Reference: [Clay_Arena](#clay_createarenawithcapacityandmemory), [Clay_ErrorHandler](#clay_errorhandler), [Clay_SetCurrentContext](#clay_setcurrentcontext)
|
Reference: [Clay_Arena](#clay_createarenawithcapacityandmemory), [Clay_ErrorHandler](#clay_errorhandler), [Clay_SetCurrentContext](#clay_setcurrentcontext)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Clay_SetCurrentContext
|
### Clay_SetCurrentContext
|
||||||
|
|
||||||
`void Clay_SetCurrentContext(Clay_Context* context)`
|
`void Clay_SetCurrentContext(Clay_Context* context)`
|
||||||
|
|
||||||
Sets the context that subsequent clay commands will operate on. You can get this reference from [Clay_Initialize](#clay_initialize) or [Clay_GetCurrentContext](#clay_getcurrentcontext). See [Running more than one Clay instance](#running-more-than-one-clay-instance).
|
Sets the context that subsequent clay commands will operate on. You can get this reference from [Clay_Initialize](#clay_initialize) or [Clay_GetCurrentContext](#clay_getcurrentcontext). See [Running more than one Clay instance](#running-more-than-one-clay-instance).
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
### Clay_GetCurrentContext
|
### Clay_GetCurrentContext
|
||||||
|
|
||||||
`Clay_Context* Clay_GetCurrentContext()`
|
`Clay_Context* Clay_GetCurrentContext()`
|
||||||
|
16
clay.h
16
clay.h
@ -525,6 +525,7 @@ int32_t Clay_GetMaxElementCount(void);
|
|||||||
void Clay_SetMaxElementCount(int32_t maxElementCount);
|
void Clay_SetMaxElementCount(int32_t maxElementCount);
|
||||||
int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
||||||
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
||||||
|
void Clay_ResetMeasureTextCache(void);
|
||||||
|
|
||||||
// Internal API functions required by macros
|
// Internal API functions required by macros
|
||||||
void Clay__OpenElement(void);
|
void Clay__OpenElement(void);
|
||||||
@ -4051,6 +4052,21 @@ void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CLAY_WASM_EXPORT("Clay_ResetMeasureTextCache")
|
||||||
|
void Clay_ResetMeasureTextCache(void) {
|
||||||
|
Clay_Context* context = Clay_GetCurrentContext();
|
||||||
|
context->measureTextHashMapInternal.length = 0;
|
||||||
|
context->measureTextHashMapInternalFreeList.length = 0;
|
||||||
|
context->measureTextHashMap.length = 0;
|
||||||
|
context->measuredWords.length = 0;
|
||||||
|
context->measuredWordsFreeList.length = 0;
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < context->measureTextHashMap.capacity; ++i) {
|
||||||
|
context->measureTextHashMap.internalArray[i] = 0;
|
||||||
|
}
|
||||||
|
context->measureTextHashMapInternal.length = 1; // Reserve the 0 value to mean "no next element"
|
||||||
|
}
|
||||||
|
|
||||||
#endif // CLAY_IMPLEMENTATION
|
#endif // CLAY_IMPLEMENTATION
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user