mirror of
https://github.com/nicbarker/clay.git
synced 2025-05-13 05:48:04 +00:00
initial attempt
This commit is contained in:
parent
8237122350
commit
ac61107eee
@ -8,6 +8,7 @@ add_subdirectory("examples/cpp-project-example")
|
||||
# Don't try to compile C99 projects using MSVC
|
||||
if(NOT MSVC)
|
||||
add_subdirectory("examples/raylib-sidebar-scrolling-container")
|
||||
add_subdirectory("examples/multi-context-raylib-sidebar-scrolling-container")
|
||||
# add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
|
||||
add_subdirectory("examples/clay-official-website")
|
||||
add_subdirectory("examples/introducing-clay-video-demo")
|
||||
|
56
clay.h
56
clay.h
@ -60,7 +60,7 @@
|
||||
|
||||
#define CLAY_BORDER(...) Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(CLAY__CONFIG_WRAPPER(Clay_BorderElementConfig, __VA_ARGS__)) }, CLAY__ELEMENT_CONFIG_TYPE_BORDER_CONTAINER)
|
||||
|
||||
#define CLAY_BORDER_OUTSIDE(...) Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = __VA_ARGS__, .right = __VA_ARGS__, .top = __VA_ARGS__, .bottom = __VA_ARGS__ }) }, CLAY__ELEMENT_CONFIG_TYPE_BORDER_CONTAINER)
|
||||
#define CLAY_BORDER_OUTSIDE(...) { .left = __VA_ARGS__, .right = __VA_ARGS__, .top = __VA_ARGS__, .bottom = __VA_ARGS__ }
|
||||
|
||||
#define CLAY_BORDER_OUTSIDE_RADIUS(width, color, radius) Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .cornerRadius = CLAY_CORNER_RADIUS(radius) })}, CLAY__ELEMENT_CONFIG_TYPE_BORDER_CONTAINER)
|
||||
|
||||
@ -125,7 +125,7 @@ static uint8_t CLAY__ELEMENT_DEFINITION_LATCH;
|
||||
*/
|
||||
#define CLAY(...) \
|
||||
for (\
|
||||
CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(), ##__VA_ARGS__, Clay__ElementPostConfiguration(), 0); \
|
||||
CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(CLAY__CONFIG_WRAPPER(Clay_ElementDeclaration, __VA_ARGS__)), Clay__ElementPostConfiguration(), 0); \
|
||||
CLAY__ELEMENT_DEFINITION_LATCH < 1; \
|
||||
++CLAY__ELEMENT_DEFINITION_LATCH, Clay__CloseElement() \
|
||||
)
|
||||
@ -473,6 +473,17 @@ CLAY__TYPEDEF(Clay_PointerData, struct {
|
||||
Clay_PointerDataInteractionState state;
|
||||
});
|
||||
|
||||
CLAY__TYPEDEF(Clay_ElementDeclaration, struct t {
|
||||
Clay_ElementId id;
|
||||
Clay_LayoutConfig layoutConfig;
|
||||
Clay_RectangleElementConfig rectangle;
|
||||
Clay_ImageElementConfig image;
|
||||
Clay_FloatingElementConfig floating;
|
||||
Clay_CustomElementConfig custom;
|
||||
Clay_ScrollElementConfig scroll;
|
||||
Clay_BorderElementConfig border;
|
||||
});
|
||||
|
||||
CLAY__TYPEDEF(Clay_ErrorType, enum {
|
||||
CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED,
|
||||
CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED,
|
||||
@ -524,7 +535,7 @@ int32_t Clay_GetMaxMeasureTextCacheWordCount(void);
|
||||
void Clay_SetMaxMeasureTextCacheWordCount(int32_t maxMeasureTextCacheWordCount);
|
||||
|
||||
// Internal API functions required by macros
|
||||
void Clay__OpenElement(void);
|
||||
void Clay__OpenElement(Clay_ElementDeclaration config);
|
||||
void Clay__CloseElement(void);
|
||||
Clay_LayoutConfig * Clay__StoreLayoutConfig(Clay_LayoutConfig config);
|
||||
void Clay__ElementPostConfiguration(void);
|
||||
@ -1976,7 +1987,16 @@ void Clay__CloseElement(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void Clay__OpenElement(void) {
|
||||
bool Clay__MemCmp(char *a, char *b, int length) {
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Clay__OpenElement(Clay_ElementDeclaration declaration) {
|
||||
Clay_Context* context = Clay_GetCurrentContext();
|
||||
if (context->layoutElements.length == context->layoutElements.capacity - 1 || context->booleanWarnings.maxElementsExceeded) {
|
||||
context->booleanWarnings.maxElementsExceeded = true;
|
||||
@ -1990,6 +2010,28 @@ void Clay__OpenElement(void) {
|
||||
} else {
|
||||
Clay__int32_tArray_Set(&context->layoutElementClipElementIds, context->layoutElements.length - 1, 0);
|
||||
}
|
||||
Clay__GetOpenLayoutElement()->layoutConfig = Clay__StoreLayoutConfig(declaration.layoutConfig);
|
||||
if (declaration.id.id != 0) {
|
||||
Clay__AttachId(declaration.id);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.rectangle), (char *)(&CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_RectangleElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .rectangleElementConfig = Clay__StoreRectangleElementConfig(declaration.rectangle) }, CLAY__ELEMENT_CONFIG_TYPE_RECTANGLE);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.image), (char *)(&CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_ImageElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .imageElementConfig = Clay__StoreImageElementConfig(declaration.image) }, CLAY__ELEMENT_CONFIG_TYPE_IMAGE);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.floating), (char *)(&CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_FloatingElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .floatingElementConfig = Clay__StoreFloatingElementConfig(declaration.floating) }, CLAY__ELEMENT_CONFIG_TYPE_FLOATING_CONTAINER);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.custom), (char *)(&CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_CustomElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .customElementConfig = Clay__StoreCustomElementConfig(declaration.custom) }, CLAY__ELEMENT_CONFIG_TYPE_CUSTOM);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.scroll), (char *)(&CLAY__SCROLL_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_ScrollElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .scrollElementConfig = Clay__StoreScrollElementConfig(declaration.scroll) }, CLAY__ELEMENT_CONFIG_TYPE_SCROLL_CONTAINER);
|
||||
}
|
||||
if (!Clay__MemCmp((char *)(&declaration.border), (char *)(&CLAY__BORDER_ELEMENT_CONFIG_DEFAULT), sizeof(Clay_BorderElementConfig))) {
|
||||
Clay__AttachElementConfig(CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = Clay__StoreBorderElementConfig(declaration.border) }, CLAY__ELEMENT_CONFIG_TYPE_BORDER_CONTAINER);
|
||||
}
|
||||
}
|
||||
|
||||
void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig) {
|
||||
@ -2001,7 +2043,7 @@ void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig)
|
||||
Clay_LayoutElement *parentElement = Clay__GetOpenLayoutElement();
|
||||
parentElement->childrenOrTextContent.children.length++;
|
||||
|
||||
Clay__OpenElement();
|
||||
Clay__OpenElement((Clay_ElementDeclaration){ });
|
||||
Clay_LayoutElement * openLayoutElement = Clay__GetOpenLayoutElement();
|
||||
Clay__int32_tArray_Add(&context->layoutElementChildrenBuffer, context->layoutElements.length - 1);
|
||||
Clay__MeasureTextCacheItem *textMeasured = Clay__MeasureTextCached(&text, textConfig);
|
||||
@ -3855,7 +3897,7 @@ void Clay_BeginLayout(void) {
|
||||
context->booleanWarnings.maxElementsExceeded = false;
|
||||
context->booleanWarnings.maxTextMeasureCacheExceeded = false;
|
||||
context->booleanWarnings.maxRenderCommandsExceeded = false;
|
||||
Clay__OpenElement();
|
||||
Clay__OpenElement((Clay_ElementDeclaration){});
|
||||
CLAY_ID("Clay__RootContainer");
|
||||
CLAY_LAYOUT({ .sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)} });
|
||||
Clay__ElementPostConfiguration();
|
||||
@ -3871,7 +3913,7 @@ Clay_RenderCommandArray Clay_EndLayout() {
|
||||
Clay__CloseElement();
|
||||
if (context->debugModeEnabled) {
|
||||
context->warningsEnabled = false;
|
||||
Clay__RenderDebugView();
|
||||
// Clay__RenderDebugView();
|
||||
context->warningsEnabled = true;
|
||||
}
|
||||
if (context->booleanWarnings.maxElementsExceeded) {
|
||||
|
@ -0,0 +1,35 @@
|
||||
cmake_minimum_required(VERSION 3.27)
|
||||
project(clay_examples_multi_context_raylib_sidebar_scrolling_container C)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
# Adding Raylib
|
||||
include(FetchContent)
|
||||
set(FETCHCONTENT_QUIET FALSE)
|
||||
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
|
||||
set(BUILD_GAMES OFF CACHE BOOL "" FORCE) # don't build the supplied example games
|
||||
|
||||
FetchContent_Declare(
|
||||
raylib
|
||||
GIT_REPOSITORY "https://github.com/raysan5/raylib.git"
|
||||
GIT_TAG "master"
|
||||
GIT_PROGRESS TRUE
|
||||
GIT_SHALLOW TRUE
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(raylib)
|
||||
|
||||
add_executable(clay_examples_multi_context_raylib_sidebar_scrolling_container main.c)
|
||||
|
||||
target_compile_options(clay_examples_multi_context_raylib_sidebar_scrolling_container PUBLIC)
|
||||
target_include_directories(clay_examples_multi_context_raylib_sidebar_scrolling_container PUBLIC .)
|
||||
|
||||
target_link_libraries(clay_examples_multi_context_raylib_sidebar_scrolling_container PUBLIC raylib)
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces -DCLAY_DEBUG")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
|
||||
add_custom_command(
|
||||
TARGET clay_examples_multi_context_raylib_sidebar_scrolling_container POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/resources
|
||||
${CMAKE_CURRENT_BINARY_DIR}/resources)
|
256
examples/multi-context-raylib-sidebar-scrolling-container/main.c
Normal file
256
examples/multi-context-raylib-sidebar-scrolling-container/main.c
Normal file
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 101 KiB |
Loading…
Reference in New Issue
Block a user