mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-22 06:08:03 +00:00
Compare commits
8 Commits
4359b458e7
...
e998c16bb6
Author | SHA1 | Date | |
---|---|---|---|
|
e998c16bb6 | ||
|
a9e94e3be0 | ||
|
cbb50267da | ||
|
55792fdbec | ||
|
50aad568fa | ||
|
b4dc02c73a | ||
|
3f635cdd79 | ||
|
fbf8251996 |
@ -38,3 +38,6 @@ if(NOT MSVC AND (CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_SDL3_EXAMPLES))
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
||||||
|
|
||||||
|
#add_library(${PROJECT_NAME} INTERFACE)
|
||||||
|
#target_include_directories(${PROJECT_NAME} INTERFACE .)
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -495,7 +495,7 @@ main :: proc() {
|
|||||||
clay.Initialize(arena, {cast(f32)raylib.GetScreenWidth(), cast(f32)raylib.GetScreenHeight()}, { handler = errorHandler })
|
clay.Initialize(arena, {cast(f32)raylib.GetScreenWidth(), cast(f32)raylib.GetScreenHeight()}, { handler = errorHandler })
|
||||||
clay.SetMeasureTextFunction(measureText, nil)
|
clay.SetMeasureTextFunction(measureText, nil)
|
||||||
|
|
||||||
raylib.SetConfigFlags({.VSYNC_HINT, .WINDOW_RESIZABLE, .WINDOW_HIGHDPI, .MSAA_4X_HINT})
|
raylib.SetConfigFlags({.VSYNC_HINT, .WINDOW_RESIZABLE, .MSAA_4X_HINT})
|
||||||
raylib.InitWindow(windowWidth, windowHeight, "Raylib Odin Example")
|
raylib.InitWindow(windowWidth, windowHeight, "Raylib Odin Example")
|
||||||
raylib.SetTargetFPS(raylib.GetMonitorRefreshRate(0))
|
raylib.SetTargetFPS(raylib.GetMonitorRefreshRate(0))
|
||||||
loadFont(FONT_ID_TITLE_56, 56, "resources/Calistoga-Regular.ttf")
|
loadFont(FONT_ID_TITLE_56, 56, "resources/Calistoga-Regular.ttf")
|
||||||
|
24
clay.h
24
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.
|
||||||
@ -1399,13 +1401,9 @@ uint64_t Clay__HashData(const uint8_t* data, size_t length) {
|
|||||||
return result[0] ^ result[1];
|
return result[0] ^ result[1];
|
||||||
}
|
}
|
||||||
#elif !defined(CLAY_DISABLE_SIMD) && defined(__aarch64__)
|
#elif !defined(CLAY_DISABLE_SIMD) && defined(__aarch64__)
|
||||||
static inline uint64x2_t Clay__SIMDRotateLeft(uint64x2_t x, int r) {
|
|
||||||
return vorrq_u64(vshlq_n_u64(x, 17), vshrq_n_u64(x, 64 - 17));
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void Clay__SIMDARXMix(uint64x2_t* a, uint64x2_t* b) {
|
static inline void Clay__SIMDARXMix(uint64x2_t* a, uint64x2_t* b) {
|
||||||
*a = vaddq_u64(*a, *b);
|
*a = vaddq_u64(*a, *b);
|
||||||
*b = veorq_u64(Clay__SIMDRotateLeft(*b, 17), *a);
|
*b = veorq_u64(vorrq_u64(vshlq_n_u64(*b, 17), vshrq_n_u64(*b, 64 - 17)), *a);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t Clay__HashData(const uint8_t* data, size_t length) {
|
uint64_t Clay__HashData(const uint8_t* data, size_t length) {
|
||||||
@ -1674,6 +1672,8 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl
|
|||||||
hashItem->generation = context->generation + 1;
|
hashItem->generation = context->generation + 1;
|
||||||
hashItem->layoutElement = layoutElement;
|
hashItem->layoutElement = layoutElement;
|
||||||
hashItem->debugData->collision = false;
|
hashItem->debugData->collision = false;
|
||||||
|
hashItem->onHoverFunction = NULL;
|
||||||
|
hashItem->hoverFunctionUserData = 0;
|
||||||
} else { // Multiple collisions this frame - two elements have the same ID
|
} else { // Multiple collisions this frame - two elements have the same ID
|
||||||
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
|
context->errorHandler.errorHandlerFunction(CLAY__INIT(Clay_ErrorData) {
|
||||||
.errorType = CLAY_ERROR_TYPE_DUPLICATE_ID,
|
.errorType = CLAY_ERROR_TYPE_DUPLICATE_ID,
|
||||||
@ -1981,7 +1981,7 @@ Clay_ElementId Clay__AttachId(Clay_ElementId elementId) {
|
|||||||
uint32_t idAlias = openLayoutElement->id;
|
uint32_t idAlias = openLayoutElement->id;
|
||||||
openLayoutElement->id = elementId.id;
|
openLayoutElement->id = elementId.id;
|
||||||
Clay__AddHashMapItem(elementId, openLayoutElement, idAlias);
|
Clay__AddHashMapItem(elementId, openLayoutElement, idAlias);
|
||||||
Clay__StringArray_Add(&context->layoutElementIdStrings, elementId.stringId);
|
Clay__StringArray_Set(&context->layoutElementIdStrings, context->layoutElements.length - 1, elementId.stringId);
|
||||||
return elementId;
|
return elementId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2805,14 +2805,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,
|
||||||
|
@ -226,7 +226,7 @@ int main(void) {
|
|||||||
uint64_t totalMemorySize = Clay_MinMemorySize();
|
uint64_t totalMemorySize = Clay_MinMemorySize();
|
||||||
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize));
|
||||||
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors, 0 });
|
Clay_Initialize(clayMemory, (Clay_Dimensions) { (float)GetScreenWidth(), (float)GetScreenHeight() }, (Clay_ErrorHandler) { HandleClayErrors, 0 });
|
||||||
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_WINDOW_HIGHDPI | FLAG_MSAA_4X_HINT);
|
Clay_Raylib_Initialize(1024, 768, "Clay - Raylib Renderer Example", FLAG_VSYNC_HINT | FLAG_WINDOW_RESIZABLE | FLAG_MSAA_4X_HINT);
|
||||||
profilePicture = LoadTexture("resources/profile-picture.png");
|
profilePicture = LoadTexture("resources/profile-picture.png");
|
||||||
|
|
||||||
Font fonts[2];
|
Font fonts[2];
|
||||||
|
Loading…
Reference in New Issue
Block a user