mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-21 05:38:04 +00:00
Compare commits
7 Commits
d83af4cbdc
...
7e6884565c
Author | SHA1 | Date | |
---|---|---|---|
|
7e6884565c | ||
|
b33ba4ff62 | ||
|
f88f0517f7 | ||
|
5391a259f3 | ||
|
fe2d44a888 | ||
|
06167b4f4b | ||
|
fbf8251996 |
12
README.md
12
README.md
@ -1787,7 +1787,8 @@ Note: when using the debug tools, their internal colors are represented as 0-255
|
|||||||
|
|
||||||
```C
|
```C
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int length;
|
bool isStaticallyAllocated;
|
||||||
|
int32_t length;
|
||||||
const char *chars;
|
const char *chars;
|
||||||
} Clay_String;
|
} Clay_String;
|
||||||
```
|
```
|
||||||
@ -1796,7 +1797,14 @@ typedef struct {
|
|||||||
|
|
||||||
**Fields**
|
**Fields**
|
||||||
|
|
||||||
**`.length`** - `int`
|
**`.isStaticallyAllocated`** - `bool`
|
||||||
|
|
||||||
|
Whether or not the string is statically allocated, or in other words, whether
|
||||||
|
or not it lives for the entire lifetime of the program.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**`.length`** - `int32_t`
|
||||||
|
|
||||||
The number of characters in the string, _not including an optional null terminator._
|
The number of characters in the string, _not including an optional null terminator._
|
||||||
|
|
||||||
|
22
clay.h
22
clay.h
@ -360,6 +360,8 @@ typedef CLAY_PACKED_ENUM {
|
|||||||
CLAY_TEXT_ALIGN_CENTER,
|
CLAY_TEXT_ALIGN_CENTER,
|
||||||
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
// Horizontally aligns wrapped lines of text to the right hand side of their bounding box.
|
||||||
CLAY_TEXT_ALIGN_RIGHT,
|
CLAY_TEXT_ALIGN_RIGHT,
|
||||||
|
// The boundingBox passed to the TEXT render command may be smaller than the measured text size. The renderer must then decide how to shorten the text to make it fit
|
||||||
|
CLAY_TEXT_ALIGN_SHRINK,
|
||||||
} Clay_TextAlignment;
|
} Clay_TextAlignment;
|
||||||
|
|
||||||
// Controls various functionality related to text elements.
|
// Controls various functionality related to text elements.
|
||||||
@ -1392,6 +1394,7 @@ uint64_t Clay__HashData(const uint8_t* data, size_t length) {
|
|||||||
Clay__SIMDARXMix(&v2, &v3);
|
Clay__SIMDARXMix(&v2, &v3);
|
||||||
v0 = _mm_add_epi64(v0, v2);
|
v0 = _mm_add_epi64(v0, v2);
|
||||||
v1 = _mm_add_epi64(v1, v3);
|
v1 = _mm_add_epi64(v1, v3);
|
||||||
|
v0 = _mm_add_epi64(v0, v1);
|
||||||
|
|
||||||
uint64_t result[2];
|
uint64_t result[2];
|
||||||
_mm_storeu_si128((__m128i*)result, v0);
|
_mm_storeu_si128((__m128i*)result, v0);
|
||||||
@ -1445,6 +1448,7 @@ uint64_t Clay__HashData(const uint8_t* data, size_t length) {
|
|||||||
Clay__SIMDARXMix(&v2, &v3);
|
Clay__SIMDARXMix(&v2, &v3);
|
||||||
v0 = vaddq_u64(v0, v2);
|
v0 = vaddq_u64(v0, v2);
|
||||||
v1 = vaddq_u64(v1, v3);
|
v1 = vaddq_u64(v1, v3);
|
||||||
|
v0 = vaddq_u64(v0, v1);
|
||||||
|
|
||||||
uint64_t result[2];
|
uint64_t result[2];
|
||||||
vst1q_u64(result, v0);
|
vst1q_u64(result, v0);
|
||||||
@ -2803,14 +2807,24 @@ void Clay__CalculateFinalLayout(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
float offset = (currentElementBoundingBox.width - wrappedLine->dimensions.width);
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_LEFT || textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
}
|
}
|
||||||
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_CENTER) {
|
||||||
offset /= 2;
|
offset /= 2;
|
||||||
}
|
}
|
||||||
|
Clay_BoundingBox textBoundingBox = {
|
||||||
|
currentElementBoundingBox.x + offset,
|
||||||
|
currentElementBoundingBox.y + yPosition,
|
||||||
|
wrappedLine->dimensions.width,
|
||||||
|
wrappedLine->dimensions.height
|
||||||
|
};
|
||||||
|
if (textElementConfig->textAlignment == CLAY_TEXT_ALIGN_SHRINK && boundingBox.width > currentElementBoundingBox.width) {
|
||||||
|
boundingBox.width = currentElementBoundingBox.width;
|
||||||
|
}
|
||||||
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
Clay__AddRenderCommand(CLAY__INIT(Clay_RenderCommand) {
|
||||||
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
.boundingBox = { currentElementBoundingBox.x + offset, currentElementBoundingBox.y + yPosition, wrappedLine->dimensions.width, wrappedLine->dimensions.height },
|
||||||
|
.boundingBox = textBoundingBox,
|
||||||
.renderData = { .text = {
|
.renderData = { .text = {
|
||||||
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
.stringContents = CLAY__INIT(Clay_StringSlice) { .length = wrappedLine->line.length, .chars = wrappedLine->line.chars, .baseChars = currentElement->childrenOrTextContent.textElementData->text.chars },
|
||||||
.textColor = textElementConfig->textColor,
|
.textColor = textElementConfig->textColor,
|
||||||
@ -4118,11 +4132,15 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) {
|
|||||||
for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) {
|
for (int32_t i = 0; i < context->scrollContainerDatas.length; ++i) {
|
||||||
Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&context->scrollContainerDatas, i);
|
Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&context->scrollContainerDatas, i);
|
||||||
if (scrollContainerData->elementId == id.id) {
|
if (scrollContainerData->elementId == id.id) {
|
||||||
|
Clay_ScrollElementConfig *scrollElementConfig = Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig;
|
||||||
|
if (!scrollElementConfig) { // This can happen on the first frame before a scroll container is declared
|
||||||
|
return CLAY__INIT(Clay_ScrollContainerData) CLAY__DEFAULT_STRUCT;
|
||||||
|
}
|
||||||
return CLAY__INIT(Clay_ScrollContainerData) {
|
return CLAY__INIT(Clay_ScrollContainerData) {
|
||||||
.scrollPosition = &scrollContainerData->scrollPosition,
|
.scrollPosition = &scrollContainerData->scrollPosition,
|
||||||
.scrollContainerDimensions = { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height },
|
.scrollContainerDimensions = { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height },
|
||||||
.contentDimensions = scrollContainerData->contentSize,
|
.contentDimensions = scrollContainerData->contentSize,
|
||||||
.config = *Clay__FindElementConfigWithType(scrollContainerData->layoutElement, CLAY__ELEMENT_CONFIG_TYPE_SCROLL).scrollElementConfig,
|
.config = *scrollElementConfig,
|
||||||
.found = true
|
.found = true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ FetchContent_MakeAvailable(fontstash)
|
|||||||
FetchContent_Declare(
|
FetchContent_Declare(
|
||||||
sokol
|
sokol
|
||||||
GIT_REPOSITORY "https://github.com/floooh/sokol.git"
|
GIT_REPOSITORY "https://github.com/floooh/sokol.git"
|
||||||
GIT_TAG "da9de496f938b7575eff7f01ab774d77469bd390"
|
GIT_TAG "master"
|
||||||
GIT_PROGRESS TRUE
|
GIT_PROGRESS TRUE
|
||||||
GIT_SHALLOW TRUE
|
GIT_SHALLOW TRUE
|
||||||
)
|
)
|
||||||
|
@ -157,7 +157,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
|
|||||||
if(strlen > temp_render_buffer_len) {
|
if(strlen > temp_render_buffer_len) {
|
||||||
// Grow the temp buffer if we need a larger string
|
// Grow the temp buffer if we need a larger string
|
||||||
if(temp_render_buffer) free(temp_render_buffer);
|
if(temp_render_buffer) free(temp_render_buffer);
|
||||||
temp_render_buffer = malloc(strlen);
|
temp_render_buffer = (char *) malloc(strlen);
|
||||||
temp_render_buffer_len = strlen;
|
temp_render_buffer_len = strlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands, Font* fonts)
|
|||||||
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.topRight), roundf(boundingBox.y + config->cornerRadius.topRight) }, roundf(config->cornerRadius.topRight - config->width.top), config->cornerRadius.topRight, 270, 360, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.topRight), roundf(boundingBox.y + config->cornerRadius.topRight) }, roundf(config->cornerRadius.topRight - config->width.top), config->cornerRadius.topRight, 270, 360, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
||||||
}
|
}
|
||||||
if (config->cornerRadius.bottomLeft > 0) {
|
if (config->cornerRadius.bottomLeft > 0) {
|
||||||
DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.bottomLeft), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomLeft) }, roundf(config->cornerRadius.bottomLeft - config->width.top), config->cornerRadius.bottomLeft, 90, 180, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
DrawRing((Vector2) { roundf(boundingBox.x + config->cornerRadius.bottomLeft), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomLeft) }, roundf(config->cornerRadius.bottomLeft - config->width.bottom), config->cornerRadius.bottomLeft, 90, 180, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
||||||
}
|
}
|
||||||
if (config->cornerRadius.bottomRight > 0) {
|
if (config->cornerRadius.bottomRight > 0) {
|
||||||
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.bottomRight), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomRight) }, roundf(config->cornerRadius.bottomRight - config->width.bottom), config->cornerRadius.bottomRight, 0.1, 90, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
DrawRing((Vector2) { roundf(boundingBox.x + boundingBox.width - config->cornerRadius.bottomRight), roundf(boundingBox.y + boundingBox.height - config->cornerRadius.bottomRight) }, roundf(config->cornerRadius.bottomRight - config->width.bottom), config->cornerRadius.bottomRight, 0.1, 90, 10, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
||||||
|
Loading…
Reference in New Issue
Block a user