mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-03 00:48:03 +00:00
Compare commits
6 Commits
8512295b19
...
f5aa388f9f
Author | SHA1 | Date | |
---|---|---|---|
|
f5aa388f9f | ||
|
9e7595b873 | ||
|
32d1a31dfe | ||
|
b2b50724e2 | ||
|
15fbf81e84 | ||
|
78e7ee8888 |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
build/
|
||||
.DS_Store
|
||||
.idea/
|
||||
node_modules/
|
||||
|
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_CreateArenaWithCapacityAndMemory](#clay_createarenawithcapacityandmemory)
|
||||
- [Clay_SetMeasureTextFunction](#clay_setmeasuretextfunction)
|
||||
- [Clay_ResetMeasureTextCache](#clau_resetmeasuretextcache)
|
||||
- [Clay_SetMaxElementCount](clay_setmaxelementcount)
|
||||
- [Clay_SetMaxMeasureTextCacheWordCount](#clay_setmaxmeasuretextcachewordcount)
|
||||
- [Clay_Initialize](#clay_initialize)
|
||||
- [Clay_GetCurrentContext](#clay_getcurrentcontext)
|
||||
- [Clay_SetCurrentContext](#clay_setcurrentcontext)
|
||||
- [Clay_SetLayoutDimensions](#clay_setlayoutdimensions)
|
||||
- [Clay_SetPointerState](#clay_setpointerstate)
|
||||
- [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
|
||||
|
||||
`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)
|
||||
|
||||
---
|
||||
|
||||
### Clay_SetCurrentContext
|
||||
|
||||
`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).
|
||||
|
||||
---
|
||||
|
||||
### Clay_GetCurrentContext
|
||||
|
||||
`Clay_Context* Clay_GetCurrentContext()`
|
||||
|
34
clay.h
34
clay.h
@ -524,6 +524,7 @@ int32_t Clay_GetMaxElementCount(void);
|
||||
void Clay_SetMaxElementCount(int32_t maxElementCount);
|
||||
int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
||||
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
||||
void Clay_ResetMeasureTextCache(void);
|
||||
|
||||
// Internal API functions required by macros
|
||||
void Clay__OpenElement(void);
|
||||
@ -1390,7 +1391,7 @@ struct Clay_Context {
|
||||
bool externalScrollHandlingEnabled;
|
||||
uint32_t debugSelectedElementId;
|
||||
uint32_t generation;
|
||||
uint64_t arenaResetOffset;
|
||||
uintptr_t arenaResetOffset;
|
||||
Clay_Arena internalArena;
|
||||
// Layout Elements / Render Commands
|
||||
Clay_LayoutElementArray layoutElements;
|
||||
@ -2102,6 +2103,9 @@ void Clay__CompressChildrenAlongAxis(bool xAxis, float totalSizeToDistribute, Cl
|
||||
float targetSize = 0;
|
||||
for (int32_t i = 0; i < resizableContainerBuffer.length; ++i) {
|
||||
Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&context->layoutElements, Clay__int32_tArray_Get(&resizableContainerBuffer, i));
|
||||
if (!xAxis && Clay__ElementHasConfig(childElement, CLAY__ELEMENT_CONFIG_TYPE_IMAGE)) {
|
||||
continue;
|
||||
}
|
||||
float childSize = xAxis ? childElement->dimensions.width : childElement->dimensions.height;
|
||||
if ((childSize - largestSize) < 0.1 && (childSize - largestSize) > -0.1) {
|
||||
Clay__int32_tArray_Add(&largestContainers, Clay__int32_tArray_Get(&resizableContainerBuffer, i));
|
||||
@ -2471,9 +2475,9 @@ void Clay__CalculateFinalLayout() {
|
||||
while (sortMax > 0) { // todo dumb bubble sort
|
||||
for (int32_t i = 0; i < sortMax; ++i) {
|
||||
Clay__LayoutElementTreeRoot current = *Clay__LayoutElementTreeRootArray_Get(&context->layoutElementTreeRoots, i);
|
||||
Clay__LayoutElementTreeRoot *next = Clay__LayoutElementTreeRootArray_Get(&context->layoutElementTreeRoots, i + 1);
|
||||
if (next->zIndex < current.zIndex) {
|
||||
Clay__LayoutElementTreeRootArray_Set(&context->layoutElementTreeRoots, i, *next);
|
||||
Clay__LayoutElementTreeRoot next = *Clay__LayoutElementTreeRootArray_Get(&context->layoutElementTreeRoots, i + 1);
|
||||
if (next.zIndex < current.zIndex) {
|
||||
Clay__LayoutElementTreeRootArray_Set(&context->layoutElementTreeRoots, i, next);
|
||||
Clay__LayoutElementTreeRootArray_Set(&context->layoutElementTreeRoots, i + 1, current);
|
||||
}
|
||||
}
|
||||
@ -3222,16 +3226,19 @@ void Clay__RenderDebugView() {
|
||||
Clay_TextElementConfig *infoTitleConfig = CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE });
|
||||
Clay_ElementId scrollId = Clay__HashString(CLAY_STRING("Clay__DebugViewOuterScrollPane"), 0, 0);
|
||||
float scrollYOffset = 0;
|
||||
bool pointerInDebugView = context->pointerInfo.position.y < context->layoutDimensions.height - 300;
|
||||
for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) {
|
||||
Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&context->scrollContainerDatas, i);
|
||||
if (scrollContainerData->elementId == scrollId.id) {
|
||||
if (!context->externalScrollHandlingEnabled) {
|
||||
scrollYOffset = scrollContainerData->scrollPosition.y;
|
||||
} else {
|
||||
pointerInDebugView = context->pointerInfo.position.y + scrollContainerData->scrollPosition.y < context->layoutDimensions.height - 300;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
int32_t highlightedRow = context->pointerInfo.position.y < context->layoutDimensions.height - 300
|
||||
int32_t highlightedRow = pointerInDebugView
|
||||
? (int32_t)((context->pointerInfo.position.y - scrollYOffset) / (float)CLAY__DEBUGVIEW_ROW_HEIGHT) - 1
|
||||
: -1;
|
||||
if (context->pointerInfo.position.x < context->layoutDimensions.width - (float)Clay__debugViewWidth) {
|
||||
@ -3609,7 +3616,7 @@ uint32_t Clay_MinMemorySize(void) {
|
||||
.maxMeasureTextCacheWordCount = Clay__defaultMaxMeasureTextWordCacheCount,
|
||||
.internalArena = {
|
||||
.capacity = SIZE_MAX,
|
||||
.memory = (char*)&fakeContext,
|
||||
.memory = NULL,
|
||||
}
|
||||
};
|
||||
Clay_Context* currentContext = Clay_GetCurrentContext();
|
||||
@ -4035,6 +4042,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
|
||||
|
||||
/*
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user