diff --git a/CMakeLists.txt b/CMakeLists.txt index ecb29d7..29fbfcd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,7 @@ if(CLAY_INCLUDE_ALL_EXAMPLES OR CLAY_INCLUDE_DEMOS) if(NOT MSVC) add_subdirectory("examples/clay-official-website") endif() + add_subdirectory("examples/cairo-pdf-rendering") add_subdirectory("examples/introducing-clay-video-demo") endif () diff --git a/clay.h b/clay.h index e04ed2f..ff88e4a 100644 --- a/clay.h +++ b/clay.h @@ -117,7 +117,7 @@ static uint8_t CLAY__ELEMENT_DEFINITION_LATCH; */ #define CLAY(...) \ for (\ - CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(), Clay__ConfigureOpenElement(CLAY__INIT(Clay_ElementDeclaration) __VA_ARGS__), 0); \ + CLAY__ELEMENT_DEFINITION_LATCH = (Clay__OpenElement(), Clay__ConfigureOpenElement(CLAY__CONFIG_WRAPPER(Clay_ElementDeclaration, __VA_ARGS__)), 0); \ CLAY__ELEMENT_DEFINITION_LATCH < 1; \ ++CLAY__ELEMENT_DEFINITION_LATCH, Clay__CloseElement() \ ) @@ -502,6 +502,8 @@ typedef struct { Clay_SharedElementConfig shared; } Clay_ElementDeclaration; +CLAY__WRAPPER_STRUCT(Clay_ElementDeclaration); + typedef CLAY_PACKED_ENUM { CLAY_ERROR_TYPE_TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED, CLAY_ERROR_TYPE_ARENA_CAPACITY_EXCEEDED, @@ -957,7 +959,7 @@ Clay_ElementConfig Clay__CurrentConfigUnion(Clay__ElementConfigType type) { Clay_Context *context = Clay_GetCurrentContext(); Clay_LayoutElement *openElement = Clay__GetOpenLayoutElement(); if (Clay__ElementHasConfig(openElement, type)) { - return CLAY__INIT(Clay_ElementConfig) { .config = Clay__FindElementConfigWithType(openElement, type), .type = type }; + return CLAY__INIT(Clay_ElementConfig) { .type = type, .config = Clay__FindElementConfigWithType(openElement, type) }; } // Unhandled: structural changes to element switch (type) { @@ -2798,8 +2800,8 @@ void Clay__RenderDebugView(void) { } Clay__RenderDebugLayoutData layoutData = CLAY__DEFAULT_STRUCT; CLAY({ .id = CLAY_ID("Clay__DebugView"), + .layout = { .sizing = { CLAY_SIZING_FIXED((float)Clay__debugViewWidth) , CLAY_SIZING_FIXED(context->layoutDimensions.height) }, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .floating = { .zIndex = 65000, .parentId = Clay__HashString(CLAY_STRING("Clay__RootContainer"), 0, 0).id, .attachment = { .element = CLAY_ATTACH_POINT_LEFT_CENTER, .parent = CLAY_ATTACH_POINT_RIGHT_CENTER }}, - .layout = { .sizing = { CLAY_SIZING_FIXED((float)Clay__debugViewWidth) , CLAY_SIZING_FIXED(context->layoutDimensions.height) }, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .border = { .bottom = { .width = 1, .color = CLAY__DEBUGVIEW_COLOR_3 }} }) { CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING }, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} }, .rectangle = { .color = CLAY__DEBUGVIEW_COLOR_2 } }) { @@ -2807,9 +2809,9 @@ void Clay__RenderDebugView(void) { CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0) } } }) {} // Close button CLAY({ + .layout = { .sizing = {CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10)}, .childAlignment = {CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER} }, + .rectangle = { .color = {217,91,67,80} }, .border = CLAY_BORDER_OUTSIDE({ 1, (CLAY__INIT(Clay_Color){217,91,67,255}) }), - .layout = { .sizing = {CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 10)}, .childAlignment = {CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER} }, - .rectangle = { .color = {217,91,67,80} } }) { Clay_OnHover(HandleDebugViewCloseButtonInteraction, 0); CLAY_TEXT(CLAY_STRING("x"), CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16 })); @@ -2845,9 +2847,9 @@ void Clay__RenderDebugView(void) { if (context->debugSelectedElementId != 0) { Clay_LayoutElementHashMapItem *selectedItem = Clay__GetHashMapItem(context->debugSelectedElementId); CLAY({ + .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, + .rectangle = { .color = CLAY__DEBUGVIEW_COLOR_2 }, .scroll = { .vertical = true }, - .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .rectangle = { .color = CLAY__DEBUGVIEW_COLOR_2 }, .border = { .betweenChildren = { .width = 1, .color = CLAY__DEBUGVIEW_COLOR_3 }} }) { CLAY({ .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT + 8)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { @@ -3071,7 +3073,7 @@ void Clay__RenderDebugView(void) { } } } else { - CLAY({ .id = CLAY_ID("Clay__DebugViewWarningsScrollPane"), .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .childGap = 6, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .scroll = { .horizontal = true, .vertical = true }, .rectangle = { .color = CLAY__DEBUGVIEW_COLOR_2 } }) { + CLAY({ .id = CLAY_ID("Clay__DebugViewWarningsScrollPane"), .layout = { .sizing = {CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(300)}, .childGap = 6, .layoutDirection = CLAY_TOP_TO_BOTTOM }, .rectangle = { .color = CLAY__DEBUGVIEW_COLOR_2 }, .scroll = { .horizontal = true, .vertical = true } }) { Clay_TextElementConfig *warningConfig = CLAY_TEXT_CONFIG({ .textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }); CLAY({ .id = CLAY_ID("Clay__DebugViewWarningItemHeader"), .layout = { .sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING, CLAY__DEBUGVIEW_OUTER_PADDING}, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} } }) { CLAY_TEXT(CLAY_STRING("Warnings"), warningConfig); diff --git a/examples/SDL2-video-demo/CMakeLists.txt b/examples/SDL2-video-demo/CMakeLists.txt index ace8592..4dffd2b 100644 --- a/examples/SDL2-video-demo/CMakeLists.txt +++ b/examples/SDL2-video-demo/CMakeLists.txt @@ -45,10 +45,10 @@ target_link_libraries(SDL2_video_demo PUBLIC ) if(MSVC) - set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") else() - set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces -DCLAY_DEBUG") - set(CMAKE_C_FLAGS_RELEASE "-O3") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") endif() add_custom_command( diff --git a/examples/SDL3-simple-demo/CMakeLists.txt b/examples/SDL3-simple-demo/CMakeLists.txt index 4a86f0e..df467a9 100644 --- a/examples/SDL3-simple-demo/CMakeLists.txt +++ b/examples/SDL3-simple-demo/CMakeLists.txt @@ -4,8 +4,8 @@ cmake_minimum_required(VERSION 3.27) project(clay_examples_sdl3_simple_demo C) set(CMAKE_C_STANDARD 99) -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") include(FetchContent) set(FETCHCONTENT_QUIET FALSE) diff --git a/examples/cairo-pdf-rendering/CMakeLists.txt b/examples/cairo-pdf-rendering/CMakeLists.txt index 1f321dd..bdfe4e7 100644 --- a/examples/cairo-pdf-rendering/CMakeLists.txt +++ b/examples/cairo-pdf-rendering/CMakeLists.txt @@ -4,7 +4,6 @@ set(CMAKE_C_STANDARD 99) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake") - add_executable(clay_examples_cairo_pdf_rendering main.c) find_package(Cairo REQUIRED) @@ -13,8 +12,8 @@ target_compile_options(clay_examples_cairo_pdf_rendering PUBLIC) target_include_directories(clay_examples_cairo_pdf_rendering PUBLIC . ${CAIRO_INCLUDE_DIRS}) target_link_libraries(clay_examples_cairo_pdf_rendering PUBLIC Cairo::Cairo) -set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces") -set(CMAKE_C_FLAGS_RELEASE "-O3") +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") add_custom_command( TARGET clay_examples_cairo_pdf_rendering POST_BUILD diff --git a/examples/cairo-pdf-rendering/main.c b/examples/cairo-pdf-rendering/main.c index f9fc793..6b70ce4 100644 --- a/examples/cairo-pdf-rendering/main.c +++ b/examples/cairo-pdf-rendering/main.c @@ -37,32 +37,21 @@ void Layout() { static Clay_Color BACKGROUND = { 0xF4, 0xEB, 0xE6, 255 }; static Clay_Color ACCENT = { 0xFA, 0xE0, 0xD4, 255 }; - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, - .layoutDirection = CLAY_TOP_TO_BOTTOM }), - CLAY_RECTANGLE({ .color = BACKGROUND })) { - CLAY(CLAY_ID("PageMargins"), - CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, - .padding = { 70, 70, 50, 50 }, // Some nice looking page margins - .layoutDirection = CLAY_TOP_TO_BOTTOM, - .childGap = 10})) { - + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, + .layoutDirection = CLAY_TOP_TO_BOTTOM }, + .rectangle = { .color = BACKGROUND } }) { + CLAY({ .id = CLAY_ID("PageMargins"), .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, + .padding = { 70, 70, 50, 50 }, // Some nice looking page margins + .layoutDirection = CLAY_TOP_TO_BOTTOM, + .childGap = 10} + }) { // Section Title - CLAY(CLAY_TEXT( - CLAY_STRING("Features Overview"), - CLAY_TEXT_CONFIG({ - .fontFamily = CLAY_STRING("Calistoga"), - .textColor = PRIMARY, - .fontSize = 24 - }) - )); + CLAY_TEXT(CLAY_STRING("Features Overview"), CLAY_TEXT_CONFIG({.fontFamily = CLAY_STRING("Calistoga"), .textColor = PRIMARY, .fontSize = 24})); // Feature Box - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) }, .childGap = 10 })) { - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) }}), CLAY_RECTANGLE({ - .color = ACCENT, - .cornerRadius = CLAY_CORNER_RADIUS(12), - })) { - CLAY(CLAY_LAYOUT({.padding = CLAY_PADDING_ALL(20), .childGap = 4, .layoutDirection = CLAY_TOP_TO_BOTTOM })) { + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) }, .childGap = 10 }}) { + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIT(0) }}, .rectangle = { .color = ACCENT }, .shared = { .cornerRadius = CLAY_CORNER_RADIUS(12) } }) { + CLAY({ .layout = {.padding = CLAY_PADDING_ALL(20), .childGap = 4, .layoutDirection = CLAY_TOP_TO_BOTTOM }}) { CLAY_TEXT(CLAY_STRING("- High performance"), CLAY_TEXT_CONFIG({ .textColor = PRIMARY, .fontSize = 14, .fontFamily = CLAY_STRING("Quicksand SemiBold") })); CLAY_TEXT(CLAY_STRING("- Declarative syntax"), @@ -75,29 +64,29 @@ void Layout() { CLAY_TEXT_CONFIG({ .textColor = PRIMARY, .fontSize = 14, .fontFamily = CLAY_STRING("Quicksand SemiBold") })); } } - CLAY(CLAY_LAYOUT({ + CLAY({ .layout = { .sizing = {CLAY_SIZING_FIT(0), CLAY_SIZING_GROW(0)}, .padding = CLAY_PADDING_ALL(10), .layoutDirection = CLAY_TOP_TO_BOTTOM, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER }, .childGap = 4 - }), CLAY_RECTANGLE({ .color = ACCENT, .cornerRadius = CLAY_CORNER_RADIUS(8) })) { + }, .rectangle = { .color = ACCENT }, .shared = {.cornerRadius = CLAY_CORNER_RADIUS(8)}}) { // Profile picture - CLAY(CLAY_LAYOUT({ + CLAY({ .layout = { .sizing = {CLAY_SIZING_FIT(0), CLAY_SIZING_GROW(0)}, .padding = { 30, 30, 0, 0 }, .layoutDirection = CLAY_TOP_TO_BOTTOM, - .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER }}), CLAY_BORDER_OUTSIDE_RADIUS(2, PRIMARY, 10)) { - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_FIXED(32), CLAY_SIZING_FIXED(32) } }), CLAY_IMAGE({ .sourceDimensions = { 32, 32 }, .path = CLAY_STRING("resources/check.png") })); + .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER }}, .border = CLAY_BORDER_OUTSIDE(2, PRIMARY), .shared = { .cornerRadius = 10 }}) { + CLAY({ .layout = { .sizing = { CLAY_SIZING_FIXED(32), CLAY_SIZING_FIXED(32) } }, .image = { .sourceDimensions = { 32, 32 }, .path = CLAY_STRING("resources/check.png") }}); } } } - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(16) } })); + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_FIXED(16) } }}); - CLAY(CLAY_LAYOUT({ .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, .childGap = 10, .layoutDirection = CLAY_TOP_TO_BOTTOM })) { + CLAY({ .layout = { .sizing = { CLAY_SIZING_GROW(0), CLAY_SIZING_GROW(0) }, .childGap = 10, .layoutDirection = CLAY_TOP_TO_BOTTOM }}) { CLAY_TEXT(CLAY_STRING("Cairo"), CLAY_TEXT_CONFIG({ .fontFamily = CLAY_STRING("Calistoga"), .fontSize = 24, .textColor = PRIMARY })); - CLAY(CLAY_LAYOUT({ .padding = CLAY_PADDING_ALL(10) }), CLAY_RECTANGLE({ .color = ACCENT, .cornerRadius = CLAY_CORNER_RADIUS(10) })) { + CLAY({ .layout = { .padding = CLAY_PADDING_ALL(10) }, .rectangle = { .color = ACCENT }, .shared = { .cornerRadius = 10 } }) { CLAY_TEXT(CLAY_STRING("Officiis quia quia qui inventore ratione voluptas et. Quidem sunt unde similique. Qui est et exercitationem cumque harum illum. Numquam placeat aliquid quo voluptatem. " "Deleniti saepe nihil exercitationem nemo illo. Consequatur beatae repellat provident similique. Provident qui exercitationem deserunt sapiente. Quam qui dolor corporis odit. " "Assumenda corrupti sunt culpa pariatur. Vero sit ut minima. In est consequatur minus et cum sint illum aperiam. Qui ipsa quas nisi omnis aut quia nobis. " @@ -136,11 +125,12 @@ int main(void) { uint64_t totalMemorySize = Clay_MinMemorySize(); Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, malloc(totalMemorySize)); - Clay_SetMeasureTextFunction(Clay_Cairo_MeasureText); // We initialize Clay with the same size Clay_Initialize(clayMemory, (Clay_Dimensions) { width, height }, (Clay_ErrorHandler) { HandleClayErrors }); + Clay_SetMeasureTextFunction(Clay_Cairo_MeasureText, 0); + Clay_BeginLayout(); // Here you can now create the declarative clay layout. diff --git a/examples/clay-official-website/CMakeLists.txt b/examples/clay-official-website/CMakeLists.txt index 9702d21..b64f447 100644 --- a/examples/clay-official-website/CMakeLists.txt +++ b/examples/clay-official-website/CMakeLists.txt @@ -7,5 +7,3 @@ add_executable(clay_official_website main.c) target_compile_options(clay_official_website PUBLIC -Wall -Werror -Wno-unknown-pragmas -Wno-error=missing-braces) target_include_directories(clay_official_website PUBLIC .) - -set(CMAKE_C_FLAGS_RELEASE "-O3") \ No newline at end of file diff --git a/examples/cpp-project-example/CMakeLists.txt b/examples/cpp-project-example/CMakeLists.txt index 24422d7..4ddcf39 100644 --- a/examples/cpp-project-example/CMakeLists.txt +++ b/examples/cpp-project-example/CMakeLists.txt @@ -11,6 +11,6 @@ add_executable(clay_examples_cpp_project_example main.cpp) target_include_directories(clay_examples_cpp_project_example PUBLIC .) if(NOT MSVC) - set(CMAKE_CXX_FLAGS_DEBUG "-Werror -Wall") - set(CMAKE_CXX_FLAGS_RELEASE "-O3") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") endif() diff --git a/examples/cpp-project-example/main.cpp b/examples/cpp-project-example/main.cpp index 363e8ef..0d52406 100644 --- a/examples/cpp-project-example/main.cpp +++ b/examples/cpp-project-example/main.cpp @@ -13,7 +13,7 @@ int main(void) { Clay_Arena clayMemory = Clay_CreateArenaWithCapacityAndMemory(totalMemorySize, (char *)malloc(totalMemorySize)); Clay_Initialize(clayMemory, Clay_Dimensions {1024,768}, Clay_ErrorHandler { HandleClayErrors }); Clay_BeginLayout(); - CLAY(CLAY_RECTANGLE({ .color = {255,255,255,0} }), CLAY_LAYOUT(layoutElement)) { + CLAY({ .layout = layoutElement, .rectangle = { .color = {255,255,255,0} } }) { CLAY_TEXT(CLAY_STRING(""), CLAY_TEXT_CONFIG({ .fontId = 0 })); } Clay_EndLayout(); diff --git a/examples/introducing-clay-video-demo/CMakeLists.txt b/examples/introducing-clay-video-demo/CMakeLists.txt index 3c56dce..48c5983 100644 --- a/examples/introducing-clay-video-demo/CMakeLists.txt +++ b/examples/introducing-clay-video-demo/CMakeLists.txt @@ -29,7 +29,7 @@ if(MSVC) set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG") else() set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - set(CMAKE_C_FLAGS_RELEASE "-O3") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") endif() add_custom_command( diff --git a/examples/introducing-clay-video-demo/main.c b/examples/introducing-clay-video-demo/main.c index a017b7c..9f188c4 100644 --- a/examples/introducing-clay-video-demo/main.c +++ b/examples/introducing-clay-video-demo/main.c @@ -24,7 +24,7 @@ int main(void) { }; SetTextureFilter(Raylib_fonts[FONT_ID_BODY_16].font.texture, TEXTURE_FILTER_BILINEAR); - ClayVideoDemo_Initialize(); + ClayVideoDemo_Data data = ClayVideoDemo_Initialize(); while (!WindowShouldClose()) { // Run once per frame @@ -45,11 +45,7 @@ int main(void) { GetFrameTime() ); - Clay_BeginLayout(); - - ClayVideoDemo_CreateLayout(); - - Clay_RenderCommandArray renderCommands = Clay_EndLayout(); + Clay_RenderCommandArray renderCommands = ClayVideoDemo_CreateLayout(&data); BeginDrawing(); ClearBackground(BLACK); diff --git a/examples/raylib-multi-context/CMakeLists.txt b/examples/raylib-multi-context/CMakeLists.txt index 5e082f2..24853b5 100644 --- a/examples/raylib-multi-context/CMakeLists.txt +++ b/examples/raylib-multi-context/CMakeLists.txt @@ -26,7 +26,7 @@ target_include_directories(clay_examples_raylib_multi_context PUBLIC .) target_link_libraries(clay_examples_raylib_multi_context PUBLIC raylib) set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") add_custom_command( TARGET clay_examples_raylib_multi_context POST_BUILD diff --git a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt index 94ee26b..a8072f6 100644 --- a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt +++ b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt @@ -25,10 +25,10 @@ target_include_directories(clay_examples_raylib_sidebar_scrolling_container PUBL target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib) if(MSVC) - set(CMAKE_C_FLAGS_DEBUG "/D CLAY_DEBUG") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") else() set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}") endif() add_custom_command( diff --git a/renderers/cairo/clay_renderer_cairo.c b/renderers/cairo/clay_renderer_cairo.c index c8e3c16..ff3813e 100644 --- a/renderers/cairo/clay_renderer_cairo.c +++ b/renderers/cairo/clay_renderer_cairo.c @@ -83,12 +83,12 @@ static inline char *Clay_Cairo__NullTerminate(Clay_String *str) { } // Measure text using cairo's *toy* text API. -static inline Clay_Dimensions Clay_Cairo_MeasureText(Clay_String *str, Clay_TextElementConfig *config, uintptr_t userData) { +static inline Clay_Dimensions Clay_Cairo_MeasureText(Clay_StringSlice str, Clay_TextElementConfig *config, uintptr_t userData) { // Edge case: Clay computes the width of a whitespace character // once. Cairo does not factor in whitespaces when computing text // extents, this edge-case serves as a short-circuit to introduce // (somewhat) sensible values into Clay. - if(str->length == 1 && str->chars[0] == ' ') { + if(str.length == 1 && str.chars[0] == ' ') { cairo_text_extents_t te; cairo_text_extents(Clay__Cairo, " ", &te); return (Clay_Dimensions) { @@ -102,7 +102,8 @@ static inline Clay_Dimensions Clay_Cairo_MeasureText(Clay_String *str, Clay_Text } // Ensure string is null-terminated for Cairo - char *text = Clay_Cairo__NullTerminate(str); + Clay_String toTerminate = (Clay_String){ str.length, str.chars }; + char *text = Clay_Cairo__NullTerminate(&toTerminate); char *font_family = Clay_Cairo__NullTerminate(&config->fontFamily); // Save and reset the Cairo context to avoid unwanted transformations @@ -195,6 +196,7 @@ void Clay_Cairo_Render(Clay_RenderCommandArray commands) { cairo_t *cr = Clay__Cairo; for(size_t i = 0; i < commands.length; i++) { Clay_RenderCommand *command = Clay_RenderCommandArray_Get(&commands, i); + Clay_CornerRadius cornerRadius = command->textOrSharedConfig.sharedConfig->cornerRadius; switch(command->commandType) { case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: { @@ -205,21 +207,21 @@ void Clay_Cairo_Render(Clay_RenderCommandArray commands) { cairo_set_source_rgba(cr, CLAY_TO_CAIRO(color)); cairo_new_sub_path(cr); - cairo_arc(cr, bb.x + config->cornerRadius.topLeft, - bb.y + config->cornerRadius.topLeft, - config->cornerRadius.topLeft, + cairo_arc(cr, bb.x + cornerRadius.topLeft, + bb.y + cornerRadius.topLeft, + cornerRadius.topLeft, M_PI, 3 * M_PI / 2); // 180° to 270° - cairo_arc(cr, bb.x + bb.width - config->cornerRadius.topRight, - bb.y + config->cornerRadius.topRight, - config->cornerRadius.topRight, + cairo_arc(cr, bb.x + bb.width - cornerRadius.topRight, + bb.y + cornerRadius.topRight, + cornerRadius.topRight, 3 * M_PI / 2, 2 * M_PI); // 270° to 360° - cairo_arc(cr, bb.x + bb.width - config->cornerRadius.bottomRight, - bb.y + bb.height - config->cornerRadius.bottomRight, - config->cornerRadius.bottomRight, + cairo_arc(cr, bb.x + bb.width - cornerRadius.bottomRight, + bb.y + bb.height - cornerRadius.bottomRight, + cornerRadius.bottomRight, 0, M_PI / 2); // 0° to 90° - cairo_arc(cr, bb.x + config->cornerRadius.bottomLeft, - bb.y + bb.height - config->cornerRadius.bottomLeft, - config->cornerRadius.bottomLeft, + cairo_arc(cr, bb.x + cornerRadius.bottomLeft, + bb.y + bb.height - cornerRadius.bottomLeft, + cornerRadius.bottomLeft, M_PI / 2, M_PI); // 90° to 180° cairo_close_path(cr); @@ -229,7 +231,8 @@ void Clay_Cairo_Render(Clay_RenderCommandArray commands) { case CLAY_RENDER_COMMAND_TYPE_TEXT: { // Cairo expects null terminated strings, we need to clone // to temporarily introduce one. - char *text = Clay_Cairo__NullTerminate(&command->text); + Clay_String toTerminate = (Clay_String){ command->textOrSharedConfig.text.length, command->textOrSharedConfig.text.chars }; + char *text = Clay_Cairo__NullTerminate(&toTerminate); char *font_family = Clay_Cairo__NullTerminate(&command->config.textElementConfig->fontFamily); Clay_BoundingBox bb = command->boundingBox; @@ -252,10 +255,10 @@ void Clay_Cairo_Render(Clay_RenderCommandArray commands) { Clay_BorderElementConfig *config = command->config.borderElementConfig; Clay_BoundingBox bb = command->boundingBox; - double top_left_radius = config->cornerRadius.topLeft / 2.0; - double top_right_radius = config->cornerRadius.topRight / 2.0; - double bottom_right_radius = config->cornerRadius.bottomRight / 2.0; - double bottom_left_radius = config->cornerRadius.bottomLeft / 2.0; + double top_left_radius = cornerRadius.topLeft / 2.0; + double top_right_radius = cornerRadius.topRight / 2.0; + double bottom_right_radius = cornerRadius.bottomRight / 2.0; + double bottom_left_radius = cornerRadius.bottomLeft / 2.0; // Draw the top border if (config->top.width > 0) {