From e485dfc92e8e9f7393ad3a93cde4dc0280c97987 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 15:59:51 +1200 Subject: [PATCH 01/28] test actions --- .github/workflows/cmake-multi-platform.yml | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 00000000..a93b5f7b --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,92 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Cache + uses: actions/cache@v4.0.2 + with: + # A list of files, directories, and wildcard patterns to cache and restore + path: "_deps" + # An explicit key for restoring and saving the cache + key: "_deps" + + - name: Install Dependencies + run: | + DEBIAN_FRONTEND=noninteractive apt-get install -y git + DEBIAN_FRONTEND=noninteractive apt-get install -y libwayland-dev + DEBIAN_FRONTEND=noninteractive apt-get install -y pkg-config + DEBIAN_FRONTEND=noninteractive apt-get install -y libxkbcommon-dev + DEBIAN_FRONTEND=noninteractive apt-get install -y xorg-dev + + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} From b533c321847443f055df85002c15d42116272a20 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:04:08 +1200 Subject: [PATCH 02/28] Add sudo and disable step on windows --- .github/workflows/cmake-multi-platform.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index a93b5f7b..6acd706a 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -63,12 +63,13 @@ jobs: key: "_deps" - name: Install Dependencies + if: runner.os == 'Linux' run: | - DEBIAN_FRONTEND=noninteractive apt-get install -y git - DEBIAN_FRONTEND=noninteractive apt-get install -y libwayland-dev - DEBIAN_FRONTEND=noninteractive apt-get install -y pkg-config - DEBIAN_FRONTEND=noninteractive apt-get install -y libxkbcommon-dev - DEBIAN_FRONTEND=noninteractive apt-get install -y xorg-dev + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y git + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y libwayland-dev + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y pkg-config + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y libxkbcommon-dev + DEBIAN_FRONTEND=noninteractive sudo apt-get install -y xorg-dev - name: Configure CMake From 9a0b29b7125a5615e46f474fb7add46dfd09dfc6 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:13:31 +1200 Subject: [PATCH 03/28] fix cache and msvc --- .github/workflows/cmake-multi-platform.yml | 2 +- examples/clay-official-website/CMakeLists.txt | 2 ++ examples/raylib-sidebar-scrolling-container/CMakeLists.txt | 2 ++ 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 6acd706a..0c05d918 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -58,7 +58,7 @@ jobs: uses: actions/cache@v4.0.2 with: # A list of files, directories, and wildcard patterns to cache and restore - path: "_deps" + path: "/home/runner/work/clay/clay/build/_deps/raylib-subbuild" # An explicit key for restoring and saving the cache key: "_deps" diff --git a/examples/clay-official-website/CMakeLists.txt b/examples/clay-official-website/CMakeLists.txt index 65087bbc..bca47c8d 100644 --- a/examples/clay-official-website/CMakeLists.txt +++ b/examples/clay-official-website/CMakeLists.txt @@ -5,7 +5,9 @@ set(CMAKE_C_STANDARD 99) add_executable(clay_official_website main.c) +if(!MSVC) target_compile_options(clay_official_website PUBLIC -Wall -Werror -Wno-unknown-pragmas) +endif() target_include_directories(clay_official_website PUBLIC .) set(CMAKE_CXX_FLAGS_RELEASE "-O3") \ No newline at end of file diff --git a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt index 7fe58fd4..1499b58a 100644 --- a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt +++ b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt @@ -21,7 +21,9 @@ set(CMAKE_C_STANDARD 99) add_executable(clay_examples_raylib_sidebar_scrolling_container main.c multi-compilation-unit.c) +if(!MSVC) target_compile_options(clay_examples_raylib_sidebar_scrolling_container PUBLIC -Wall -Werror -Wno-unknown-pragmas) +endif() target_include_directories(clay_examples_raylib_sidebar_scrolling_container PUBLIC .) target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib) From e5e39d12e9096b6e388d32c40516993a68285ddc Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:21:22 +1200 Subject: [PATCH 04/28] Test msvc replacement for attribute packed --- clay.h | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/clay.h b/clay.h index ac9e1c65..6ac89fa8 100644 --- a/clay.h +++ b/clay.h @@ -28,6 +28,12 @@ #define CLAY_WASM_EXPORT(null) #endif +#ifdef MSC_VER +#define CLAY_PACKED_ENUM : unsigned char +#else +#define CLAY_PACKED_ENUM __attribute__((__packed__)) +#endif + // Public Macro API ------------------------ #define CLAY_LAYOUT(...) Clay__StoreLayoutConfig((Clay_LayoutConfig) {__VA_ARGS__ }) @@ -158,24 +164,24 @@ typedef struct { // Element Configs --------------------------- // Layout -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY_LEFT_TO_RIGHT, CLAY_TOP_TO_BOTTOM, } Clay_LayoutDirection; -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY_ALIGN_X_LEFT, CLAY_ALIGN_X_RIGHT, CLAY_ALIGN_X_CENTER, } Clay_LayoutAlignmentX; -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY_ALIGN_Y_TOP, CLAY_ALIGN_Y_BOTTOM, CLAY_ALIGN_Y_CENTER, } Clay_LayoutAlignmentY; -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY__SIZING_TYPE_FIT, CLAY__SIZING_TYPE_GROW, CLAY__SIZING_TYPE_PERCENT, @@ -260,7 +266,7 @@ typedef struct } Clay_ImageElementConfig; // Floating -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY_ATTACH_POINT_LEFT_TOP, CLAY_ATTACH_POINT_LEFT_CENTER, CLAY_ATTACH_POINT_LEFT_BOTTOM, @@ -596,7 +602,7 @@ Clay_ElementId *Clay__ElementIdArray_Add(Clay__ElementIdArray *array, Clay_Eleme #pragma endregion // __GENERATED__ template -typedef enum __attribute__((__packed__)) { +typedef enum CLAY_PACKED_ENUM { CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER, CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE, CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER, From 2def72dc6220890681a448503980a8c2356ccd88 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:24:34 +1200 Subject: [PATCH 05/28] Cache update and fix typo --- .github/workflows/cmake-multi-platform.yml | 2 +- clay.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 0c05d918..e94e0128 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -58,7 +58,7 @@ jobs: uses: actions/cache@v4.0.2 with: # A list of files, directories, and wildcard patterns to cache and restore - path: "/home/runner/work/clay/clay/build/_deps/raylib-subbuild" + path: "/home/runner/work/clay/clay/build/_deps" # An explicit key for restoring and saving the cache key: "_deps" diff --git a/clay.h b/clay.h index 6ac89fa8..f5f4c2fb 100644 --- a/clay.h +++ b/clay.h @@ -28,7 +28,7 @@ #define CLAY_WASM_EXPORT(null) #endif -#ifdef MSC_VER +#ifdef _MSC_VER #define CLAY_PACKED_ENUM : unsigned char #else #define CLAY_PACKED_ENUM __attribute__((__packed__)) From 35c6210da652907d48a932a81b98cd938defd2be Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:29:11 +1200 Subject: [PATCH 06/28] undefine packed enum for now --- clay.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clay.h b/clay.h index f5f4c2fb..1c91888e 100644 --- a/clay.h +++ b/clay.h @@ -28,8 +28,8 @@ #define CLAY_WASM_EXPORT(null) #endif -#ifdef _MSC_VER -#define CLAY_PACKED_ENUM : unsigned char +#ifdef MSC_VER +#define CLAY_PACKED_ENUM #else #define CLAY_PACKED_ENUM __attribute__((__packed__)) #endif From 4ce2339d24fb8e286a4a1a966085283fe90a86c6 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:30:46 +1200 Subject: [PATCH 07/28] typo --- clay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clay.h b/clay.h index 1c91888e..0b724dc0 100644 --- a/clay.h +++ b/clay.h @@ -28,7 +28,7 @@ #define CLAY_WASM_EXPORT(null) #endif -#ifdef MSC_VER +#ifdef _MSC_VER #define CLAY_PACKED_ENUM #else #define CLAY_PACKED_ENUM __attribute__((__packed__)) From fffe56693146b7ef0551accc33dcca78cbd728e8 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 16:41:44 +1200 Subject: [PATCH 08/28] try compiling as c++ on windows --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86955ec0..ca72ae08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 3.28) -project(clay C) +if (MSVC) +project(clay CXX) +set(CMAKE_CXX_STANDARD 20) +else () +project(clay C) set(CMAKE_C_STANDARD 99) +endif() add_subdirectory("examples/raylib-sidebar-scrolling-container") add_subdirectory("examples/clay-official-website") \ No newline at end of file From ee1e1bb95f977fef8ea6b5aa9a9ed1f5987309ee Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 19:33:23 +1200 Subject: [PATCH 09/28] C++ only on windows --- CMakeLists.txt | 15 ++++------ clay.h | 28 +++++++++++-------- examples/cpp-project-example/CMakeLists.txt | 12 ++++++++ examples/cpp-project-example/main.cpp | 10 +++++++ .../CMakeLists.txt | 9 ++---- 5 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 examples/cpp-project-example/CMakeLists.txt create mode 100644 examples/cpp-project-example/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ca72ae08..1cf2e6d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,9 @@ cmake_minimum_required(VERSION 3.28) +project(clay) -if (MSVC) -project(clay CXX) -set(CMAKE_CXX_STANDARD 20) -else () -project(clay C) -set(CMAKE_C_STANDARD 99) -endif() - +if(MSVC) +add_subdirectory("examples/cpp-project-example") +elseif() add_subdirectory("examples/raylib-sidebar-scrolling-container") -add_subdirectory("examples/clay-official-website") \ No newline at end of file +add_subdirectory("examples/clay-official-website") +endif() \ No newline at end of file diff --git a/clay.h b/clay.h index 0b724dc0..f6d7c5da 100644 --- a/clay.h +++ b/clay.h @@ -452,7 +452,11 @@ extern uint32_t Clay__debugViewWidth; #define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y)) #define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y)) -#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x)) +#ifdef __cplusplus +#define CLAY__ALIGNMENT(type) alignof(type) +#elif +#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; } a, a.x)) +#endif bool Clay__warningsEnabled = true; @@ -614,14 +618,14 @@ typedef enum CLAY_PACKED_ENUM { } Clay__LayoutElementType; Clay_RenderCommandType Clay__LayoutElementTypeToRenderCommandType[] = { - [CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE, - [CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE] = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, - [CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE, - [CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE, - [CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_BORDER, - [CLAY__LAYOUT_ELEMENT_TYPE_IMAGE] = CLAY_RENDER_COMMAND_TYPE_IMAGE, - [CLAY__LAYOUT_ELEMENT_TYPE_TEXT] = CLAY_RENDER_COMMAND_TYPE_TEXT, - [CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM] = CLAY_RENDER_COMMAND_TYPE_CUSTOM, + CLAY_RENDER_COMMAND_TYPE_NONE, + CLAY_RENDER_COMMAND_TYPE_RECTANGLE, + CLAY_RENDER_COMMAND_TYPE_NONE, + CLAY_RENDER_COMMAND_TYPE_NONE, + CLAY_RENDER_COMMAND_TYPE_BORDER, + CLAY_RENDER_COMMAND_TYPE_IMAGE, + CLAY_RENDER_COMMAND_TYPE_TEXT, + CLAY_RENDER_COMMAND_TYPE_CUSTOM, }; Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){}; @@ -1414,7 +1418,7 @@ uint32_t Clay__HashTextWithConfig(Clay_String *text, Clay_TextElementConfig *con union { float fontSize; uint32_t bits; - } fontSizeBits = { .fontSize = config->fontSize }; + } fontSizeBits = { .fontSize = (float)config->fontSize }; uint32_t hash = 0; uint64_t pointerAsNumber = (uint64_t)text->chars; @@ -1615,8 +1619,8 @@ void Clay__OpenFloatingElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfi Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1, .parentId = parent->id, + .clipElementId = (uint32_t)(originalParentId == 0 ? (Clay__openClipElementStack.length > 0 ? Clay__int32_tArray_Get(&Clay__openClipElementStack, (int)Clay__openClipElementStack.length - 1) : 0) : 0), .zIndex = floatingConfig->zIndex, - .clipElementId = originalParentId == 0 ? (Clay__openClipElementStack.length > 0 ? Clay__int32_tArray_Get(&Clay__openClipElementStack, (int)Clay__openClipElementStack.length - 1) : 0) : 0, }); } @@ -2757,7 +2761,7 @@ void Clay__RenderDebugView() { highlightedRow = -1; } Clay__RenderDebugLayoutData layoutData = {}; - CLAY_FLOATING_CONTAINER(CLAY_ID("Clay__DebugView"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED(Clay__debugViewWidth) , CLAY_SIZING_FIXED(Clay__layoutDimensions.height) }), CLAY_FLOATING_CONFIG(.attachment = { .element = CLAY_ATTACH_POINT_LEFT_CENTER, .parent = CLAY_ATTACH_POINT_RIGHT_CENTER })) { + CLAY_FLOATING_CONTAINER(CLAY_ID("Clay__DebugView"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED((float)Clay__debugViewWidth) , CLAY_SIZING_FIXED(Clay__layoutDimensions.height) }), CLAY_FLOATING_CONFIG(.attachment = { .element = CLAY_ATTACH_POINT_LEFT_CENTER, .parent = CLAY_ATTACH_POINT_RIGHT_CENTER })) { CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewLeftBorder"), CLAY_LAYOUT(.sizing = { .width = CLAY_SIZING_FIXED(1), .height = CLAY_SIZING_GROW() }), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} CLAY_CONTAINER(CLAY_ID("Clay__DebugViewInner"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()})) { CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderOuter"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { diff --git a/examples/cpp-project-example/CMakeLists.txt b/examples/cpp-project-example/CMakeLists.txt new file mode 100644 index 00000000..6ebaae76 --- /dev/null +++ b/examples/cpp-project-example/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.28) +project(clay_examples_cpp_project_example CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g") + +add_executable(clay_examples_cpp_project_example main.cpp) + +target_include_directories(clay_examples_cpp_project_example PUBLIC .) + +set(CMAKE_CXX_FLAGS_DEBUG "-Wall") +set(CMAKE_CXX_FLAGS_RELEASE "-O3") \ No newline at end of file diff --git a/examples/cpp-project-example/main.cpp b/examples/cpp-project-example/main.cpp new file mode 100644 index 00000000..9048d257 --- /dev/null +++ b/examples/cpp-project-example/main.cpp @@ -0,0 +1,10 @@ +#include +#define CLAY_IMPLEMENTATION +#include "../../clay.h" + +int main(void) { + uint64_t totalMemorySize = Clay_MinMemorySize(); + Clay_Arena clayMemory = (Clay_Arena) { .label = CLAY_STRING("Clay Memory Arena"), .capacity = totalMemorySize, .memory = (char *)malloc(totalMemorySize) }; + Clay_Initialize(clayMemory, (Clay_Dimensions) {1024,768}); + return 0; +} diff --git a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt index 1499b58a..15b0a1d2 100644 --- a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt +++ b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.28) -project(clay_examples_raylib_sidebar_scrolling_container C) +project(clay_examples_raylib_sidebar_scrolling_container) + +target_compile_options(clay_examples_raylib_sidebar_scrolling_container PUBLIC -Wall -Werror -Wno-unknown-pragmas) # Adding Raylib include(FetchContent) @@ -17,13 +19,8 @@ FetchContent_Declare( FetchContent_MakeAvailable(raylib) -set(CMAKE_C_STANDARD 99) - add_executable(clay_examples_raylib_sidebar_scrolling_container main.c multi-compilation-unit.c) -if(!MSVC) -target_compile_options(clay_examples_raylib_sidebar_scrolling_container PUBLIC -Wall -Werror -Wno-unknown-pragmas) -endif() target_include_directories(clay_examples_raylib_sidebar_scrolling_container PUBLIC .) target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib) From 9211595821cec0e37e0ec9d2d60ad1aaaa3f6134 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 20:54:41 +1200 Subject: [PATCH 10/28] Try CLAY__INIT replacement --- CMakeLists.txt | 6 +++--- clay.h | 8 +++++--- .../raylib-sidebar-scrolling-container/CMakeLists.txt | 5 ++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1cf2e6d8..9bbe6d11 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.28) project(clay) -if(MSVC) -add_subdirectory("examples/cpp-project-example") -elseif() +if(!MSVC) add_subdirectory("examples/raylib-sidebar-scrolling-container") add_subdirectory("examples/clay-official-website") +else() +add_subdirectory("examples/cpp-project-example") endif() \ No newline at end of file diff --git a/clay.h b/clay.h index f6d7c5da..750e9834 100644 --- a/clay.h +++ b/clay.h @@ -454,14 +454,16 @@ extern uint32_t Clay__debugViewWidth; #ifdef __cplusplus #define CLAY__ALIGNMENT(type) alignof(type) +#define CLAY__INIT(type) type #elif +#define CLAY__INIT(type) (type) #define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; } a, a.x)) #endif bool Clay__warningsEnabled = true; -Clay_String CLAY__SPACECHAR = (Clay_String) { .length = 1, .chars = " " }; -Clay_String CLAY__STRING_DEFAULT = (Clay_String) { .length = 0, .chars = "" }; +Clay_String CLAY__SPACECHAR = CLAY__INIT(Clay_String) { .length = 1, .chars = " " }; +Clay_String CLAY__STRING_DEFAULT = CLAY__INIT(Clay_String) { .length = 0, .chars = "" }; typedef struct { @@ -652,7 +654,7 @@ Clay_LayoutConfig *Clay__LayoutConfigArray_Add(Clay__LayoutConfigArray *array, C #pragma endregion // __GENERATED__ template -Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = (Clay_RectangleElementConfig){0}; +Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = (Clay_RectangleElementConfig){{0}}; // __GENERATED__ template array_define,array_add TYPE=Clay_RectangleElementConfig NAME=Clay__RectangleElementConfigArray DEFAULT_VALUE=&CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT #pragma region generated diff --git a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt index 15b0a1d2..9d185d18 100644 --- a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt +++ b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt @@ -1,7 +1,5 @@ cmake_minimum_required(VERSION 3.28) -project(clay_examples_raylib_sidebar_scrolling_container) - -target_compile_options(clay_examples_raylib_sidebar_scrolling_container PUBLIC -Wall -Werror -Wno-unknown-pragmas) +project(clay_examples_raylib_sidebar_scrolling_container C) # Adding Raylib include(FetchContent) @@ -21,6 +19,7 @@ FetchContent_MakeAvailable(raylib) add_executable(clay_examples_raylib_sidebar_scrolling_container main.c multi-compilation-unit.c) +target_compile_options(clay_examples_raylib_sidebar_scrolling_container PUBLIC -Wall -Werror -Wno-unknown-pragmas) target_include_directories(clay_examples_raylib_sidebar_scrolling_container PUBLIC .) target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib) From 27ec3331fdb3ec292ea208eed50865946a521546 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:02:10 +1200 Subject: [PATCH 11/28] More fixes for msvc --- clay.h | 92 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/clay.h b/clay.h index 750e9834..bf703e9f 100644 --- a/clay.h +++ b/clay.h @@ -36,7 +36,7 @@ // Public Macro API ------------------------ -#define CLAY_LAYOUT(...) Clay__StoreLayoutConfig((Clay_LayoutConfig) {__VA_ARGS__ }) +#define CLAY_LAYOUT(...) Clay__StoreLayoutConfig(CLAY__INIT(Clay_LayoutConfig) {__VA_ARGS__ }) #define CLAY_RECTANGLE_CONFIG(...) Clay__StoreRectangleElementConfig((Clay_RectangleElementConfig) {__VA_ARGS__ }) @@ -62,13 +62,13 @@ #define CLAY_CORNER_RADIUS(radius) (Clay_CornerRadius) { radius, radius, radius, radius } -#define CLAY_SIZING_FIT(...) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_FIT, .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__} } +#define CLAY_SIZING_FIT(...) (Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_FIT } -#define CLAY_SIZING_GROW(...) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_GROW, .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__} } +#define CLAY_SIZING_GROW(...) (Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_GROW } -#define CLAY_SIZING_FIXED(fixedSize) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_GROW, .sizeMinMax = { fixedSize, fixedSize } } +#define CLAY_SIZING_FIXED(fixedSize) (Clay_SizingAxis) { .sizeMinMax = { fixedSize, fixedSize }, .type = CLAY__SIZING_TYPE_GROW } -#define CLAY_SIZING_PERCENT(percentOfParent) (Clay_SizingAxis) { .type = CLAY__SIZING_TYPE_PERCENT, .sizePercent = (percentOfParent) } +#define CLAY_SIZING_PERCENT(percentOfParent) (Clay_SizingAxis) { .sizePercent = (percentOfParent), .type = CLAY__SIZING_TYPE_PERCENT } #define CLAY_ID(label) Clay__HashString(CLAY_STRING(label), 0, 0) @@ -471,7 +471,7 @@ typedef struct Clay_String dynamicMessage; } Clay__Warning; -Clay__Warning CLAY__WARNING_DEFAULT = (Clay__Warning) {}; +Clay__Warning CLAY__WARNING_DEFAULT = CLAY__INIT(Clay__Warning) {}; #pragma region generated typedef struct @@ -483,7 +483,7 @@ typedef struct Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { uint64_t totalSizeBytes = capacity * sizeof(Clay_String); - Clay__WarningArray array = (Clay__WarningArray){.capacity = capacity, .length = 0}; + Clay__WarningArray array = CLAY__INIT(Clay__WarningArray){.capacity = capacity, .length = 0}; uint64_t nextAllocAddress = (uint64_t)(arena->nextAllocation + arena->memory); uint64_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String))); arenaOffsetAligned -= (uint64_t)arena->memory; @@ -499,7 +499,7 @@ Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Are return array; } -Clay__WarningArray Clay_warnings = (Clay__WarningArray) {}; +Clay__WarningArray Clay_warnings = CLAY__INIT(Clay__WarningArray) {}; Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning item) { @@ -527,7 +527,7 @@ void* Clay__Array_Allocate_Arena(uint32_t capacity, uint32_t itemSize, uint32_t } else { if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); @@ -542,7 +542,7 @@ bool Clay__Array_RangeCheck(int index, uint32_t length) return true; } if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Array access out of bounds.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Array access out of bounds.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); @@ -556,7 +556,7 @@ bool Clay__Array_IncrementCapacityCheck(uint32_t length, uint32_t capacity) return true; } if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Attempting to add to array that is already at capacity.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Attempting to add to array that is already at capacity.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); @@ -1133,7 +1133,7 @@ void Clay__MeasureTextCacheItemArray_Set(Clay__MeasureTextCacheItemArray *array, array->length = index < array->length ? array->length : index + 1; } else { if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); @@ -1169,7 +1169,7 @@ void Clay__int32_tArray_Set(Clay__int32_tArray *array, int index, int32_t value) array->length = index < array->length ? array->length : index + 1; } else { if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); @@ -1311,12 +1311,12 @@ typedef struct Clay__PointerInfo Clay__pointerInfo = (Clay__PointerInfo) { .position = {-1, -1} }; Clay_Dimensions Clay__layoutDimensions = (Clay_Dimensions){}; -Clay_ElementId Clay__dynamicElementIndexBaseHash = (Clay_ElementId) { .id = 128476991, .stringId = { .chars = "Auto ID", .length = 8 } }; +Clay_ElementId Clay__dynamicElementIndexBaseHash = (Clay_ElementId) { .id = 128476991, .stringId = { .length = 8, .chars = "Auto ID" } }; uint32_t Clay__dynamicElementIndex = 0; bool Clay__debugModeEnabled = false; uint32_t Clay__debugSelectedElementId = 0; uint32_t Clay__debugViewWidth = 400; -Clay_Color Clay__debugViewHighlightColor = (Clay_Color) { 168, 66, 28, 100 }; +Clay_Color Clay__debugViewHighlightColor = CLAY__INIT(Clay_Color) { 168, 66, 28, 100 }; uint32_t Clay__generation = 0; uint64_t Clay__arenaResetOffset = 0; Clay_Arena Clay__internalArena; @@ -1402,7 +1402,7 @@ Clay_ElementId Clay__Rehash(Clay_ElementId elementId, uint32_t number) { id += (id << 3); id ^= (id >> 11); id += (id << 15); - return (Clay_ElementId) { .stringId = elementId.stringId, .id = id, .offset = number, .baseId = elementId.baseId }; + return (Clay_ElementId) { .id = id, .offset = number, .baseId = elementId.baseId, .stringId = elementId.stringId }; } uint32_t Clay__RehashWithNumber(uint32_t id, uint32_t number) { @@ -1488,7 +1488,7 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl hashItem->debugData->collision = false; } else { // Multiple collisions this frame - two elements have the same ID if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Duplicate ID detected for element: "), Clay__WriteStringToCharBuffer(&Clay__dynamicStringData, elementId.stringId) }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Duplicate ID detected for element: "), Clay__WriteStringToCharBuffer(&Clay__dynamicStringData, elementId.stringId) }); } if (Clay__debugModeEnabled) { hashItem->debugData->collision = true; @@ -1529,7 +1529,7 @@ Clay_LayoutElement *Clay__OpenElementWithParent(Clay_ElementId elementId, Clay__ #endif .id = elementId.id, .elementType = commandType, - .minDimensions = (Clay_Dimensions) { (float)layoutConfig->padding.x * 2, (float)layoutConfig->padding.y * 2 }, + .minDimensions = CLAY__INIT(Clay_Dimensions) { (float)layoutConfig->padding.x * 2, (float)layoutConfig->padding.y * 2 }, .children = (Clay__LayoutElementChildren) { .length = 0 }, .layoutConfig = layoutConfig, .elementConfig = elementConfig, @@ -1612,7 +1612,7 @@ void Clay__OpenFloatingElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfi } else { Clay_LayoutElementHashMapItem *parentItem = Clay__GetHashMapItem(floatingConfig->parentId); if (!parentItem) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Clay Warning: Couldn't find parent container to attach floating container to.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Clay Warning: Couldn't find parent container to attach floating container to.") }); } else { parent = parentItem->layoutElement; } @@ -1697,7 +1697,7 @@ void Clay__OpenTextElement(Clay_ElementId id, Clay_String text, Clay_TextElement internalElement->dimensions.width = textMeasured.width; internalElement->dimensions.height = textMeasured.height; internalElement->text = text; - internalElement->minDimensions = (Clay_Dimensions) { .width = textMeasured.height, .height = textMeasured.height }; // TODO not sure this is the best way to decide min width for text + internalElement->minDimensions = CLAY__INIT(Clay_Dimensions) { .width = textMeasured.height, .height = textMeasured.height }; // TODO not sure this is the best way to decide min width for text Clay__TextElementDataArray_Add(&Clay__textElementData, (Clay__TextElementData) { .preferredDimensions = textMeasured, .elementIndex = Clay__layoutElements.length - 1}); Clay__CloseElement(); } @@ -2039,7 +2039,7 @@ void Clay__CalculateFinalLayout() { }); containerElement->dimensions.height += lineDimensions.height + (float)(containerElement->children.length > 0 ? textConfig->lineSpacing : 0); containerElement->children.length++; - lineDimensions = (Clay_Dimensions) {}; + lineDimensions = CLAY__INIT(Clay_Dimensions) {}; Clay__int32_tArray_Add(&Clay__layoutElementChildren, (int32_t)Clay__layoutElements.length - 1); } else { // In the middle of a word @@ -2116,7 +2116,7 @@ void Clay__CalculateFinalLayout() { dfsBuffer.length = 0; Clay__LayoutElementTreeRoot *root = Clay__LayoutElementTreeRootArray_Get(&Clay__layoutElementTreeRoots, rootIndex); Clay_LayoutElement *rootElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, (int)root->layoutElementIndex); - Clay_Vector2 rootPosition = (Clay_Vector2) {}; + Clay_Vector2 rootPosition = CLAY__INIT(Clay_Vector2) {}; Clay_LayoutElementHashMapItem *parentHashMapItem = Clay__GetHashMapItem(root->parentId); // Position root floating containers if (rootElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER && parentHashMapItem) { @@ -2183,7 +2183,7 @@ void Clay__CalculateFinalLayout() { }); } } - Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, (Clay__LayoutElementTreeNode) { .layoutElement = rootElement, .position = rootPosition, .nextChildOffset = (Clay_Vector2) { .x = (float)rootElement->layoutConfig->padding.x, .y = (float)rootElement->layoutConfig->padding.y } }); + Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, (Clay__LayoutElementTreeNode) { .layoutElement = rootElement, .position = rootPosition, .nextChildOffset = CLAY__INIT(Clay_Vector2) { .x = (float)rootElement->layoutConfig->padding.x, .y = (float)rootElement->layoutConfig->padding.y } }); Clay__treeNodeVisited.internalArray[0] = false; while (dfsBuffer.length > 0) { @@ -2281,7 +2281,7 @@ void Clay__CalculateFinalLayout() { if (currentElementTreeNode->layoutElement->elementType != CLAY__LAYOUT_ELEMENT_TYPE_TEXT) { dfsBuffer.length += currentElement->children.length; - Clay_Dimensions contentSize = (Clay_Dimensions) {0,0}; + Clay_Dimensions contentSize = CLAY__INIT(Clay_Dimensions) {0,0}; if (layoutConfig->layoutDirection == CLAY_LEFT_TO_RIGHT) { for (int i = 0; i < currentElement->children.length; ++i) { Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, currentElement->children.elements[i]); @@ -2403,7 +2403,7 @@ void Clay__CalculateFinalLayout() { } } - Clay_Vector2 childPosition = (Clay_Vector2) { + Clay_Vector2 childPosition = CLAY__INIT(Clay_Vector2) { currentElementTreeNode->position.x + currentElementTreeNode->nextChildOffset.x + scrollOffset.x, currentElementTreeNode->position.y + currentElementTreeNode->nextChildOffset.y + scrollOffset.y, }; @@ -2412,8 +2412,8 @@ void Clay__CalculateFinalLayout() { uint32_t newNodeIndex = dfsBuffer.length - 1 - i; dfsBuffer.internalArray[newNodeIndex] = (Clay__LayoutElementTreeNode) { .layoutElement = childElement, - .position = (Clay_Vector2) { childPosition.x, childPosition.y }, - .nextChildOffset = (Clay_Vector2) { .x = (float)childElement->layoutConfig->padding.x, .y = (float)childElement->layoutConfig->padding.y }, + .position = CLAY__INIT(Clay_Vector2) { childPosition.x, childPosition.y }, + .nextChildOffset = CLAY__INIT(Clay_Vector2) { .x = (float)childElement->layoutConfig->padding.x, .y = (float)childElement->layoutConfig->padding.y }, }; Clay__treeNodeVisited.internalArray[newNodeIndex] = false; @@ -2443,16 +2443,16 @@ inline Clay_ScrollElementConfig * Clay__StoreScrollElementConfig(Clay_ScrollElem inline Clay_BorderElementConfig * Clay__StoreBorderElementConfig(Clay_BorderElementConfig config) { return Clay__BorderElementConfigArray_Add(&Clay__borderElementConfigs, config); } #pragma region DebugTools -Clay_Color CLAY__DEBUGVIEW_COLOR_1 = (Clay_Color) {58, 56, 52, 255}; -Clay_Color CLAY__DEBUGVIEW_COLOR_2 = (Clay_Color) {62, 60, 58, 255}; -Clay_Color CLAY__DEBUGVIEW_COLOR_3 = (Clay_Color) {141, 133, 135, 255}; -Clay_Color CLAY__DEBUGVIEW_COLOR_4 = (Clay_Color) {238, 226, 231, 255}; -Clay_Color CLAY__DEBUGVIEW_COLOR_SELECTED_ROW = (Clay_Color) {102, 80, 78, 255}; +Clay_Color CLAY__DEBUGVIEW_COLOR_1 = CLAY__INIT(Clay_Color) {58, 56, 52, 255}; +Clay_Color CLAY__DEBUGVIEW_COLOR_2 = CLAY__INIT(Clay_Color) {62, 60, 58, 255}; +Clay_Color CLAY__DEBUGVIEW_COLOR_3 = CLAY__INIT(Clay_Color) {141, 133, 135, 255}; +Clay_Color CLAY__DEBUGVIEW_COLOR_4 = CLAY__INIT(Clay_Color) {238, 226, 231, 255}; +Clay_Color CLAY__DEBUGVIEW_COLOR_SELECTED_ROW = CLAY__INIT(Clay_Color) {102, 80, 78, 255}; const int CLAY__DEBUGVIEW_ROW_HEIGHT = 30; const int CLAY__DEBUGVIEW_OUTER_PADDING = 10; const int CLAY__DEBUGVIEW_INDENT_WIDTH = 16; -Clay_TextElementConfig Clay__DebugView_TextNameConfig = (Clay_TextElementConfig) {.fontSize = 16, .textColor = {238, 226, 231, 255}, .wrapMode = CLAY_TEXT_WRAP_NONE }; -Clay_LayoutConfig Clay__DebugView_ScrollViewItemLayoutConfig = (Clay_LayoutConfig) {}; +Clay_TextElementConfig Clay__DebugView_TextNameConfig = (Clay_TextElementConfig) {.textColor = {238, 226, 231, 255}, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }; +Clay_LayoutConfig Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_LayoutConfig) {}; Clay_String Clay__IntToString(int integer) { if (integer == 0) { @@ -2510,7 +2510,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay_ElementId textContentsOuterId = CLAY_ID("Clay__DebugView_ElementTextContentsOuter"); Clay_ElementId textContentsId = CLAY_ID("Clay__DebugView_ElementTextContents"); Clay__int32_tArray dfsBuffer = Clay__reusableElementIndexBuffer; - Clay__DebugView_ScrollViewItemLayoutConfig = (Clay_LayoutConfig) { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT) }, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }, .childGap = 6}; + Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_LayoutConfig) { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT) }, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }, .childGap = 6}; Clay__RenderDebugLayoutData layoutData = {}; uint32_t highlightedElementId = 0; @@ -2586,14 +2586,14 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay_String elementTypeName = (Clay_String){}; Clay_Color elementTypeColor = (Clay_Color){}; switch (currentElement->elementType) { - case CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE: elementTypeName = CLAY_STRING("Rectangle"); elementTypeColor = ((Clay_Color) {243,134,48,255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER: elementTypeName = CLAY_STRING("Container"); elementTypeColor = ((Clay_Color) {53,92,125, 255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_TEXT: elementTypeName = CLAY_STRING("Text"); elementTypeColor = ((Clay_Color) {105,210,231,255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_IMAGE: elementTypeName = CLAY_STRING("Image"); elementTypeColor = ((Clay_Color) {121,189,154,255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER: elementTypeName = CLAY_STRING("Floating"); elementTypeColor = ((Clay_Color) {250,105,0,255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER: elementTypeName = CLAY_STRING("Scroll"); elementTypeColor = ((Clay_Color) {242,196,90,255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER: elementTypeName = CLAY_STRING("Border"); elementTypeColor = ((Clay_Color) {108,91,123, 255}); break; - case CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM: elementTypeName = CLAY_STRING("Custom"); elementTypeColor = ((Clay_Color) {11,72,107,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE: elementTypeName = CLAY_STRING("Rectangle"); elementTypeColor = (CLAY__INIT(Clay_Color) {243,134,48,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER: elementTypeName = CLAY_STRING("Container"); elementTypeColor = (CLAY__INIT(Clay_Color) {53,92,125, 255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_TEXT: elementTypeName = CLAY_STRING("Text"); elementTypeColor = (CLAY__INIT(Clay_Color) {105,210,231,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_IMAGE: elementTypeName = CLAY_STRING("Image"); elementTypeColor = (CLAY__INIT(Clay_Color) {121,189,154,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER: elementTypeName = CLAY_STRING("Floating"); elementTypeColor = (CLAY__INIT(Clay_Color) {250,105,0,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER: elementTypeName = CLAY_STRING("Scroll"); elementTypeColor = (CLAY__INIT(Clay_Color) {242,196,90,255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER: elementTypeName = CLAY_STRING("Border"); elementTypeColor = (CLAY__INIT(Clay_Color) {108,91,123, 255}); break; + case CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM: elementTypeName = CLAY_STRING("Custom"); elementTypeColor = (CLAY__INIT(Clay_Color) {11,72,107,255}); break; } Clay_Color backgroundColor = elementTypeColor; backgroundColor.a = 90; @@ -3259,12 +3259,12 @@ void Clay_BeginLayout() { Clay__generation++; Clay__dynamicElementIndex = 0; // Set up the root container that covers the entire window - Clay_Dimensions rootDimensions = (Clay_Dimensions) {Clay__layoutDimensions.width, Clay__layoutDimensions.height}; + Clay_Dimensions rootDimensions = CLAY__INIT(Clay_Dimensions) {Clay__layoutDimensions.width, Clay__layoutDimensions.height}; if (Clay__debugModeEnabled) { rootDimensions.width -= (float)Clay__debugViewWidth; } Clay_ElementId rootElementId = CLAY_ID("Clay__RootContainer"); - Clay_LayoutElement rootLayoutElement = (Clay_LayoutElement){.id = rootElementId.id, .layoutConfig = CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)})}; + Clay_LayoutElement rootLayoutElement = (Clay_LayoutElement){.layoutConfig = CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)}), .id = rootElementId.id, }; Clay__openLayoutElement = Clay_LayoutElementArray_Add(&Clay__layoutElements, rootLayoutElement); Clay__LayoutElementPointerArray_Add(&Clay__openLayoutElementStack, Clay__openLayoutElement); Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1 }); @@ -3306,7 +3306,7 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) { if (scrollContainerData->elementId == id.id) { return (Clay_ScrollContainerData) { .scrollPosition = &scrollContainerData->scrollPosition, - .scrollContainerDimensions = (Clay_Dimensions) { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height }, + .scrollContainerDimensions = CLAY__INIT(Clay_Dimensions) { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height }, .contentDimensions = scrollContainerData->contentSize, .config = *scrollContainerData->layoutElement->elementConfig.scrollElementConfig, .found = true From 165085e70dbffb9d4babf19f31536f5b800d22f9 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:05:33 +1200 Subject: [PATCH 12/28] fix init for clay_string --- clay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clay.h b/clay.h index bf703e9f..ccd8a109 100644 --- a/clay.h +++ b/clay.h @@ -80,7 +80,7 @@ #define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0])) -#define CLAY_STRING(string) (Clay_String) { .length = CLAY__STRING_LENGTH(string), .chars = (string) } +#define CLAY_STRING(string) CLAY__INIT(Clay_String) { .length = CLAY__STRING_LENGTH(string), .chars = (string) } static int CLAY__ELEMENT_DEFINITION_LATCH = 0; From e0c1380715f06f4c0f8aaf4d0d259edc2d679f52 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:08:35 +1200 Subject: [PATCH 13/28] Fix generated --- clay.h | 46 +++++++++++++++---------------- generator/array_define.template.c | 2 +- generator/array_set.template.c | 2 +- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/clay.h b/clay.h index ccd8a109..4e08248d 100644 --- a/clay.h +++ b/clay.h @@ -576,7 +576,7 @@ typedef struct } Clay__BoolArray; Clay__BoolArray Clay__BoolArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__BoolArray){.capacity = capacity, .length = 0, .internalArray = (bool *)Clay__Array_Allocate_Arena(capacity, sizeof(bool), CLAY__ALIGNMENT(bool), arena)}; + return CLAY__INIT(Clay__BoolArray){.capacity = capacity, .length = 0, .internalArray = (bool *)Clay__Array_Allocate_Arena(capacity, sizeof(bool), CLAY__ALIGNMENT(bool), arena)}; } #pragma endregion // __GENERATED__ template @@ -593,7 +593,7 @@ typedef struct } Clay__ElementIdArray; Clay__ElementIdArray Clay__ElementIdArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__ElementIdArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ElementId *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ElementId), CLAY__ALIGNMENT(Clay_ElementId), arena)}; + return CLAY__INIT(Clay__ElementIdArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ElementId *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ElementId), CLAY__ALIGNMENT(Clay_ElementId), arena)}; } Clay_ElementId *Clay__ElementIdArray_Get(Clay__ElementIdArray *array, int index) { return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : &CLAY__ELEMENT_ID_DEFAULT; @@ -642,7 +642,7 @@ typedef struct } Clay__LayoutConfigArray; Clay__LayoutConfigArray Clay__LayoutConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__LayoutConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutConfig), CLAY__ALIGNMENT(Clay_LayoutConfig), arena)}; + return CLAY__INIT(Clay__LayoutConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutConfig), CLAY__ALIGNMENT(Clay_LayoutConfig), arena)}; } Clay_LayoutConfig *Clay__LayoutConfigArray_Add(Clay__LayoutConfigArray *array, Clay_LayoutConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -666,7 +666,7 @@ typedef struct } Clay__RectangleElementConfigArray; Clay__RectangleElementConfigArray Clay__RectangleElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__RectangleElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RectangleElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RectangleElementConfig), CLAY__ALIGNMENT(Clay_RectangleElementConfig), arena)}; + return CLAY__INIT(Clay__RectangleElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RectangleElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RectangleElementConfig), CLAY__ALIGNMENT(Clay_RectangleElementConfig), arena)}; } Clay_RectangleElementConfig *Clay__RectangleElementConfigArray_Add(Clay__RectangleElementConfigArray *array, Clay_RectangleElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -690,7 +690,7 @@ typedef struct } Clay__TextElementConfigArray; Clay__TextElementConfigArray Clay__TextElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__TextElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_TextElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_TextElementConfig), CLAY__ALIGNMENT(Clay_TextElementConfig), arena)}; + return CLAY__INIT(Clay__TextElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_TextElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_TextElementConfig), CLAY__ALIGNMENT(Clay_TextElementConfig), arena)}; } Clay_TextElementConfig *Clay__TextElementConfigArray_Add(Clay__TextElementConfigArray *array, Clay_TextElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -714,7 +714,7 @@ typedef struct } Clay__ImageElementConfigArray; Clay__ImageElementConfigArray Clay__ImageElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__ImageElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ImageElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ImageElementConfig), CLAY__ALIGNMENT(Clay_ImageElementConfig), arena)}; + return CLAY__INIT(Clay__ImageElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ImageElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ImageElementConfig), CLAY__ALIGNMENT(Clay_ImageElementConfig), arena)}; } Clay_ImageElementConfig *Clay__ImageElementConfigArray_Add(Clay__ImageElementConfigArray *array, Clay_ImageElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -738,7 +738,7 @@ typedef struct } Clay__FloatingElementConfigArray; Clay__FloatingElementConfigArray Clay__FloatingElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__FloatingElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_FloatingElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_FloatingElementConfig), CLAY__ALIGNMENT(Clay_FloatingElementConfig), arena)}; + return CLAY__INIT(Clay__FloatingElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_FloatingElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_FloatingElementConfig), CLAY__ALIGNMENT(Clay_FloatingElementConfig), arena)}; } Clay_FloatingElementConfig *Clay__FloatingElementConfigArray_Add(Clay__FloatingElementConfigArray *array, Clay_FloatingElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -762,7 +762,7 @@ typedef struct } Clay__CustomElementConfigArray; Clay__CustomElementConfigArray Clay__CustomElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__CustomElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_CustomElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_CustomElementConfig), CLAY__ALIGNMENT(Clay_CustomElementConfig), arena)}; + return CLAY__INIT(Clay__CustomElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_CustomElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_CustomElementConfig), CLAY__ALIGNMENT(Clay_CustomElementConfig), arena)}; } Clay_CustomElementConfig *Clay__CustomElementConfigArray_Add(Clay__CustomElementConfigArray *array, Clay_CustomElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -786,7 +786,7 @@ typedef struct } Clay__ScrollElementConfigArray; Clay__ScrollElementConfigArray Clay__ScrollElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__ScrollElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ScrollElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ScrollElementConfig), CLAY__ALIGNMENT(Clay_ScrollElementConfig), arena)}; + return CLAY__INIT(Clay__ScrollElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_ScrollElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_ScrollElementConfig), CLAY__ALIGNMENT(Clay_ScrollElementConfig), arena)}; } Clay_ScrollElementConfig *Clay__ScrollElementConfigArray_Add(Clay__ScrollElementConfigArray *array, Clay_ScrollElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -816,7 +816,7 @@ typedef struct } Clay__TextElementDataArray; Clay__TextElementDataArray Clay__TextElementDataArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__TextElementDataArray){.capacity = capacity, .length = 0, .internalArray = (Clay__TextElementData *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__TextElementData), CLAY__ALIGNMENT(Clay__TextElementData), arena)}; + return CLAY__INIT(Clay__TextElementDataArray){.capacity = capacity, .length = 0, .internalArray = (Clay__TextElementData *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__TextElementData), CLAY__ALIGNMENT(Clay__TextElementData), arena)}; } Clay__TextElementData *Clay__TextElementDataArray_Get(Clay__TextElementDataArray *array, int index) { return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : &CLAY__TEXT_ELEMENT_DATA_DEFAULT; @@ -843,7 +843,7 @@ typedef struct } Clay__BorderElementConfigArray; Clay__BorderElementConfigArray Clay__BorderElementConfigArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__BorderElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_BorderElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_BorderElementConfig), CLAY__ALIGNMENT(Clay_BorderElementConfig), arena)}; + return CLAY__INIT(Clay__BorderElementConfigArray){.capacity = capacity, .length = 0, .internalArray = (Clay_BorderElementConfig *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_BorderElementConfig), CLAY__ALIGNMENT(Clay_BorderElementConfig), arena)}; } Clay_BorderElementConfig *Clay__BorderElementConfigArray_Add(Clay__BorderElementConfigArray *array, Clay_BorderElementConfig item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -890,7 +890,7 @@ typedef struct } Clay_LayoutElementArray; Clay_LayoutElementArray Clay_LayoutElementArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay_LayoutElementArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElement *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElement), CLAY__ALIGNMENT(Clay_LayoutElement), arena)}; + return CLAY__INIT(Clay_LayoutElementArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElement *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElement), CLAY__ALIGNMENT(Clay_LayoutElement), arena)}; } Clay_LayoutElement *Clay_LayoutElementArray_Add(Clay_LayoutElementArray *array, Clay_LayoutElement item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -915,7 +915,7 @@ typedef struct } Clay__LayoutElementPointerArray; Clay__LayoutElementPointerArray Clay__LayoutElementPointerArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__LayoutElementPointerArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElement* *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElement*), CLAY__ALIGNMENT(Clay_LayoutElement*), arena)}; + return CLAY__INIT(Clay__LayoutElementPointerArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElement* *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElement*), CLAY__ALIGNMENT(Clay_LayoutElement*), arena)}; } Clay_LayoutElement* *Clay__LayoutElementPointerArray_Add(Clay__LayoutElementPointerArray *array, Clay_LayoutElement* item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -944,7 +944,7 @@ Clay_RenderCommand CLAY__RENDER_COMMAND_DEFAULT = (Clay_RenderCommand) {}; // __GENERATED__ template array_define TYPE=Clay_RenderCommand NAME=Clay_RenderCommandArray #pragma region generated Clay_RenderCommandArray Clay_RenderCommandArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay_RenderCommandArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RenderCommand *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RenderCommand), CLAY__ALIGNMENT(Clay_RenderCommand), arena)}; + return CLAY__INIT(Clay_RenderCommandArray){.capacity = capacity, .length = 0, .internalArray = (Clay_RenderCommand *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_RenderCommand), CLAY__ALIGNMENT(Clay_RenderCommand), arena)}; } #pragma endregion // __GENERATED__ template @@ -997,7 +997,7 @@ typedef struct } Clay__ScrollContainerDataInternalArray; Clay__ScrollContainerDataInternalArray Clay__ScrollContainerDataInternalArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__ScrollContainerDataInternalArray){.capacity = capacity, .length = 0, .internalArray = (Clay__ScrollContainerDataInternal *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__ScrollContainerDataInternal), CLAY__ALIGNMENT(Clay__ScrollContainerDataInternal), arena)}; + return CLAY__INIT(Clay__ScrollContainerDataInternalArray){.capacity = capacity, .length = 0, .internalArray = (Clay__ScrollContainerDataInternal *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__ScrollContainerDataInternal), CLAY__ALIGNMENT(Clay__ScrollContainerDataInternal), arena)}; } Clay__ScrollContainerDataInternal *Clay__ScrollContainerDataInternalArray_Add(Clay__ScrollContainerDataInternalArray *array, Clay__ScrollContainerDataInternal item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -1044,7 +1044,7 @@ typedef struct } Clay__DebugElementDataArray; Clay__DebugElementDataArray Clay__DebugElementDataArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__DebugElementDataArray){.capacity = capacity, .length = 0, .internalArray = (Clay__DebugElementData *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__DebugElementData), CLAY__ALIGNMENT(Clay__DebugElementData), arena)}; + return CLAY__INIT(Clay__DebugElementDataArray){.capacity = capacity, .length = 0, .internalArray = (Clay__DebugElementData *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__DebugElementData), CLAY__ALIGNMENT(Clay__DebugElementData), arena)}; } Clay__DebugElementData *Clay__DebugElementDataArray_Add(Clay__DebugElementDataArray *array, Clay__DebugElementData item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -1081,7 +1081,7 @@ typedef struct } Clay__LayoutElementHashMapItemArray; Clay__LayoutElementHashMapItemArray Clay__LayoutElementHashMapItemArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__LayoutElementHashMapItemArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElementHashMapItem *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElementHashMapItem), CLAY__ALIGNMENT(Clay_LayoutElementHashMapItem), arena)}; + return CLAY__INIT(Clay__LayoutElementHashMapItemArray){.capacity = capacity, .length = 0, .internalArray = (Clay_LayoutElementHashMapItem *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_LayoutElementHashMapItem), CLAY__ALIGNMENT(Clay_LayoutElementHashMapItem), arena)}; } Clay_LayoutElementHashMapItem *Clay__LayoutElementHashMapItemArray_Get(Clay__LayoutElementHashMapItemArray *array, int index) { return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : &CLAY__LAYOUT_ELEMENT_HASH_MAP_ITEM_DEFAULT; @@ -1115,7 +1115,7 @@ typedef struct } Clay__MeasureTextCacheItemArray; Clay__MeasureTextCacheItemArray Clay__MeasureTextCacheItemArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__MeasureTextCacheItemArray){.capacity = capacity, .length = 0, .internalArray = (Clay__MeasureTextCacheItem *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__MeasureTextCacheItem), CLAY__ALIGNMENT(Clay__MeasureTextCacheItem), arena)}; + return CLAY__INIT(Clay__MeasureTextCacheItemArray){.capacity = capacity, .length = 0, .internalArray = (Clay__MeasureTextCacheItem *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__MeasureTextCacheItem), CLAY__ALIGNMENT(Clay__MeasureTextCacheItem), arena)}; } Clay__MeasureTextCacheItem *Clay__MeasureTextCacheItemArray_Get(Clay__MeasureTextCacheItemArray *array, int index) { return Clay__Array_RangeCheck(index, array->length) ? &array->internalArray[index] : &CLAY__MEASURE_TEXT_CACHE_ITEM_DEFAULT; @@ -1153,7 +1153,7 @@ typedef struct } Clay__int32_tArray; Clay__int32_tArray Clay__int32_tArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__int32_tArray){.capacity = capacity, .length = 0, .internalArray = (int32_t *)Clay__Array_Allocate_Arena(capacity, sizeof(int32_t), CLAY__ALIGNMENT(int32_t), arena)}; + return CLAY__INIT(Clay__int32_tArray){.capacity = capacity, .length = 0, .internalArray = (int32_t *)Clay__Array_Allocate_Arena(capacity, sizeof(int32_t), CLAY__ALIGNMENT(int32_t), arena)}; } int32_t Clay__int32_tArray_Get(Clay__int32_tArray *array, int index) { return Clay__Array_RangeCheck(index, array->length) ? array->internalArray[index] : -1; @@ -1200,7 +1200,7 @@ typedef struct } Clay__LayoutElementTreeNodeArray; Clay__LayoutElementTreeNodeArray Clay__LayoutElementTreeNodeArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__LayoutElementTreeNodeArray){.capacity = capacity, .length = 0, .internalArray = (Clay__LayoutElementTreeNode *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__LayoutElementTreeNode), CLAY__ALIGNMENT(Clay__LayoutElementTreeNode), arena)}; + return CLAY__INIT(Clay__LayoutElementTreeNodeArray){.capacity = capacity, .length = 0, .internalArray = (Clay__LayoutElementTreeNode *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__LayoutElementTreeNode), CLAY__ALIGNMENT(Clay__LayoutElementTreeNode), arena)}; } Clay__LayoutElementTreeNode *Clay__LayoutElementTreeNodeArray_Add(Clay__LayoutElementTreeNodeArray *array, Clay__LayoutElementTreeNode item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -1235,7 +1235,7 @@ typedef struct } Clay__LayoutElementTreeRootArray; Clay__LayoutElementTreeRootArray Clay__LayoutElementTreeRootArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__LayoutElementTreeRootArray){.capacity = capacity, .length = 0, .internalArray = (Clay__LayoutElementTreeRoot *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__LayoutElementTreeRoot), CLAY__ALIGNMENT(Clay__LayoutElementTreeRoot), arena)}; + return CLAY__INIT(Clay__LayoutElementTreeRootArray){.capacity = capacity, .length = 0, .internalArray = (Clay__LayoutElementTreeRoot *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay__LayoutElementTreeRoot), CLAY__ALIGNMENT(Clay__LayoutElementTreeRoot), arena)}; } Clay__LayoutElementTreeRoot *Clay__LayoutElementTreeRootArray_Add(Clay__LayoutElementTreeRootArray *array, Clay__LayoutElementTreeRoot item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { @@ -1260,7 +1260,7 @@ typedef struct } Clay__CharArray; Clay__CharArray Clay__CharArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__CharArray){.capacity = capacity, .length = 0, .internalArray = (uint8_t *)Clay__Array_Allocate_Arena(capacity, sizeof(uint8_t), CLAY__ALIGNMENT(uint8_t), arena)}; + return CLAY__INIT(Clay__CharArray){.capacity = capacity, .length = 0, .internalArray = (uint8_t *)Clay__Array_Allocate_Arena(capacity, sizeof(uint8_t), CLAY__ALIGNMENT(uint8_t), arena)}; } #pragma endregion // __GENERATED__ template @@ -1283,7 +1283,7 @@ typedef struct } Clay__StringArray; Clay__StringArray Clay__StringArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return (Clay__StringArray){.capacity = capacity, .length = 0, .internalArray = (Clay_String *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_String), CLAY__ALIGNMENT(Clay_String), arena)}; + return CLAY__INIT(Clay__StringArray){.capacity = capacity, .length = 0, .internalArray = (Clay_String *)Clay__Array_Allocate_Arena(capacity, sizeof(Clay_String), CLAY__ALIGNMENT(Clay_String), arena)}; } Clay_String *Clay__StringArray_Add(Clay__StringArray *array, Clay_String item) { if (Clay__Array_IncrementCapacityCheck(array->length, array->capacity)) { diff --git a/generator/array_define.template.c b/generator/array_define.template.c index 0cf42b8f..1df342b2 100644 --- a/generator/array_define.template.c +++ b/generator/array_define.template.c @@ -6,5 +6,5 @@ typedef struct } $NAME$; $NAME$ $NAME$_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { - return ($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__ALIGNMENT($TYPE$), arena)}; + return CLAY__INIT($NAME$){.capacity = capacity, .length = 0, .internalArray = ($TYPE$ *)Clay__Array_Allocate_Arena(capacity, sizeof($TYPE$), CLAY__ALIGNMENT($TYPE$), arena)}; } \ No newline at end of file diff --git a/generator/array_set.template.c b/generator/array_set.template.c index 36b560f8..31bbc6a5 100644 --- a/generator/array_set.template.c +++ b/generator/array_set.template.c @@ -4,7 +4,7 @@ void $NAME$_Set($NAME$ *array, int index, $TYPE$ value) { array->length = index < array->length ? array->length : index + 1; } else { if (Clay__warningsEnabled) { - Clay__WarningArray_Add(&Clay_warnings, (Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); + Clay__WarningArray_Add(&Clay_warnings, CLAY__INIT(Clay__Warning) { CLAY_STRING("Attempting to allocate array in arena, but arena is already at capacity and would overflow.") }); } #ifdef CLAY_OVERFLOW_TRAP raise(SIGTRAP); From da6929e5f43aed73cc5fc0879f3b15e9b7b6126e Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:12:19 +1200 Subject: [PATCH 14/28] more msvc --- clay.h | 64 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/clay.h b/clay.h index 4e08248d..82d9731d 100644 --- a/clay.h +++ b/clay.h @@ -581,7 +581,7 @@ Clay__BoolArray Clay__BoolArray_Allocate_Arena(uint32_t capacity, Clay_Arena *ar #pragma endregion // __GENERATED__ template -Clay_ElementId CLAY__ELEMENT_ID_DEFAULT = (Clay_ElementId) {}; +Clay_ElementId CLAY__ELEMENT_ID_DEFAULT = CLAY__INIT(Clay_ElementId) {}; // __GENERATED__ template array_define,array_get,array_add TYPE=Clay_ElementId NAME=Clay__ElementIdArray DEFAULT_VALUE=&CLAY__ELEMENT_ID_DEFAULT #pragma region generated @@ -630,7 +630,7 @@ Clay_RenderCommandType Clay__LayoutElementTypeToRenderCommandType[] = { CLAY_RENDER_COMMAND_TYPE_CUSTOM, }; -Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){}; +Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = CLAY__INIT(Clay_LayoutConfig){}; // __GENERATED__ template array_define,array_add TYPE=Clay_LayoutConfig NAME=Clay__LayoutConfigArray DEFAULT_VALUE=&CLAY_LAYOUT_DEFAULT #pragma region generated @@ -654,7 +654,7 @@ Clay_LayoutConfig *Clay__LayoutConfigArray_Add(Clay__LayoutConfigArray *array, C #pragma endregion // __GENERATED__ template -Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = (Clay_RectangleElementConfig){{0}}; +Clay_RectangleElementConfig CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_RectangleElementConfig){{0}}; // __GENERATED__ template array_define,array_add TYPE=Clay_RectangleElementConfig NAME=Clay__RectangleElementConfigArray DEFAULT_VALUE=&CLAY__RECTANGLE_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -678,7 +678,7 @@ Clay_RectangleElementConfig *Clay__RectangleElementConfigArray_Add(Clay__Rectang #pragma endregion // __GENERATED__ template -Clay_TextElementConfig CLAY__TEXT_ELEMENT_CONFIG_DEFAULT = (Clay_TextElementConfig) {}; +Clay_TextElementConfig CLAY__TEXT_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_TextElementConfig) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_TextElementConfig NAME=Clay__TextElementConfigArray DEFAULT_VALUE=&CLAY__TEXT_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -702,7 +702,7 @@ Clay_TextElementConfig *Clay__TextElementConfigArray_Add(Clay__TextElementConfig #pragma endregion // __GENERATED__ template -Clay_ImageElementConfig CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT = (Clay_ImageElementConfig) {}; +Clay_ImageElementConfig CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_ImageElementConfig) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_ImageElementConfig NAME=Clay__ImageElementConfigArray DEFAULT_VALUE=&CLAY__IMAGE_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -726,7 +726,7 @@ Clay_ImageElementConfig *Clay__ImageElementConfigArray_Add(Clay__ImageElementCon #pragma endregion // __GENERATED__ template -Clay_FloatingElementConfig CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT = (Clay_FloatingElementConfig) {}; +Clay_FloatingElementConfig CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_FloatingElementConfig) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_FloatingElementConfig NAME=Clay__FloatingElementConfigArray DEFAULT_VALUE=&CLAY__FLOATING_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -750,7 +750,7 @@ Clay_FloatingElementConfig *Clay__FloatingElementConfigArray_Add(Clay__FloatingE #pragma endregion // __GENERATED__ template -Clay_CustomElementConfig CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT = (Clay_CustomElementConfig) {}; +Clay_CustomElementConfig CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_CustomElementConfig) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_CustomElementConfig NAME=Clay__CustomElementConfigArray DEFAULT_VALUE=&CLAY__CUSTOM_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -774,7 +774,7 @@ Clay_CustomElementConfig *Clay__CustomElementConfigArray_Add(Clay__CustomElement #pragma endregion // __GENERATED__ template -Clay_ScrollElementConfig CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_ScrollElementConfig ) {}; +Clay_ScrollElementConfig CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_ScrollElementConfig ) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_ScrollElementConfig NAME=Clay__ScrollElementConfigArray DEFAULT_VALUE=&CLAY__SCROLL_CONTAINER_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -804,7 +804,7 @@ typedef struct Clay_Dimensions preferredDimensions; } Clay__TextElementData; -Clay__TextElementData CLAY__TEXT_ELEMENT_DATA_DEFAULT = (Clay__TextElementData) {}; +Clay__TextElementData CLAY__TEXT_ELEMENT_DATA_DEFAULT = CLAY__INIT(Clay__TextElementData) {}; // __GENERATED__ template array_define,array_get,array_add TYPE=Clay__TextElementData NAME=Clay__TextElementDataArray DEFAULT_VALUE=&CLAY__TEXT_ELEMENT_DATA_DEFAULT #pragma region generated @@ -831,7 +831,7 @@ Clay__TextElementData *Clay__TextElementDataArray_Add(Clay__TextElementDataArray #pragma endregion // __GENERATED__ template -Clay_BorderElementConfig CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT = (Clay_BorderElementConfig ) {}; +Clay_BorderElementConfig CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT = CLAY__INIT(Clay_BorderElementConfig ) {}; // __GENERATED__ template array_define,array_add TYPE=Clay_BorderElementConfig NAME=Clay__BorderElementConfigArray DEFAULT_VALUE=&CLAY__BORDER_CONTAINER_ELEMENT_CONFIG_DEFAULT #pragma region generated @@ -878,7 +878,7 @@ typedef struct t_Clay_LayoutElement Clay__LayoutElementType elementType; } Clay_LayoutElement; -Clay_LayoutElement CLAY__LAYOUT_ELEMENT_DEFAULT = (Clay_LayoutElement) {}; +Clay_LayoutElement CLAY__LAYOUT_ELEMENT_DEFAULT = CLAY__INIT(Clay_LayoutElement) {}; // __GENERATED__ template array_define,array_add,array_get TYPE=Clay_LayoutElement NAME=Clay_LayoutElementArray DEFAULT_VALUE=&CLAY__LAYOUT_ELEMENT_DEFAULT #pragma region generated @@ -939,7 +939,7 @@ Clay_LayoutElement* Clay__LayoutElementPointerArray_RemoveSwapback(Clay__LayoutE #pragma endregion // __GENERATED__ template -Clay_RenderCommand CLAY__RENDER_COMMAND_DEFAULT = (Clay_RenderCommand) {}; +Clay_RenderCommand CLAY__RENDER_COMMAND_DEFAULT = CLAY__INIT(Clay_RenderCommand) {}; // __GENERATED__ template array_define TYPE=Clay_RenderCommand NAME=Clay_RenderCommandArray #pragma region generated @@ -985,7 +985,7 @@ typedef struct bool pointerScrollActive; } Clay__ScrollContainerDataInternal; -Clay__ScrollContainerDataInternal CLAY__SCROLL_CONTAINER_DEFAULT = (Clay__ScrollContainerDataInternal) {}; +Clay__ScrollContainerDataInternal CLAY__SCROLL_CONTAINER_DEFAULT = CLAY__INIT(Clay__ScrollContainerDataInternal) {}; // __GENERATED__ template define,array_add,array_get TYPE=Clay__ScrollContainerDataInternal NAME=Clay__ScrollContainerDataInternalArray DEFAULT_VALUE=&CLAY__SCROLL_CONTAINER_DEFAULT #pragma region generated @@ -1032,7 +1032,7 @@ typedef struct bool collapsed; } Clay__DebugElementData; -Clay__DebugElementData CLAY__DEBUG_ELEMENT_DATA_DEFAULT = (Clay__DebugElementData) {}; +Clay__DebugElementData CLAY__DEBUG_ELEMENT_DATA_DEFAULT = CLAY__INIT(Clay__DebugElementData) {}; // __GENERATED__ template array_define,array_add,array_get TYPE=Clay__DebugElementData NAME=Clay__DebugElementDataArray DEFAULT_VALUE=&CLAY__DEBUG_ELEMENT_DATA_DEFAULT #pragma region generated @@ -1069,7 +1069,7 @@ typedef struct Clay__DebugElementData *debugData; } Clay_LayoutElementHashMapItem; -Clay_LayoutElementHashMapItem CLAY__LAYOUT_ELEMENT_HASH_MAP_ITEM_DEFAULT = (Clay_LayoutElementHashMapItem) { .layoutElement = &CLAY__LAYOUT_ELEMENT_DEFAULT }; +Clay_LayoutElementHashMapItem CLAY__LAYOUT_ELEMENT_HASH_MAP_ITEM_DEFAULT = CLAY__INIT(Clay_LayoutElementHashMapItem) { .layoutElement = &CLAY__LAYOUT_ELEMENT_DEFAULT }; // __GENERATED__ template array_define,array_get,array_add TYPE=Clay_LayoutElementHashMapItem NAME=Clay__LayoutElementHashMapItemArray DEFAULT_VALUE=&CLAY__LAYOUT_ELEMENT_HASH_MAP_ITEM_DEFAULT #pragma region generated @@ -1103,7 +1103,7 @@ typedef struct int32_t nextIndex; } Clay__MeasureTextCacheItem; -Clay__MeasureTextCacheItem CLAY__MEASURE_TEXT_CACHE_ITEM_DEFAULT = (Clay__MeasureTextCacheItem) { }; +Clay__MeasureTextCacheItem CLAY__MEASURE_TEXT_CACHE_ITEM_DEFAULT = CLAY__INIT(Clay__MeasureTextCacheItem) { }; // __GENERATED__ template array_define,array_get,array_add,array_set TYPE=Clay__MeasureTextCacheItem NAME=Clay__MeasureTextCacheItemArray DEFAULT_VALUE=&CLAY__MEASURE_TEXT_CACHE_ITEM_DEFAULT #pragma region generated @@ -1188,7 +1188,7 @@ typedef struct Clay_Vector2 nextChildOffset; } Clay__LayoutElementTreeNode; -Clay__LayoutElementTreeNode CLAY__LAYOUT_ELEMENT_TREE_NODE_DEFAULT = (Clay__LayoutElementTreeNode) {}; +Clay__LayoutElementTreeNode CLAY__LAYOUT_ELEMENT_TREE_NODE_DEFAULT = CLAY__INIT(Clay__LayoutElementTreeNode) {}; // __GENERATED__ template array_define,array_add,array_get TYPE=Clay__LayoutElementTreeNode NAME=Clay__LayoutElementTreeNodeArray DEFAULT_VALUE=&CLAY__LAYOUT_ELEMENT_TREE_NODE_DEFAULT #pragma region generated @@ -1223,7 +1223,7 @@ typedef struct uint32_t zIndex; } Clay__LayoutElementTreeRoot; -Clay__LayoutElementTreeRoot CLAY__LAYOUT_ELEMENT_TREE_ROOT_DEFAULT = (Clay__LayoutElementTreeRoot) {}; +Clay__LayoutElementTreeRoot CLAY__LAYOUT_ELEMENT_TREE_ROOT_DEFAULT = CLAY__INIT(Clay__LayoutElementTreeRoot) {}; // __GENERATED__ template array_define,array_add,array_get TYPE=Clay__LayoutElementTreeRoot NAME=Clay__LayoutElementTreeRootArray DEFAULT_VALUE=&CLAY__LAYOUT_ELEMENT_TREE_ROOT_DEFAULT #pragma region generated @@ -1270,7 +1270,7 @@ Clay_String Clay__WriteStringToCharBuffer(Clay__CharArray *buffer, Clay_String s buffer->internalArray[buffer->length + i] = string.chars[i]; } buffer->length += string.length; - return (Clay_String) { .length = string.length, .chars = (const char *)(buffer->internalArray + buffer->length - string.length) }; + return CLAY__INIT(Clay_String) { .length = string.length, .chars = (const char *)(buffer->internalArray + buffer->length - string.length) }; } // __GENERATED__ template array_define,array_add TYPE=Clay_String NAME=Clay__StringArray DEFAULT_VALUE=&CLAY__STRING_DEFAULT @@ -1310,8 +1310,8 @@ typedef struct } Clay__PointerInfo; Clay__PointerInfo Clay__pointerInfo = (Clay__PointerInfo) { .position = {-1, -1} }; -Clay_Dimensions Clay__layoutDimensions = (Clay_Dimensions){}; -Clay_ElementId Clay__dynamicElementIndexBaseHash = (Clay_ElementId) { .id = 128476991, .stringId = { .length = 8, .chars = "Auto ID" } }; +Clay_Dimensions Clay__layoutDimensions = CLAY__INIT(Clay_Dimensions){}; +Clay_ElementId Clay__dynamicElementIndexBaseHash = CLAY__INIT(Clay_ElementId) { .id = 128476991, .stringId = { .length = 8, .chars = "Auto ID" } }; uint32_t Clay__dynamicElementIndex = 0; bool Clay__debugModeEnabled = false; uint32_t Clay__debugSelectedElementId = 0; @@ -1386,7 +1386,7 @@ Clay_ElementId Clay__HashString(Clay_String key, const uint32_t offset, const ui LAST_HASH = key; LAST_HASH.length = (int)offset; #endif - return (Clay_ElementId) { .stringId = key, .id = hash + 1, .offset = offset, .baseId = base + 1 }; // Reserve the hash result of zero as "null id" + return CLAY__INIT(Clay_ElementId) { .stringId = key, .id = hash + 1, .offset = offset, .baseId = base + 1 }; // Reserve the hash result of zero as "null id" } uint32_t Clay__GetOpenLayoutElementId(void) { @@ -1402,7 +1402,7 @@ Clay_ElementId Clay__Rehash(Clay_ElementId elementId, uint32_t number) { id += (id << 3); id ^= (id >> 11); id += (id << 15); - return (Clay_ElementId) { .id = id, .offset = number, .baseId = elementId.baseId, .stringId = elementId.stringId }; + return CLAY__INIT(Clay_ElementId) { .id = id, .offset = number, .baseId = elementId.baseId, .stringId = elementId.stringId }; } uint32_t Clay__RehashWithNumber(uint32_t id, uint32_t number) { @@ -1989,12 +1989,12 @@ void Clay__CalculateFinalLayout() { int lineStartIndex = 0; int wordStartIndex = 0; int wordEndIndex = 0; - Clay_Dimensions lineDimensions = (Clay_Dimensions){}; + Clay_Dimensions lineDimensions = CLAY__INIT(Clay_Dimensions){}; float spaceWidth = Clay__MeasureText(&CLAY__SPACECHAR, textConfig).width; // todo may as well cache it somewhere while (wordStartIndex <= text.length) { if (text.chars[wordEndIndex] == ' ' || (text.chars[wordEndIndex] == '\n' && textConfig->wrapMode <= CLAY_TEXT_WRAP_NEWLINES) || wordEndIndex == text.length) { - Clay_String stringToRender = (Clay_String) { .length = wordEndIndex - lineStartIndex, .chars = text.chars + lineStartIndex }; - Clay_String wordToMeasure = (Clay_String) { .length = wordEndIndex - wordStartIndex, .chars = text.chars + wordStartIndex }; + Clay_String stringToRender = CLAY__INIT(Clay_String) { .length = wordEndIndex - lineStartIndex, .chars = text.chars + lineStartIndex }; + Clay_String wordToMeasure = CLAY__INIT(Clay_String) { .length = wordEndIndex - wordStartIndex, .chars = text.chars + wordStartIndex }; // Clip off trailing spaces and newline characters Clay_Dimensions wordDimensions = Clay__MeasureTextCached(&wordToMeasure, textConfig); lineDimensions.width = lineDimensions.width + wordDimensions.width + spaceWidth; @@ -2005,7 +2005,7 @@ void Clay__CalculateFinalLayout() { lineDimensions.width -= spaceWidth; // We can wrap at the most recent word start if (wordStartIndex != lineStartIndex) { - stringToRender = (Clay_String) { .length = wordStartIndex - lineStartIndex - 1, .chars = text.chars + lineStartIndex }; + stringToRender = CLAY__INIT(Clay_String) { .length = wordStartIndex - lineStartIndex - 1, .chars = text.chars + lineStartIndex }; lineDimensions.width -= (wordDimensions.width + spaceWidth); lineStartIndex = wordStartIndex; wordStartIndex = lineStartIndex; @@ -2456,7 +2456,7 @@ Clay_LayoutConfig Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_L Clay_String Clay__IntToString(int integer) { if (integer == 0) { - return (Clay_String) { .length = 1, .chars = "0" }; + return CLAY__INIT(Clay_String) { .length = 1, .chars = "0" }; } char *chars = (char *)(Clay__dynamicStringData.internalArray + Clay__dynamicStringData.length); int length = 0; @@ -2481,7 +2481,7 @@ Clay_String Clay__IntToString(int integer) { chars[k] = temp; } Clay__dynamicStringData.length += length; - return (Clay_String) { .length = length, .chars = chars }; + return CLAY__INIT(Clay_String) { .length = length, .chars = chars }; } typedef struct @@ -2583,8 +2583,8 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR } } CLAY_TEXT(Clay__Rehash(elementNameId, currentElement->id), Clay__layoutElementIdStrings.internalArray[currentElementIndex], offscreen ? CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3) : &Clay__DebugView_TextNameConfig); - Clay_String elementTypeName = (Clay_String){}; - Clay_Color elementTypeColor = (Clay_Color){}; + Clay_String elementTypeName = CLAY__INIT(Clay_String){}; + Clay_Color elementTypeColor = CLAY__INIT(Clay_Color){}; switch (currentElement->elementType) { case CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE: elementTypeName = CLAY_STRING("Rectangle"); elementTypeColor = (CLAY__INIT(Clay_Color) {243,134,48,255}); break; case CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER: elementTypeName = CLAY_STRING("Container"); elementTypeColor = (CLAY__INIT(Clay_Color) {53,92,125, 255}); break; @@ -2612,7 +2612,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR CLAY_RECTANGLE(Clay__Rehash(textContentsOuterId, currentElement->id), CLAY_LAYOUT(.sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }), CLAY_RECTANGLE_CONFIG()) { CLAY_CONTAINER(Clay__Rehash(elementTextSpacer, currentElement->id), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_INDENT_WIDTH + 16)})) {} CLAY_TEXT(CLAY_IDI("Clay__DebugView_TextOpenQuote", currentElement->id), CLAY_STRING("\""), rawTextConfig); - CLAY_TEXT(Clay__Rehash(textContentsId, currentElement->id), currentElement->text.length > 40 ? ((Clay_String) { .chars = currentElement->text.chars, .length = 40 }) : currentElement->text, rawTextConfig); + CLAY_TEXT(Clay__Rehash(textContentsId, currentElement->id), currentElement->text.length > 40 ? (CLAY__INIT(Clay_String) { .chars = currentElement->text.chars, .length = 40 }) : currentElement->text, rawTextConfig); if (currentElement->text.length > 40) { CLAY_TEXT(CLAY_IDI("Clay__DebugView_TextEllipsis", currentElement->id), CLAY_STRING("..."), rawTextConfig); } From 0e608037b733c1a82374742ba0810154756ebaae Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:14:32 +1200 Subject: [PATCH 15/28] more msvc fixes --- clay.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/clay.h b/clay.h index 82d9731d..abc63d61 100644 --- a/clay.h +++ b/clay.h @@ -38,37 +38,37 @@ #define CLAY_LAYOUT(...) Clay__StoreLayoutConfig(CLAY__INIT(Clay_LayoutConfig) {__VA_ARGS__ }) -#define CLAY_RECTANGLE_CONFIG(...) Clay__StoreRectangleElementConfig((Clay_RectangleElementConfig) {__VA_ARGS__ }) +#define CLAY_RECTANGLE_CONFIG(...) Clay__StoreRectangleElementConfig(CLAY__INIT(Clay_RectangleElementConfig) {__VA_ARGS__ }) -#define CLAY_TEXT_CONFIG(...) Clay__StoreTextElementConfig((Clay_TextElementConfig) {__VA_ARGS__ }) +#define CLAY_TEXT_CONFIG(...) Clay__StoreTextElementConfig(CLAY__INIT(Clay_TextElementConfig) {__VA_ARGS__ }) -#define CLAY_IMAGE_CONFIG(...) Clay__StoreImageElementConfig((Clay_ImageElementConfig) {__VA_ARGS__ }) +#define CLAY_IMAGE_CONFIG(...) Clay__StoreImageElementConfig(CLAY__INIT(Clay_ImageElementConfig) {__VA_ARGS__ }) -#define CLAY_FLOATING_CONFIG(...) Clay__StoreFloatingElementConfig((Clay_FloatingElementConfig) {__VA_ARGS__ }) +#define CLAY_FLOATING_CONFIG(...) Clay__StoreFloatingElementConfig(CLAY__INIT(Clay_FloatingElementConfig) {__VA_ARGS__ }) -#define CLAY_CUSTOM_ELEMENT_CONFIG(...) Clay__StoreCustomElementConfig((Clay_CustomElementConfig) {__VA_ARGS__ }) +#define CLAY_CUSTOM_ELEMENT_CONFIG(...) Clay__StoreCustomElementConfig(CLAY__INIT(Clay_CustomElementConfig) {__VA_ARGS__ }) -#define CLAY_SCROLL_CONFIG(...) Clay__StoreScrollElementConfig((Clay_ScrollElementConfig) {__VA_ARGS__ }) +#define CLAY_SCROLL_CONFIG(...) Clay__StoreScrollElementConfig(CLAY__INIT(Clay_ScrollElementConfig) {__VA_ARGS__ }) -#define CLAY_BORDER_CONFIG(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { __VA_ARGS__ }) +#define CLAY_BORDER_CONFIG(...) Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { __VA_ARGS__ }) -#define CLAY_BORDER_CONFIG_OUTSIDE(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ } }) +#define CLAY_BORDER_CONFIG_OUTSIDE(...) Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ } }) -#define CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(width, color, radius) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .cornerRadius = { radius, radius, radius, radius } }) +#define CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(width, color, radius) Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .cornerRadius = { radius, radius, radius, radius } }) -#define CLAY_BORDER_CONFIG_ALL(...) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ } }) +#define CLAY_BORDER_CONFIG_ALL(...) Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = { __VA_ARGS__ }, .right = { __VA_ARGS__ }, .top = { __VA_ARGS__ }, .bottom = { __VA_ARGS__ }, .betweenChildren = { __VA_ARGS__ } }) -#define CLAY_BORDER_CONFIG_ALL_RADIUS(width, color, radius) Clay__StoreBorderElementConfig((Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .betweenChildren = { width, color }, .cornerRadius = { radius, radius, radius, radius }}) +#define CLAY_BORDER_CONFIG_ALL_RADIUS(width, color, radius) Clay__StoreBorderElementConfig(CLAY__INIT(Clay_BorderElementConfig) { .left = { width, color }, .right = { width, color }, .top = { width, color }, .bottom = { width, color }, .betweenChildren = { width, color }, .cornerRadius = { radius, radius, radius, radius }}) -#define CLAY_CORNER_RADIUS(radius) (Clay_CornerRadius) { radius, radius, radius, radius } +#define CLAY_CORNER_RADIUS(radius) CLAY__INIT(Clay_CornerRadius) { radius, radius, radius, radius } -#define CLAY_SIZING_FIT(...) (Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_FIT } +#define CLAY_SIZING_FIT(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_FIT } -#define CLAY_SIZING_GROW(...) (Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_GROW } +#define CLAY_SIZING_GROW(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_GROW } -#define CLAY_SIZING_FIXED(fixedSize) (Clay_SizingAxis) { .sizeMinMax = { fixedSize, fixedSize }, .type = CLAY__SIZING_TYPE_GROW } +#define CLAY_SIZING_FIXED(fixedSize) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = { fixedSize, fixedSize }, .type = CLAY__SIZING_TYPE_GROW } -#define CLAY_SIZING_PERCENT(percentOfParent) (Clay_SizingAxis) { .sizePercent = (percentOfParent), .type = CLAY__SIZING_TYPE_PERCENT } +#define CLAY_SIZING_PERCENT(percentOfParent) CLAY__INIT(Clay_SizingAxis) { .sizePercent = (percentOfParent), .type = CLAY__SIZING_TYPE_PERCENT } #define CLAY_ID(label) Clay__HashString(CLAY_STRING(label), 0, 0) From 8fbb196377147e463ce0fea7edd13ebabdafaab2 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:21:05 +1200 Subject: [PATCH 16/28] msvc --- clay.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/clay.h b/clay.h index abc63d61..9fca6ba2 100644 --- a/clay.h +++ b/clay.h @@ -1309,7 +1309,7 @@ typedef struct Clay__PointerInfoMouseDownState state; } Clay__PointerInfo; -Clay__PointerInfo Clay__pointerInfo = (Clay__PointerInfo) { .position = {-1, -1} }; +Clay__PointerInfo Clay__pointerInfo = CLAY__INIT(Clay__PointerInfo) { .position = {-1, -1} }; Clay_Dimensions Clay__layoutDimensions = CLAY__INIT(Clay_Dimensions){}; Clay_ElementId Clay__dynamicElementIndexBaseHash = CLAY__INIT(Clay_ElementId) { .id = 128476991, .stringId = { .length = 8, .chars = "Auto ID" } }; uint32_t Clay__dynamicElementIndex = 0; @@ -1386,7 +1386,7 @@ Clay_ElementId Clay__HashString(Clay_String key, const uint32_t offset, const ui LAST_HASH = key; LAST_HASH.length = (int)offset; #endif - return CLAY__INIT(Clay_ElementId) { .stringId = key, .id = hash + 1, .offset = offset, .baseId = base + 1 }; // Reserve the hash result of zero as "null id" + return CLAY__INIT(Clay_ElementId) { .id = hash + 1, .offset = offset, .baseId = base + 1, .stringId = key }; // Reserve the hash result of zero as "null id" } uint32_t Clay__GetOpenLayoutElementId(void) { @@ -1460,7 +1460,7 @@ Clay_Dimensions Clay__MeasureTextCached(Clay_String *text, Clay_TextElementConfi elementIndex = hashEntry->nextIndex; } Clay_Dimensions measured = Clay__MeasureText(text, config); - Clay__MeasureTextCacheItemArray_Add(&Clay__measureTextHashMapInternal, (Clay__MeasureTextCacheItem) { .id = id, .dimensions = measured }); + Clay__MeasureTextCacheItemArray_Add(&Clay__measureTextHashMapInternal, (Clay__MeasureTextCacheItem) { .dimensions = measured, .id = id }); if (elementIndexPrevious != 0) { Clay__MeasureTextCacheItemArray_Get(&Clay__measureTextHashMapInternal, elementIndexPrevious)->nextIndex = (int32_t)Clay__measureTextHashMapInternal.length - 1; } else { @@ -1474,7 +1474,7 @@ bool Clay__PointIsInsideRect(Clay_Vector2 point, Clay_BoundingBox rect) { } Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Clay_LayoutElement* layoutElement) { - Clay_LayoutElementHashMapItem item = (Clay_LayoutElementHashMapItem) { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = Clay__generation + 1 }; + Clay_LayoutElementHashMapItem item = CLAY__INIT(Clay_LayoutElementHashMapItem) { .elementId = elementId, .layoutElement = layoutElement, .nextIndex = -1, .generation = Clay__generation + 1 }; uint32_t hashBucket = elementId.id % Clay__layoutElementsHashMap.capacity; int32_t hashItemPrevious = -1; int32_t hashItemIndex = Clay__layoutElementsHashMap.internalArray[hashBucket]; @@ -1500,7 +1500,7 @@ Clay_LayoutElementHashMapItem* Clay__AddHashMapItem(Clay_ElementId elementId, Cl hashItemIndex = hashItem->nextIndex; } Clay_LayoutElementHashMapItem *hashItem = Clay__LayoutElementHashMapItemArray_Add(&Clay__layoutElementsHashMapInternal, item); - hashItem->debugData = Clay__DebugElementDataArray_Add(&Clay__debugElementData, (Clay__DebugElementData) {}); + hashItem->debugData = Clay__DebugElementDataArray_Add(&Clay__debugElementData, CLAY__INIT(Clay__DebugElementData) {}); if (hashItemPrevious != -1) { Clay__LayoutElementHashMapItemArray_Get(&Clay__layoutElementsHashMapInternal, hashItemPrevious)->nextIndex = (int32_t)Clay__layoutElementsHashMapInternal.length - 1; } else { @@ -1523,16 +1523,16 @@ Clay_LayoutElementHashMapItem *Clay__GetHashMapItem(uint32_t id) { } Clay_LayoutElement *Clay__OpenElementWithParent(Clay_ElementId elementId, Clay__LayoutElementType commandType, Clay_LayoutConfig* layoutConfig, Clay_ElementConfigUnion elementConfig) { - Clay_LayoutElement layoutElement = (Clay_LayoutElement) { + Clay_LayoutElement layoutElement = CLAY__INIT(Clay_LayoutElement) { #ifdef CLAY_DEBUG .name = elementId.stringId, #endif - .id = elementId.id, - .elementType = commandType, - .minDimensions = CLAY__INIT(Clay_Dimensions) { (float)layoutConfig->padding.x * 2, (float)layoutConfig->padding.y * 2 }, .children = (Clay__LayoutElementChildren) { .length = 0 }, + .minDimensions = CLAY__INIT(Clay_Dimensions) { (float)layoutConfig->padding.x * 2, (float)layoutConfig->padding.y * 2 }, .layoutConfig = layoutConfig, .elementConfig = elementConfig, + .id = elementId.id, + .elementType = commandType, }; if (layoutConfig->sizing.width.type != CLAY__SIZING_TYPE_PERCENT) { @@ -1598,7 +1598,7 @@ void Clay__OpenScrollElement(Clay_ElementId elementId, Clay_LayoutConfig *layout } } if (!scrollOffset) { - Clay__ScrollContainerDataInternalArray_Add(&Clay__scrollContainerDatas, (Clay__ScrollContainerDataInternal){.elementId = elementId.id, .layoutElement = scrollElement, .scrollOrigin = {-1,-1}, .openThisFrame = true}); + Clay__ScrollContainerDataInternalArray_Add(&Clay__scrollContainerDatas, CLAY__INIT(Clay__ScrollContainerDataInternal){.layoutElement = scrollElement, .scrollOrigin = {-1,-1}, .elementId = elementId.id, .openThisFrame = true}); } } From 5108028c11824bb1cd106c07819ee8e7ad6ebf12 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:23:54 +1200 Subject: [PATCH 17/28] msvc --- clay.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/clay.h b/clay.h index 9fca6ba2..2567bd52 100644 --- a/clay.h +++ b/clay.h @@ -1460,7 +1460,7 @@ Clay_Dimensions Clay__MeasureTextCached(Clay_String *text, Clay_TextElementConfi elementIndex = hashEntry->nextIndex; } Clay_Dimensions measured = Clay__MeasureText(text, config); - Clay__MeasureTextCacheItemArray_Add(&Clay__measureTextHashMapInternal, (Clay__MeasureTextCacheItem) { .dimensions = measured, .id = id }); + Clay__MeasureTextCacheItemArray_Add(&Clay__measureTextHashMapInternal, CLAY__INIT(Clay__MeasureTextCacheItem) { .dimensions = measured, .id = id }); if (elementIndexPrevious != 0) { Clay__MeasureTextCacheItemArray_Get(&Clay__measureTextHashMapInternal, elementIndexPrevious)->nextIndex = (int32_t)Clay__measureTextHashMapInternal.length - 1; } else { @@ -1527,7 +1527,7 @@ Clay_LayoutElement *Clay__OpenElementWithParent(Clay_ElementId elementId, Clay__ #ifdef CLAY_DEBUG .name = elementId.stringId, #endif - .children = (Clay__LayoutElementChildren) { .length = 0 }, + .children = CLAY__INIT(Clay__LayoutElementChildren) { .length = 0 }, .minDimensions = CLAY__INIT(Clay_Dimensions) { (float)layoutConfig->padding.x * 2, (float)layoutConfig->padding.y * 2 }, .layoutConfig = layoutConfig, .elementConfig = elementConfig, @@ -1565,24 +1565,24 @@ Clay_LayoutElement *Clay__OpenElement(Clay_ElementId id, Clay__LayoutElementType } void Clay__OpenContainerElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig) { - Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER, layoutConfig, (Clay_ElementConfigUnion){ CLAY__NULL }); + Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { CLAY__NULL }); } void Clay__OpenRectangleElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_RectangleElementConfig *rectangleConfig) { - Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE, layoutConfig, (Clay_ElementConfigUnion) { .rectangleElementConfig = rectangleConfig }); + Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .rectangleElementConfig = rectangleConfig }); } void Clay__OpenImageElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_ImageElementConfig *imageConfig) { - Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_IMAGE, layoutConfig, (Clay_ElementConfigUnion) { .imageElementConfig = imageConfig }); + Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_IMAGE, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .imageElementConfig = imageConfig }); Clay__LayoutElementPointerArray_Add(&Clay__imageElementPointers, Clay__openLayoutElement); } void Clay__OpenBorderElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_BorderElementConfig *borderConfig) { - Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER, layoutConfig, (Clay_ElementConfigUnion){ .borderElementConfig = borderConfig }); + Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .borderElementConfig = borderConfig }); } void Clay__OpenCustomElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, Clay_CustomElementConfig *customConfig) { - Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM, layoutConfig, (Clay_ElementConfigUnion) { .customElementConfig = customConfig }); + Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .customElementConfig = customConfig }); } void Clay__OpenScrollElement(Clay_ElementId elementId, Clay_LayoutConfig *layoutConfig, Clay_ScrollElementConfig *scrollConfig) { @@ -1617,7 +1617,7 @@ void Clay__OpenFloatingElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfi parent = parentItem->layoutElement; } } - Clay__OpenElementWithParent(id, CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER, layoutConfig, (Clay_ElementConfigUnion) { .floatingElementConfig = floatingConfig }); + Clay__OpenElementWithParent(id, CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .floatingElementConfig = floatingConfig }); Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1, .parentId = parent->id, @@ -1692,7 +1692,7 @@ void Clay__CloseElement() { } void Clay__OpenTextElement(Clay_ElementId id, Clay_String text, Clay_TextElementConfig *textConfig) { - Clay_LayoutElement *internalElement = Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_TEXT, &CLAY_LAYOUT_DEFAULT, (Clay_ElementConfigUnion) { .textElementConfig = textConfig }); + Clay_LayoutElement *internalElement = Clay__OpenElement(id, CLAY__LAYOUT_ELEMENT_TYPE_TEXT, &CLAY_LAYOUT_DEFAULT, CLAY__INIT(Clay_ElementConfigUnion) { .textElementConfig = textConfig }); Clay_Dimensions textMeasured = Clay__MeasureTextCached(&text, textConfig); internalElement->dimensions.width = textMeasured.width; internalElement->dimensions.height = textMeasured.height; @@ -1967,7 +1967,7 @@ void Clay__CalculateFinalLayout() { containerElement->layoutConfig = Clay__LayoutConfigArray_Add(&Clay__layoutConfigs, *containerElement->layoutConfig); containerElement->layoutConfig->layoutDirection = CLAY_TOP_TO_BOTTOM; containerElement->layoutConfig->childGap = textConfig->lineSpacing; - containerElement->children = (Clay__LayoutElementChildren) { // Note: this overwrites the text property + containerElement->children = CLAY__INIT(Clay__LayoutElementChildren) { // Note: this overwrites the text property .length = 0, .elements = &Clay__layoutElementChildren.internalArray[Clay__layoutElementChildren.length] }; From e309c9e03d2eaa243c138b112e5f50a2e51e7d33 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:29:56 +1200 Subject: [PATCH 18/28] msvc --- clay.h | 62 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/clay.h b/clay.h index 2567bd52..d9cb677e 100644 --- a/clay.h +++ b/clay.h @@ -1586,7 +1586,7 @@ void Clay__OpenCustomElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfig, } void Clay__OpenScrollElement(Clay_ElementId elementId, Clay_LayoutConfig *layoutConfig, Clay_ScrollElementConfig *scrollConfig) { - Clay_LayoutElement *scrollElement = Clay__OpenElement(elementId, CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER, layoutConfig, (Clay_ElementConfigUnion){ .scrollElementConfig = scrollConfig }); + Clay_LayoutElement *scrollElement = Clay__OpenElement(elementId, CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .scrollElementConfig = scrollConfig }); Clay__int32_tArray_Add(&Clay__openClipElementStack, (int)scrollElement->id); Clay__ScrollContainerDataInternal *scrollOffset = CLAY__NULL; for (int i = 0; i < Clay__scrollContainerDatas.length; i++) { @@ -1618,7 +1618,7 @@ void Clay__OpenFloatingElement(Clay_ElementId id, Clay_LayoutConfig *layoutConfi } } Clay__OpenElementWithParent(id, CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER, layoutConfig, CLAY__INIT(Clay_ElementConfigUnion) { .floatingElementConfig = floatingConfig }); - Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) { + Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1, .parentId = parent->id, .clipElementId = (uint32_t)(originalParentId == 0 ? (Clay__openClipElementStack.length > 0 ? Clay__int32_tArray_Get(&Clay__openClipElementStack, (int)Clay__openClipElementStack.length - 1) : 0) : 0), @@ -1698,7 +1698,7 @@ void Clay__OpenTextElement(Clay_ElementId id, Clay_String text, Clay_TextElement internalElement->dimensions.height = textMeasured.height; internalElement->text = text; internalElement->minDimensions = CLAY__INIT(Clay_Dimensions) { .width = textMeasured.height, .height = textMeasured.height }; // TODO not sure this is the best way to decide min width for text - Clay__TextElementDataArray_Add(&Clay__textElementData, (Clay__TextElementData) { .preferredDimensions = textMeasured, .elementIndex = Clay__layoutElements.length - 1}); + Clay__TextElementDataArray_Add(&Clay__textElementData, CLAY__INIT(Clay__TextElementData) { .elementIndex = Clay__layoutElements.length - 1, .preferredDimensions = textMeasured }); Clay__CloseElement(); } @@ -1968,18 +1968,18 @@ void Clay__CalculateFinalLayout() { containerElement->layoutConfig->layoutDirection = CLAY_TOP_TO_BOTTOM; containerElement->layoutConfig->childGap = textConfig->lineSpacing; containerElement->children = CLAY__INIT(Clay__LayoutElementChildren) { // Note: this overwrites the text property + .elements = &Clay__layoutElementChildren.internalArray[Clay__layoutElementChildren.length], .length = 0, - .elements = &Clay__layoutElementChildren.internalArray[Clay__layoutElementChildren.length] }; // Short circuit all wrap calculations if wrap mode is none if (textConfig->wrapMode == CLAY_TEXT_WRAP_NONE || (containerElement->dimensions.width == textElementData->preferredDimensions.width)) { - Clay_LayoutElementArray_Add(&Clay__layoutElements, (Clay_LayoutElement) { - .id = Clay__RehashWithNumber(containerElement->id, containerElement->children.length), - .elementType = CLAY__LAYOUT_ELEMENT_TYPE_TEXT, + Clay_LayoutElementArray_Add(&Clay__layoutElements, CLAY__INIT(Clay_LayoutElement) { .text = text, - .layoutConfig = &CLAY_LAYOUT_DEFAULT, - .elementConfig.textElementConfig = containerElement->elementConfig.textElementConfig, .dimensions = textElementData->preferredDimensions, + .layoutConfig = &CLAY_LAYOUT_DEFAULT, + .elementConfig = { .textElementConfig = containerElement->elementConfig.textElementConfig }, + .id = Clay__RehashWithNumber(containerElement->id, containerElement->children.length), + .elementType = CLAY__LAYOUT_ELEMENT_TYPE_TEXT, }); containerElement->children.length++; Clay__int32_tArray_Add(&Clay__layoutElementChildren, (int32_t)Clay__layoutElements.length - 1); @@ -2029,13 +2029,13 @@ void Clay__CalculateFinalLayout() { wordStartIndex = lineStartIndex; wordEndIndex = lineStartIndex; } - Clay_LayoutElementArray_Add(&Clay__layoutElements, (Clay_LayoutElement) { - .id = Clay__RehashWithNumber(containerElement->id, containerElement->children.length), - .elementType = CLAY__LAYOUT_ELEMENT_TYPE_TEXT, + Clay_LayoutElementArray_Add(&Clay__layoutElements, CLAY__INIT(Clay_LayoutElement) { .text = stringToRender, - .layoutConfig = &CLAY_LAYOUT_DEFAULT, - .elementConfig.textElementConfig = containerElement->elementConfig.textElementConfig, .dimensions = { lineDimensions.width, lineDimensions.height }, + .layoutConfig = &CLAY_LAYOUT_DEFAULT, + .elementConfig = { .textElementConfig = containerElement->elementConfig.textElementConfig }, + .id = Clay__RehashWithNumber(containerElement->id, containerElement->children.length), + .elementType = CLAY__LAYOUT_ELEMENT_TYPE_TEXT, }); containerElement->dimensions.height += lineDimensions.height + (float)(containerElement->children.length > 0 ? textConfig->lineSpacing : 0); containerElement->children.length++; @@ -2177,9 +2177,9 @@ void Clay__CalculateFinalLayout() { Clay_LayoutElementHashMapItem *clipHashMapItem = Clay__GetHashMapItem(root->clipElementId); if (clipHashMapItem) { Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + .boundingBox = clipHashMapItem->boundingBox, .id = Clay__RehashWithNumber(rootElement->id, 10), // TODO need a better strategy for managing derived ids .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START, - .boundingBox = clipHashMapItem->boundingBox, }); } } @@ -2210,9 +2210,9 @@ void Clay__CalculateFinalLayout() { // Apply scroll offsets to container if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER) { Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + .boundingBox = currentElementBoundingBox, .id = Clay__RehashWithNumber(currentElement->id, 10), .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START, - .boundingBox = currentElementBoundingBox, }); // This linear scan could theoretically be slow under very strange conditions, but I can't imagine a real UI with more than a few 10's of scroll containers @@ -2234,11 +2234,11 @@ void Clay__CalculateFinalLayout() { } // Create the render command for this element - Clay_RenderCommand renderCommand = (Clay_RenderCommand) { + Clay_RenderCommand renderCommand = CLAY__INIT(Clay_RenderCommand) { + .boundingBox = currentElementBoundingBox, + .config = currentElement->elementConfig, .id = currentElement->id, .commandType = Clay__LayoutElementTypeToRenderCommandType[currentElement->elementType], - .boundingBox = currentElementBoundingBox, - .config = currentElement->elementConfig }; Clay_LayoutElementHashMapItem *hashMapItem = Clay__GetHashMapItem(currentElement->id); @@ -2319,7 +2319,7 @@ void Clay__CalculateFinalLayout() { } else { // DFS is returning upwards backwards if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { .id = Clay__RehashWithNumber(currentElement->id, 11), .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_END, }); @@ -2337,11 +2337,11 @@ void Clay__CalculateFinalLayout() { #endif Clay_BorderElementConfig *borderConfig = currentElement->elementConfig.borderElementConfig; - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { + .boundingBox = currentElementBoundingBox, + .config = currentElement->elementConfig, .id = currentElement->id, .commandType = CLAY_RENDER_COMMAND_TYPE_BORDER, - .boundingBox = currentElementBoundingBox, - .config = currentElement->elementConfig }); // Render border elements between children @@ -2351,11 +2351,11 @@ void Clay__CalculateFinalLayout() { for (int i = 0; i < currentElement->children.length; ++i) { Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, currentElement->children.elements[i]); if (i > 0) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { + .boundingBox = { currentElementBoundingBox.x + borderOffset.x, currentElementBoundingBox.y, (float)borderConfig->betweenChildren.width, currentElement->dimensions.height }, + .config = { CLAY_RECTANGLE_CONFIG(.color = borderConfig->betweenChildren.color) }, .id = Clay__RehashWithNumber(currentElement->id, 5 + i), .commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, - .boundingBox = { currentElementBoundingBox.x + borderOffset.x, currentElementBoundingBox.y, (float)borderConfig->betweenChildren.width, currentElement->dimensions.height }, - .config = { CLAY_RECTANGLE_CONFIG(.color = borderConfig->betweenChildren.color) } }); } borderOffset.x += (childElement->dimensions.width + (float)layoutConfig->childGap / 2); @@ -2364,11 +2364,11 @@ void Clay__CalculateFinalLayout() { for (int i = 0; i < currentElement->children.length; ++i) { Clay_LayoutElement *childElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, currentElement->children.elements[i]); if (i > 0) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { + .boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + borderOffset.y, currentElement->dimensions.width, (float)borderConfig->betweenChildren.width }, + .config = { CLAY_RECTANGLE_CONFIG(.color = borderConfig->betweenChildren.color) }, .id = Clay__RehashWithNumber(currentElement->id, 5 + i), .commandType = CLAY_RENDER_COMMAND_TYPE_RECTANGLE, - .boundingBox = { currentElementBoundingBox.x, currentElementBoundingBox.y + borderOffset.y, currentElement->dimensions.width, (float)borderConfig->betweenChildren.width }, - .config = { CLAY_RECTANGLE_CONFIG(.color = borderConfig->betweenChildren.color) } }); } borderOffset.y += (childElement->dimensions.height + (float)layoutConfig->childGap / 2); @@ -2428,7 +2428,7 @@ void Clay__CalculateFinalLayout() { } if (root->clipElementId) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { .id = Clay__RehashWithNumber(rootElement->id, 11), .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_END }); + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { .id = Clay__RehashWithNumber(rootElement->id, 11), .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_END }); } } } @@ -3267,7 +3267,7 @@ void Clay_BeginLayout() { Clay_LayoutElement rootLayoutElement = (Clay_LayoutElement){.layoutConfig = CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)}), .id = rootElementId.id, }; Clay__openLayoutElement = Clay_LayoutElementArray_Add(&Clay__layoutElements, rootLayoutElement); Clay__LayoutElementPointerArray_Add(&Clay__openLayoutElementStack, Clay__openLayoutElement); - Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1 }); + Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1 }); Clay__StringArray_Add(&Clay__layoutElementIdStrings, CLAY_STRING("Clay__RootContainer")); Clay__AddHashMapItem(rootElementId, Clay__openLayoutElement); } From 21a67240ef38101db9ed1353e10f93a745f8ead0 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:37:52 +1200 Subject: [PATCH 19/28] msvc --- clay.h | 78 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/clay.h b/clay.h index d9cb677e..89fa40e9 100644 --- a/clay.h +++ b/clay.h @@ -219,8 +219,8 @@ typedef struct { Clay_Sizing sizing; Clay_Padding padding; uint16_t childGap; - Clay_LayoutDirection layoutDirection; Clay_ChildAlignment childAlignment; + Clay_LayoutDirection layoutDirection; } Clay_LayoutConfig; extern Clay_LayoutConfig CLAY_LAYOUT_DEFAULT; @@ -2510,7 +2510,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay_ElementId textContentsOuterId = CLAY_ID("Clay__DebugView_ElementTextContentsOuter"); Clay_ElementId textContentsId = CLAY_ID("Clay__DebugView_ElementTextContents"); Clay__int32_tArray dfsBuffer = Clay__reusableElementIndexBuffer; - Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_LayoutConfig) { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT) }, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }, .childGap = 6}; + Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_LayoutConfig) { .sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT) }, .childGap = 6, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }}; Clay__RenderDebugLayoutData layoutData = {}; uint32_t highlightedElementId = 0; @@ -2522,7 +2522,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR Clay__treeNodeVisited.internalArray[0] = false; if (rootIndex > 0) { CLAY_CONTAINER(CLAY_IDI("Clay__DebugView_EmptyRowOuter", rootIndex), CLAY_LAYOUT(.sizing = {.width = CLAY_SIZING_GROW()}, .padding = {CLAY__DEBUGVIEW_INDENT_WIDTH / 2})) { - CLAY_BORDER_CONTAINER(CLAY_IDI("Clay__DebugView_EmptyRow", rootIndex), CLAY_LAYOUT(.sizing = {.height = CLAY_SIZING_FIXED((float)CLAY__DEBUGVIEW_ROW_HEIGHT), .width = CLAY_SIZING_GROW()}), CLAY_BORDER_CONFIG(.top = { .width = 1, .color = CLAY__DEBUGVIEW_COLOR_3 } )) {} + CLAY_BORDER_CONTAINER(CLAY_IDI("Clay__DebugView_EmptyRow", rootIndex), CLAY_LAYOUT(.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED((float)CLAY__DEBUGVIEW_ROW_HEIGHT) }), CLAY_BORDER_CONFIG(.top = { .width = 1, .color = CLAY__DEBUGVIEW_COLOR_3 } )) {} } layoutData.rowCount++; } @@ -2561,7 +2561,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR CLAY_CONTAINER(outerHash, &Clay__DebugView_ScrollViewItemLayoutConfig) { if (!(currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_TEXT || currentElement->children.length == 0)) { CLAY_BORDER_CONTAINER(Clay__Rehash(collapseIconButton, currentElement->id), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(16), CLAY_SIZING_FIXED(16)}, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER}), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, CLAY__DEBUGVIEW_COLOR_3, 4)) { - CLAY_TEXT(Clay__Rehash(collapseIcon, currentElement->id), (currentElementData && currentElementData->debugData->collapsed) ? CLAY_STRING("+") : CLAY_STRING("-"), CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_4)); + CLAY_TEXT(Clay__Rehash(collapseIcon, currentElement->id), (currentElementData && currentElementData->debugData->collapsed) ? CLAY_STRING("+") : CLAY_STRING("-"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16)); } } else { CLAY_CONTAINER(Clay__Rehash(collapseIconButton, currentElement->id), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(16), CLAY_SIZING_FIXED(16)}, .childAlignment = { CLAY_ALIGN_X_CENTER, CLAY_ALIGN_Y_CENTER})) { @@ -2572,17 +2572,17 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR if (currentElementData) { if (currentElementData->debugData->collision) { CLAY_BORDER_CONTAINER(Clay__Rehash(elementOffscreenBorderId, currentElement->id), CLAY_LAYOUT(.padding = { 8, 2 }), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, ((Clay_Color){177, 147, 8, 255}), 4)) { - CLAY_TEXT(Clay__Rehash(elementDuplicateWarning, currentElement->id), CLAY_STRING("Duplicate ID"), CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3)); + CLAY_TEXT(Clay__Rehash(elementDuplicateWarning, currentElement->id), CLAY_STRING("Duplicate ID"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16)); } } if (offscreen) { CLAY_BORDER_CONTAINER(Clay__Rehash(elementOffscreenBorderId, currentElement->id), CLAY_LAYOUT(.padding = { 8, 2 }), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, CLAY__DEBUGVIEW_COLOR_3, 4)) { - CLAY_TEXT(Clay__Rehash(elementDuplicateWarning, currentElement->id), CLAY_STRING("Offscreen"), CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3)); + CLAY_TEXT(Clay__Rehash(elementDuplicateWarning, currentElement->id), CLAY_STRING("Offscreen"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16)); } } } - CLAY_TEXT(Clay__Rehash(elementNameId, currentElement->id), Clay__layoutElementIdStrings.internalArray[currentElementIndex], offscreen ? CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3) : &Clay__DebugView_TextNameConfig); + CLAY_TEXT(Clay__Rehash(elementNameId, currentElement->id), Clay__layoutElementIdStrings.internalArray[currentElementIndex], offscreen ? CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16) : &Clay__DebugView_TextNameConfig); Clay_String elementTypeName = CLAY__INIT(Clay_String){}; Clay_Color elementTypeColor = CLAY__INIT(Clay_Color){}; switch (currentElement->elementType) { @@ -2599,7 +2599,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR backgroundColor.a = 90; CLAY_BORDER_CONTAINER(Clay__Rehash(elementTypeBorderId, currentElement->id), &CLAY_LAYOUT_DEFAULT, CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, elementTypeColor, 4)) { CLAY_RECTANGLE(Clay__Rehash(elementTypeInnerRectId, currentElement->id), CLAY_LAYOUT(.padding = { 8, 2 }), CLAY_RECTANGLE_CONFIG(.color = backgroundColor, .cornerRadius = CLAY_CORNER_RADIUS(4))) { - CLAY_TEXT(Clay__Rehash(elementTypeTextId, currentElement->id), elementTypeName, CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = offscreen ? CLAY__DEBUGVIEW_COLOR_3 : CLAY__DEBUGVIEW_COLOR_4)); + CLAY_TEXT(Clay__Rehash(elementTypeTextId, currentElement->id), elementTypeName, CLAY_TEXT_CONFIG(.textColor = offscreen ? CLAY__DEBUGVIEW_COLOR_3 : CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16)); } } } @@ -2608,11 +2608,11 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR // Render the text contents below the element as a non-interactive row if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_TEXT) { layoutData.rowCount++; - Clay_TextElementConfig *rawTextConfig = offscreen ? CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3) : &Clay__DebugView_TextNameConfig; + Clay_TextElementConfig *rawTextConfig = offscreen ? CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16) : &Clay__DebugView_TextNameConfig; CLAY_RECTANGLE(Clay__Rehash(textContentsOuterId, currentElement->id), CLAY_LAYOUT(.sizing = { .height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }), CLAY_RECTANGLE_CONFIG()) { CLAY_CONTAINER(Clay__Rehash(elementTextSpacer, currentElement->id), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_INDENT_WIDTH + 16)})) {} CLAY_TEXT(CLAY_IDI("Clay__DebugView_TextOpenQuote", currentElement->id), CLAY_STRING("\""), rawTextConfig); - CLAY_TEXT(Clay__Rehash(textContentsId, currentElement->id), currentElement->text.length > 40 ? (CLAY__INIT(Clay_String) { .chars = currentElement->text.chars, .length = 40 }) : currentElement->text, rawTextConfig); + CLAY_TEXT(Clay__Rehash(textContentsId, currentElement->id), currentElement->text.length > 40 ? (CLAY__INIT(Clay_String) { .length = 40, .chars = currentElement->text.chars }) : currentElement->text, rawTextConfig); if (currentElement->text.length > 40) { CLAY_TEXT(CLAY_IDI("Clay__DebugView_TextEllipsis", currentElement->id), CLAY_STRING("..."), rawTextConfig); } @@ -2620,7 +2620,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR } } else if (currentElement->children.length > 0) { Clay__OpenContainerElement(Clay__Rehash(paddingOffset, currentElement->id), CLAY_LAYOUT(.padding = { 8 })); - Clay__OpenBorderElement(Clay__Rehash(border, currentElement->id), CLAY_LAYOUT(.layoutDirection = CLAY_LEFT_TO_RIGHT), CLAY_BORDER_CONFIG(.left = { .color = CLAY__DEBUGVIEW_COLOR_3, .width = 1})); + Clay__OpenBorderElement(Clay__Rehash(border, currentElement->id), CLAY_LAYOUT(.layoutDirection = CLAY_LEFT_TO_RIGHT), CLAY_BORDER_CONFIG(.left = { .width = 1, .color = CLAY__DEBUGVIEW_COLOR_3 })); CLAY_CONTAINER(Clay__Rehash(spacerId, currentElement->id), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED( CLAY__DEBUGVIEW_INDENT_WIDTH)}, .childAlignment = { .x = CLAY_ALIGN_X_RIGHT })) {} Clay__OpenContainerElement(Clay__Rehash(inner, currentElement->id), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM)); } @@ -2683,10 +2683,10 @@ void Clay__RenderDebugLayoutSizing(Clay_ElementId baseId, Clay_SizingAxis sizing void Clay__RenderDebugViewElementConfigHeader(Clay_String elementId, Clay_String title) { CLAY_RECTANGLE(CLAY_IDI("Clay__DebugViewElementConfigItemBorder", 1), CLAY_LAYOUT(.sizing = {.width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED(1)}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementConfigItemHeader"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING})) { - CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementConfigTitle", 1), title, CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_4, .wrapMode = CLAY_TEXT_WRAP_NONE)); + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementConfigItemHeader"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER})) { + CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementConfigTitle", 1), title, CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE)); CLAY_CONTAINER(CLAY_IDI("Clay__DebugViewElementConfigTitleSpacer", 1), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW() })) {} - CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementConfigTitle", 2), elementId, CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3, .wrapMode = CLAY_TEXT_WRAP_NONE)); + CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementConfigTitle", 2), elementId, CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE)); } CLAY_RECTANGLE(CLAY_IDI("Clay__DebugViewElementConfigItemBorder", 2), CLAY_LAYOUT(.sizing = {.width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED(1)}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} } @@ -2704,7 +2704,7 @@ void Clay__RenderDebugViewColor(Clay_Color color, Clay_TextElementConfig *textCo CLAY_TEXT(CLAY_ID_LOCAL("Brace"), CLAY_STRING(" }"), textConfig); CLAY_CONTAINER(CLAY_ID_LOCAL("Spacer"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(10) })) {} CLAY_BORDER_CONTAINER(CLAY_ID_LOCAL("PreviewBorder"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8)}), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, CLAY__DEBUGVIEW_COLOR_4, 4)) { - CLAY_RECTANGLE(CLAY_ID_LOCAL("PreviewBackground"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8)}), CLAY_RECTANGLE_CONFIG(.cornerRadius = CLAY_CORNER_RADIUS(4), .color = color)) {} + CLAY_RECTANGLE(CLAY_ID_LOCAL("PreviewBackground"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT - 8)}), CLAY_RECTANGLE_CONFIG(.color = color, .cornerRadius = CLAY_CORNER_RADIUS(4))) {} } } } @@ -2747,8 +2747,8 @@ void Clay__RenderDebugView() { uint32_t initialRootsLength = Clay__layoutElementTreeRoots.length; uint32_t initialElementsLength = Clay__layoutElements.length; - Clay_TextElementConfig *infoTextConfig = CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_4, .wrapMode = CLAY_TEXT_WRAP_NONE); - Clay_TextElementConfig *infoTitleConfig = CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_3, .wrapMode = CLAY_TEXT_WRAP_NONE); + Clay_TextElementConfig *infoTextConfig = CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE); + Clay_TextElementConfig *infoTitleConfig = CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE); uint32_t scrollId = CLAY_ID("Clay__DebugViewOuterScrollPane").id; float scrollYOffset = 0; for (int i = 0; i < Clay__scrollContainerDatas.length; ++i) { @@ -2765,27 +2765,27 @@ void Clay__RenderDebugView() { Clay__RenderDebugLayoutData layoutData = {}; CLAY_FLOATING_CONTAINER(CLAY_ID("Clay__DebugView"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_FIXED((float)Clay__debugViewWidth) , CLAY_SIZING_FIXED(Clay__layoutDimensions.height) }), CLAY_FLOATING_CONFIG(.attachment = { .element = CLAY_ATTACH_POINT_LEFT_CENTER, .parent = CLAY_ATTACH_POINT_RIGHT_CENTER })) { CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewLeftBorder"), CLAY_LAYOUT(.sizing = { .width = CLAY_SIZING_FIXED(1), .height = CLAY_SIZING_GROW() }), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewInner"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()})) { - CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderOuter"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewInner"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .layoutDirection = CLAY_TOP_TO_BOTTOM )) { + CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderOuter"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { CLAY_TEXT(CLAY_IDI("Clay__DebugViewTopHeaderId", 1), CLAY_STRING("Clay Debug Tools"), infoTextConfig); CLAY_CONTAINER(CLAY_ID("Clay__DebugViewTopHeaderSpacer"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW() })) {} CLAY_BORDER_CONTAINER(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonOuter"), &CLAY_LAYOUT_DEFAULT, CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, ((Clay_Color){217,91,67,255}), 4)) { CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonInner"), 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}), CLAY_RECTANGLE_CONFIG(.color = ((Clay_Color){217,91,67,80}))) { - CLAY_TEXT(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonText"), CLAY_STRING("x"), CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_4)); + CLAY_TEXT(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonText"), CLAY_STRING("x"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16)); } } } CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderBorder"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(1)}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} - CLAY_SCROLL_CONTAINER(CLAY_ID("Clay__DebugViewOuterScrollPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_SCROLL_CONFIG(.vertical = true, .horizontal = true)) { - CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewPaneBackground"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_RECTANGLE_CONFIG(.color = ((initialElementsLength + initialRootsLength) & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1)) { + CLAY_SCROLL_CONTAINER(CLAY_ID("Clay__DebugViewOuterScrollPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_SCROLL_CONFIG(.horizontal = true, .vertical = true)) { + CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewPaneBackground"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .layoutDirection = CLAY_TOP_TO_BOTTOM), CLAY_RECTANGLE_CONFIG(.color = ((initialElementsLength + initialRootsLength) & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1)) { Clay_ElementId panelContentsId = CLAY_ID("Clay__DebugViewPaneOuter"); CLAY_FLOATING_CONTAINER(panelContentsId, CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_FLOATING_CONFIG()) { - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewPane"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .padding = {.x = CLAY__DEBUGVIEW_OUTER_PADDING })) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .padding = {.x = CLAY__DEBUGVIEW_OUTER_PADDING }, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { layoutData = Clay__RenderDebugLayoutElementsList((int32_t)initialRootsLength, highlightedRow); } } float contentWidth = Clay__GetHashMapItem(panelContentsId.id)->layoutElement->dimensions.width; - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewScrollPanelWidth"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_FIXED(contentWidth)})) {} + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewScrollPanelWidth"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED(contentWidth)}, .layoutDirection = CLAY_TOP_TO_BOTTOM)) {} for (uint32_t i = 0; i < layoutData.rowCount; i++) { Clay_Color rowColor = (i & 1) == 0 ? CLAY__DEBUGVIEW_COLOR_2 : CLAY__DEBUGVIEW_COLOR_1; if (i == layoutData.selectedElementRowIndex) { @@ -2796,7 +2796,7 @@ void Clay__RenderDebugView() { rowColor.g *= 1.25f; rowColor.b *= 1.25f; } - CLAY_RECTANGLE(CLAY_IDI("Clay__DebugViewStripe", i), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}), CLAY_RECTANGLE_CONFIG(.color = rowColor)) {} + CLAY_RECTANGLE(CLAY_IDI("Clay__DebugViewStripe", i), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .layoutDirection = CLAY_TOP_TO_BOTTOM), CLAY_RECTANGLE_CONFIG(.color = rowColor)) {} } } } @@ -2804,8 +2804,8 @@ void Clay__RenderDebugView() { if (Clay__debugSelectedElementId != 0) { Clay_LayoutElementHashMapItem *selectedItem = Clay__GetHashMapItem(Clay__debugSelectedElementId); CLAY_SCROLL_CONTAINER(CLAY_ID("Clay__DebugViewInfoScrollPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(300)}, .childGap = 6), CLAY_SCROLL_CONFIG(.vertical = true)) { - CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewElementInfoPane"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoItemHeader"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING})) { + CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewElementInfoPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .layoutDirection = CLAY_TOP_TO_BOTTOM), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoItemHeader"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER})) { CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoTitleId", 1), CLAY_STRING("Layout Config"), infoTextConfig); CLAY_CONTAINER(CLAY_IDI("Clay__DebugViewElementInfoTitleSpacer", 1), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW() })) {} CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoTitle", 2), selectedItem->elementId.stringId, infoTitleConfig); @@ -2817,7 +2817,7 @@ void Clay__RenderDebugView() { } // Clay_LayoutConfig debug info CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewElementInfoTopBorder"), CLAY_LAYOUT(.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED(1)}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_3)) {} - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoLayoutBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoLayoutBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .boundingBox CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoLayoutTitle", 1), CLAY_STRING("Bounding Box"), infoTitleConfig); CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoLayoutBoundingBox"), CLAY_LAYOUT()) { @@ -2884,7 +2884,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE: { Clay_RectangleElementConfig *rectangleConfig = selectedItem->layoutElement->elementConfig.rectangleElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Rectangle Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoRectangleBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoRectangleBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .color CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoRectangleColorTitle", 1), CLAY_STRING("Color"), infoTitleConfig); Clay__RenderDebugViewColor(rectangleConfig->color, infoTextConfig); @@ -2897,7 +2897,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_TEXT: { Clay_TextElementConfig *textConfig = selectedItem->layoutElement->elementConfig.textElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Text Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoRectangleBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoRectangleBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .fontSize CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoRectangleFontTitle", 1), CLAY_STRING("Font Size"), infoTitleConfig); CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoRectangleFontBody", 1), Clay__IntToString(textConfig->fontSize), infoTextConfig); @@ -2928,7 +2928,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_IMAGE: { Clay_ImageElementConfig *imageConfig = selectedItem->layoutElement->elementConfig.imageElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Image Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoImageBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoImageBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .sourceDimensions CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoImageTitle", 1), CLAY_STRING("Source Dimensions"), infoTitleConfig); CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoImageDimensions"), CLAY_LAYOUT()) { @@ -2947,7 +2947,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER: { Clay_ScrollElementConfig *scrollConfig = selectedItem->layoutElement->elementConfig.scrollElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Scroll Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoScrollBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoScrollBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .vertical CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoScrollTitle", 1), CLAY_STRING("Vertical"), infoTitleConfig); CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoImageVerticalData", 1), scrollConfig->vertical ? CLAY_STRING("true") : CLAY_STRING("false") , infoTextConfig); @@ -2960,7 +2960,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER: { Clay_FloatingElementConfig *floatingConfig = selectedItem->layoutElement->elementConfig.floatingElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Floating Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoScrollBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoScrollBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .offset CLAY_TEXT(CLAY_IDI("Clay__DebugViewElementInfoFloatingTitle", 1), CLAY_STRING("Offset"), infoTitleConfig); CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoFloatingOffset"), CLAY_LAYOUT()) { @@ -2992,7 +2992,7 @@ void Clay__RenderDebugView() { case CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER: { Clay_BorderElementConfig *borderConfig = selectedItem->layoutElement->elementConfig.borderElementConfig; Clay__RenderDebugViewElementConfigHeader(selectedItem->elementId.stringId, CLAY_STRING("Border Element Config")); - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoBorderBody"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .padding = {8, 8}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewElementInfoBorderBody"), CLAY_LAYOUT(.padding = {8, 8}, .childGap = 8, .layoutDirection = CLAY_TOP_TO_BOTTOM)) { // .left CLAY_TEXT(CLAY_ID("Clay__DebugViewElementInfoBorderLeftTitle"), CLAY_STRING("Left Border"), infoTitleConfig); Clay__RenderDebugViewBorder(1, borderConfig->left, infoTextConfig); @@ -3022,17 +3022,17 @@ void Clay__RenderDebugView() { } } } else { - CLAY_SCROLL_CONTAINER(CLAY_ID("Clay__DebugViewWarningsScrollPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(300)}, .childGap = 6), CLAY_SCROLL_CONFIG(.vertical = true, .horizontal = true)) { - Clay_TextElementConfig *warningConfig = CLAY_TEXT_CONFIG(.fontSize = 16, .textColor = CLAY__DEBUGVIEW_COLOR_4, .wrapMode = CLAY_TEXT_WRAP_NONE); - CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewWarningsPane"), CLAY_LAYOUT(.layoutDirection = CLAY_TOP_TO_BOTTOM, .sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { - CLAY_CONTAINER(CLAY_ID("Clay__DebugViewWarningItemHeader"), CLAY_LAYOUT(.sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childGap = 8)) { + CLAY_SCROLL_CONTAINER(CLAY_ID("Clay__DebugViewWarningsScrollPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(300)}, .childGap = 6), CLAY_SCROLL_CONFIG(.horizontal = true, .vertical = true)) { + Clay_TextElementConfig *warningConfig = CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE); + CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewWarningsPane"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_GROW()}, .layoutDirection = CLAY_TOP_TO_BOTTOM), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { + CLAY_CONTAINER(CLAY_ID("Clay__DebugViewWarningItemHeader"), CLAY_LAYOUT(.sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER} )) { CLAY_TEXT(CLAY_ID("Clay__DebugViewWarningsTitle"), CLAY_STRING("Warnings"), warningConfig); } CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewWarningsTopBorder"), CLAY_LAYOUT(.sizing = { .width = CLAY_SIZING_GROW(), .height = CLAY_SIZING_FIXED(1)}), CLAY_RECTANGLE_CONFIG(.color = {200, 200, 200, 255})) {} int previousWarningsLength = (int)Clay_warnings.length; for (int i = 0; i < previousWarningsLength; i++) { Clay__Warning warning = Clay_warnings.internalArray[i]; - CLAY_CONTAINER(CLAY_IDI("Clay__DebugViewWarningItem", i), CLAY_LAYOUT(.sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childGap = 8)) { + CLAY_CONTAINER(CLAY_IDI("Clay__DebugViewWarningItem", i), CLAY_LAYOUT(.sizing = {.height = CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childGap = 8, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER})) { CLAY_TEXT(CLAY_IDI("Clay__DebugViewWarningText", i), warning.baseMessage, warningConfig); if (warning.dynamicMessage.length > 0) { CLAY_TEXT(CLAY_IDI("Clay__DebugViewWarningTextDynamic", i), warning.dynamicMessage, warningConfig); From 34878752ef435be840b9ff8de5ef65fac4fa929e Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:40:37 +1200 Subject: [PATCH 20/28] msvc --- clay.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/clay.h b/clay.h index 89fa40e9..dd8bba1b 100644 --- a/clay.h +++ b/clay.h @@ -2061,7 +2061,7 @@ void Clay__CalculateFinalLayout() { for (int i = 0; i < Clay__layoutElementTreeRoots.length; ++i) { Clay__LayoutElementTreeRoot *root = Clay__LayoutElementTreeRootArray_Get(&Clay__layoutElementTreeRoots, i); Clay__treeNodeVisited.internalArray[dfsBuffer.length] = false; - Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, (Clay__LayoutElementTreeNode) { .layoutElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, (int)root->layoutElementIndex) }); + Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, CLAY__INIT(Clay__LayoutElementTreeNode) { .layoutElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, (int)root->layoutElementIndex) }); } while (dfsBuffer.length > 0) { Clay__LayoutElementTreeNode *currentElementTreeNode = Clay__LayoutElementTreeNodeArray_Get(&dfsBuffer, (int)dfsBuffer.length - 1); @@ -2076,7 +2076,7 @@ void Clay__CalculateFinalLayout() { // Add the children to the DFS buffer (needs to be pushed in reverse so that stack traversal is in correct layout order) for (int i = 0; i < currentElement->children.length; i++) { Clay__treeNodeVisited.internalArray[dfsBuffer.length] = false; - Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, (Clay__LayoutElementTreeNode) { .layoutElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, currentElement->children.elements[i]) }); // TODO fix before release + Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, CLAY__INIT(Clay__LayoutElementTreeNode) { .layoutElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, currentElement->children.elements[i]) }); // TODO fix before release } continue; } @@ -2124,7 +2124,7 @@ void Clay__CalculateFinalLayout() { Clay_Dimensions rootDimensions = rootElement->dimensions; Clay_BoundingBox parentBoundingBox = parentHashMapItem->boundingBox; // Set X position - Clay_Vector2 targetAttachPosition = (Clay_Vector2){}; + Clay_Vector2 targetAttachPosition = CLAY__INIT(Clay_Vector2){}; switch (config->attachment.parent) { case CLAY_ATTACH_POINT_LEFT_TOP: case CLAY_ATTACH_POINT_LEFT_CENTER: @@ -2176,14 +2176,14 @@ void Clay__CalculateFinalLayout() { if (root->clipElementId) { Clay_LayoutElementHashMapItem *clipHashMapItem = Clay__GetHashMapItem(root->clipElementId); if (clipHashMapItem) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { .boundingBox = clipHashMapItem->boundingBox, .id = Clay__RehashWithNumber(rootElement->id, 10), // TODO need a better strategy for managing derived ids .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START, }); } } - Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, (Clay__LayoutElementTreeNode) { .layoutElement = rootElement, .position = rootPosition, .nextChildOffset = CLAY__INIT(Clay_Vector2) { .x = (float)rootElement->layoutConfig->padding.x, .y = (float)rootElement->layoutConfig->padding.y } }); + Clay__LayoutElementTreeNodeArray_Add(&dfsBuffer, CLAY__INIT(Clay__LayoutElementTreeNode) { .layoutElement = rootElement, .position = rootPosition, .nextChildOffset = CLAY__INIT(Clay_Vector2) { .x = (float)rootElement->layoutConfig->padding.x, .y = (float)rootElement->layoutConfig->padding.y } }); Clay__treeNodeVisited.internalArray[0] = false; while (dfsBuffer.length > 0) { @@ -2209,7 +2209,7 @@ void Clay__CalculateFinalLayout() { Clay__ScrollContainerDataInternal *scrollContainerData = CLAY__NULL; // Apply scroll offsets to container if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER) { - Clay_RenderCommandArray_Add(&Clay__renderCommands, (Clay_RenderCommand) { + Clay_RenderCommandArray_Add(&Clay__renderCommands, CLAY__INIT(Clay_RenderCommand) { .boundingBox = currentElementBoundingBox, .id = Clay__RehashWithNumber(currentElement->id, 10), .commandType = CLAY_RENDER_COMMAND_TYPE_SCISSOR_START, @@ -2410,7 +2410,7 @@ void Clay__CalculateFinalLayout() { // DFS buffer elements need to be added in reverse because stack traversal happens backwards uint32_t newNodeIndex = dfsBuffer.length - 1 - i; - dfsBuffer.internalArray[newNodeIndex] = (Clay__LayoutElementTreeNode) { + dfsBuffer.internalArray[newNodeIndex] = CLAY__INIT(Clay__LayoutElementTreeNode) { .layoutElement = childElement, .position = CLAY__INIT(Clay_Vector2) { childPosition.x, childPosition.y }, .nextChildOffset = CLAY__INIT(Clay_Vector2) { .x = (float)childElement->layoutConfig->padding.x, .y = (float)childElement->layoutConfig->padding.y }, @@ -3173,8 +3173,8 @@ void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDe } scrollData->pointerScrollActive = false; - scrollData->pointerOrigin = (Clay_Vector2){0,0}; - scrollData->scrollOrigin = (Clay_Vector2){0,0}; + scrollData->pointerOrigin = CLAY__INIT(Clay_Vector2){0,0}; + scrollData->scrollOrigin = CLAY__INIT(Clay_Vector2){0,0}; scrollData->momentumTime = 0; } @@ -3215,7 +3215,7 @@ void Clay_UpdateScrollContainers(bool enableDragScrolling, Clay_Vector2 scrollDe } // Handle click / touch scroll if (isPointerActive) { - highestPriorityScrollData->scrollMomentum = (Clay_Vector2){0}; + highestPriorityScrollData->scrollMomentum = CLAY__INIT(Clay_Vector2){0}; if (!highestPriorityScrollData->pointerScrollActive) { highestPriorityScrollData->pointerOrigin = Clay__pointerInfo.position; highestPriorityScrollData->scrollOrigin = highestPriorityScrollData->scrollPosition; From 0653fa64f0ed3a7dd94348f7f3b840b267bba5d2 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:43:48 +1200 Subject: [PATCH 21/28] msvc --- clay.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/clay.h b/clay.h index dd8bba1b..ea0a202b 100644 --- a/clay.h +++ b/clay.h @@ -62,9 +62,9 @@ #define CLAY_CORNER_RADIUS(radius) CLAY__INIT(Clay_CornerRadius) { radius, radius, radius, radius } -#define CLAY_SIZING_FIT(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_FIT } +#define CLAY_SIZING_FIT(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = CLAY__INIT(Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_FIT } -#define CLAY_SIZING_GROW(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = (Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_GROW } +#define CLAY_SIZING_GROW(...) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = CLAY__INIT(Clay_SizingMinMax) {__VA_ARGS__}, .type = CLAY__SIZING_TYPE_GROW } #define CLAY_SIZING_FIXED(fixedSize) CLAY__INIT(Clay_SizingAxis) { .sizeMinMax = { fixedSize, fixedSize }, .type = CLAY__SIZING_TYPE_GROW } @@ -2196,7 +2196,7 @@ void Clay__CalculateFinalLayout() { if (!Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1]) { Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true; - Clay_BoundingBox currentElementBoundingBox = (Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height }; + Clay_BoundingBox currentElementBoundingBox = CLAY__INIT(Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height }; if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER) { Clay_FloatingElementConfig *floatingElementConfig = currentElement->elementConfig.floatingElementConfig; Clay_Dimensions expand = floatingElementConfig->expand; @@ -2325,7 +2325,7 @@ void Clay__CalculateFinalLayout() { }); // Borders between elements are expressed as additional rectangle render commands } else if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER) { - Clay_BoundingBox currentElementBoundingBox = (Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height }; + Clay_BoundingBox currentElementBoundingBox = CLAY__INIT(Clay_BoundingBox) { currentElementTreeNode->position.x, currentElementTreeNode->position.y, currentElement->dimensions.width, currentElement->dimensions.height }; #ifndef CLAY_DISABLE_CULLING bool offscreen = currentElementBoundingBox.x > (float)Clay__layoutDimensions.width || currentElementBoundingBox.y > (float)Clay__layoutDimensions.height || currentElementBoundingBox.x + currentElementBoundingBox.width < 0 || currentElementBoundingBox.y + currentElementBoundingBox.height < 0; if (offscreen) { @@ -2451,7 +2451,7 @@ Clay_Color CLAY__DEBUGVIEW_COLOR_SELECTED_ROW = CLAY__INIT(Clay_Color) {102, 80, const int CLAY__DEBUGVIEW_ROW_HEIGHT = 30; const int CLAY__DEBUGVIEW_OUTER_PADDING = 10; const int CLAY__DEBUGVIEW_INDENT_WIDTH = 16; -Clay_TextElementConfig Clay__DebugView_TextNameConfig = (Clay_TextElementConfig) {.textColor = {238, 226, 231, 255}, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }; +Clay_TextElementConfig Clay__DebugView_TextNameConfig = CLAY__INIT(Clay_TextElementConfig) {.textColor = {238, 226, 231, 255}, .fontSize = 16, .wrapMode = CLAY_TEXT_WRAP_NONE }; Clay_LayoutConfig Clay__DebugView_ScrollViewItemLayoutConfig = CLAY__INIT(Clay_LayoutConfig) {}; Clay_String Clay__IntToString(int integer) { @@ -3095,7 +3095,7 @@ void Clay_SetPointerState(Clay_Vector2 position, bool isPointerDown) { Clay__treeNodeVisited.internalArray[dfsBuffer.length - 1] = true; Clay_LayoutElement *currentElement = Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&dfsBuffer, (int)dfsBuffer.length - 1)); Clay_LayoutElementHashMapItem *mapItem = Clay__GetHashMapItem(currentElement->id); // TODO I wish there was a way around this, maybe the fact that it's essentially a binary tree limits the cost, have to measure - if ((mapItem && Clay__PointIsInsideRect(position, mapItem->boundingBox)) || (!mapItem && Clay__PointIsInsideRect(position, (Clay_BoundingBox) {0,0, currentElement->dimensions.width, currentElement->dimensions.height}))) { + if ((mapItem && Clay__PointIsInsideRect(position, mapItem->boundingBox)) || (!mapItem && Clay__PointIsInsideRect(position, CLAY__INIT(Clay_BoundingBox) {0,0, currentElement->dimensions.width, currentElement->dimensions.height}))) { Clay__ElementIdArray_Add(&Clay__pointerOverIds, mapItem->elementId); if (currentElement->elementType == CLAY__LAYOUT_ELEMENT_TYPE_TEXT) { dfsBuffer.length--; From 0e255aae74cc4b65a1b59f0b19db2058722a9cf2 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:47:26 +1200 Subject: [PATCH 22/28] msvc --- clay.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clay.h b/clay.h index ea0a202b..5c334d51 100644 --- a/clay.h +++ b/clay.h @@ -2571,7 +2571,7 @@ Clay__RenderDebugLayoutData Clay__RenderDebugLayoutElementsList(int32_t initialR CLAY_CONTAINER(Clay__Rehash(outerHighlightId, currentElement->id), CLAY_LAYOUT(.padding = {0,4}, .childGap = 12, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER })) { if (currentElementData) { if (currentElementData->debugData->collision) { - CLAY_BORDER_CONTAINER(Clay__Rehash(elementOffscreenBorderId, currentElement->id), CLAY_LAYOUT(.padding = { 8, 2 }), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, ((Clay_Color){177, 147, 8, 255}), 4)) { + CLAY_BORDER_CONTAINER(Clay__Rehash(elementOffscreenBorderId, currentElement->id), CLAY_LAYOUT(.padding = { 8, 2 }), CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, (CLAY__INIT(Clay_Color){177, 147, 8, 255}), 4)) { CLAY_TEXT(Clay__Rehash(elementDuplicateWarning, currentElement->id), CLAY_STRING("Duplicate ID"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_3, .fontSize = 16)); } } @@ -2769,8 +2769,8 @@ void Clay__RenderDebugView() { CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderOuter"), CLAY_LAYOUT(.sizing = {CLAY_SIZING_GROW(), CLAY_SIZING_FIXED(CLAY__DEBUGVIEW_ROW_HEIGHT)}, .padding = {CLAY__DEBUGVIEW_OUTER_PADDING}, .childAlignment = {.y = CLAY_ALIGN_Y_CENTER}), CLAY_RECTANGLE_CONFIG(.color = CLAY__DEBUGVIEW_COLOR_2)) { CLAY_TEXT(CLAY_IDI("Clay__DebugViewTopHeaderId", 1), CLAY_STRING("Clay Debug Tools"), infoTextConfig); CLAY_CONTAINER(CLAY_ID("Clay__DebugViewTopHeaderSpacer"), CLAY_LAYOUT(.sizing = { CLAY_SIZING_GROW() })) {} - CLAY_BORDER_CONTAINER(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonOuter"), &CLAY_LAYOUT_DEFAULT, CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, ((Clay_Color){217,91,67,255}), 4)) { - CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonInner"), 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}), CLAY_RECTANGLE_CONFIG(.color = ((Clay_Color){217,91,67,80}))) { + CLAY_BORDER_CONTAINER(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonOuter"), &CLAY_LAYOUT_DEFAULT, CLAY_BORDER_CONFIG_OUTSIDE_RADIUS(1, (CLAY__INIT(Clay_Color){217,91,67,255}), 4)) { + CLAY_RECTANGLE(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonInner"), 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}), CLAY_RECTANGLE_CONFIG(.color = (CLAY__INIT(Clay_Color){217,91,67,80}))) { CLAY_TEXT(CLAY_ID("Clay__DebugViewTopHeaderCloseButtonText"), CLAY_STRING("x"), CLAY_TEXT_CONFIG(.textColor = CLAY__DEBUGVIEW_COLOR_4, .fontSize = 16)); } } @@ -3051,7 +3051,7 @@ void Clay__RenderDebugView() { CLAY_WASM_EXPORT("Clay_MinMemorySize") uint32_t Clay_MinMemorySize() { - Clay_Arena fakeArena = (Clay_Arena) { .capacity = INT64_MAX }; + Clay_Arena fakeArena = CLAY__INIT(Clay_Arena) { .capacity = INT64_MAX }; Clay__InitializePersistentMemory(&fakeArena); Clay__InitializeEphemeralMemory(&fakeArena); return fakeArena.nextAllocation; @@ -3059,7 +3059,7 @@ uint32_t Clay_MinMemorySize() { CLAY_WASM_EXPORT("Clay_CreateArenaWithCapacityAndMemory") Clay_Arena Clay_CreateArenaWithCapacityAndMemory(uint32_t capacity, void *offset) { - Clay_Arena arena = (Clay_Arena) { + Clay_Arena arena = CLAY__INIT(Clay_Arena) { .capacity = capacity, .memory = (char *)offset }; @@ -3264,7 +3264,7 @@ void Clay_BeginLayout() { rootDimensions.width -= (float)Clay__debugViewWidth; } Clay_ElementId rootElementId = CLAY_ID("Clay__RootContainer"); - Clay_LayoutElement rootLayoutElement = (Clay_LayoutElement){.layoutConfig = CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)}), .id = rootElementId.id, }; + Clay_LayoutElement rootLayoutElement = CLAY__INIT(Clay_LayoutElement) {.layoutConfig = CLAY_LAYOUT(.sizing = {CLAY_SIZING_FIXED((rootDimensions.width)), CLAY_SIZING_FIXED(rootDimensions.height)}), .id = rootElementId.id, }; Clay__openLayoutElement = Clay_LayoutElementArray_Add(&Clay__layoutElements, rootLayoutElement); Clay__LayoutElementPointerArray_Add(&Clay__openLayoutElementStack, Clay__openLayoutElement); Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, CLAY__INIT(Clay__LayoutElementTreeRoot) { .layoutElementIndex = Clay__layoutElements.length - 1 }); @@ -3304,7 +3304,7 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) { for (int i = 0; i < Clay__scrollContainerDatas.length; ++i) { Clay__ScrollContainerDataInternal *scrollContainerData = Clay__ScrollContainerDataInternalArray_Get(&Clay__scrollContainerDatas, i); if (scrollContainerData->elementId == id.id) { - return (Clay_ScrollContainerData) { + return CLAY__INIT(Clay_ScrollContainerData) { .scrollPosition = &scrollContainerData->scrollPosition, .scrollContainerDimensions = CLAY__INIT(Clay_Dimensions) { scrollContainerData->boundingBox.width, scrollContainerData->boundingBox.height }, .contentDimensions = scrollContainerData->contentSize, @@ -3313,7 +3313,7 @@ Clay_ScrollContainerData Clay_GetScrollContainerData(Clay_ElementId id) { }; } } - return (Clay_ScrollContainerData){}; + return CLAY__INIT(Clay_ScrollContainerData) {}; } CLAY_WASM_EXPORT("Clay_SetDebugModeEnabled") From 48cb2f3951ab31e76fcd76bb6e6cc3a171f4e22f Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:50:06 +1200 Subject: [PATCH 23/28] fix main.cpp --- examples/cpp-project-example/main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cpp-project-example/main.cpp b/examples/cpp-project-example/main.cpp index 9048d257..56062bd6 100644 --- a/examples/cpp-project-example/main.cpp +++ b/examples/cpp-project-example/main.cpp @@ -4,7 +4,7 @@ int main(void) { uint64_t totalMemorySize = Clay_MinMemorySize(); - Clay_Arena clayMemory = (Clay_Arena) { .label = CLAY_STRING("Clay Memory Arena"), .capacity = totalMemorySize, .memory = (char *)malloc(totalMemorySize) }; - Clay_Initialize(clayMemory, (Clay_Dimensions) {1024,768}); + Clay_Arena clayMemory = Clay_Arena { .label = CLAY_STRING("Clay Memory Arena"), .capacity = totalMemorySize, .memory = (char *)malloc(totalMemorySize) }; + Clay_Initialize(clayMemory, Clay_Dimensions {1024,768}); return 0; } From e9e55000778231e92cae3e7cb2f70da7b0fc3cd2 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:53:42 +1200 Subject: [PATCH 24/28] build projects on other platforms --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bbe6d11..6adf9f9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 3.28) project(clay) -if(!MSVC) +add_subdirectory("examples/cpp-project-example") + +if(NOT MSVC) add_subdirectory("examples/raylib-sidebar-scrolling-container") add_subdirectory("examples/clay-official-website") -else() -add_subdirectory("examples/cpp-project-example") endif() \ No newline at end of file From a790e21d4e0b4571e8bbdd5404b2bb82363ae0e8 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:56:40 +1200 Subject: [PATCH 25/28] fix bad ifdef --- clay.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clay.h b/clay.h index 5c334d51..7bc5e5da 100644 --- a/clay.h +++ b/clay.h @@ -455,9 +455,9 @@ extern uint32_t Clay__debugViewWidth; #ifdef __cplusplus #define CLAY__ALIGNMENT(type) alignof(type) #define CLAY__INIT(type) type -#elif +#else #define CLAY__INIT(type) (type) -#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; } a, a.x)) +#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x)) #endif bool Clay__warningsEnabled = true; From f1d1079faf3401831f05d2e44d3c16c68dafafb9 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sat, 28 Sep 2024 21:59:55 +1200 Subject: [PATCH 26/28] more fixes to bad macros --- clay.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clay.h b/clay.h index 7bc5e5da..8d491693 100644 --- a/clay.h +++ b/clay.h @@ -112,6 +112,14 @@ static int CLAY__ELEMENT_DEFINITION_LATCH = 0; children \ Clay__CloseElementWithChildren() +#ifdef __cplusplus +#define CLAY__ALIGNMENT(type) alignof(type) +#define CLAY__INIT(type) type +#else +#define CLAY__INIT(type) (type) +#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x)) +#endif + #ifdef __cplusplus extern "C" { #endif @@ -452,14 +460,6 @@ extern uint32_t Clay__debugViewWidth; #define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y)) #define CLAY__MIN(x, y) (((x) < (y)) ? (x) : (y)) -#ifdef __cplusplus -#define CLAY__ALIGNMENT(type) alignof(type) -#define CLAY__INIT(type) type -#else -#define CLAY__INIT(type) (type) -#define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x)) -#endif - bool Clay__warningsEnabled = true; Clay_String CLAY__SPACECHAR = CLAY__INIT(Clay_String) { .length = 1, .chars = " " }; From 24c4bcd56543beece1741ba3f915ea3672fe478a Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sun, 29 Sep 2024 12:36:46 +1300 Subject: [PATCH 27/28] Pack enums in c++ --- clay.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clay.h b/clay.h index 8d491693..bd9d3f9c 100644 --- a/clay.h +++ b/clay.h @@ -29,7 +29,7 @@ #endif #ifdef _MSC_VER -#define CLAY_PACKED_ENUM +#define CLAY_PACKED_ENUM : uint8_t #else #define CLAY_PACKED_ENUM __attribute__((__packed__)) #endif From d68af1cbe08f55ee123b613a01f10e198984b130 Mon Sep 17 00:00:00 2001 From: Nic Barker Date: Sun, 29 Sep 2024 12:49:06 +1300 Subject: [PATCH 28/28] Final tweaks --- .github/workflows/cmake-multi-platform.yml | 2 -- CMakeLists.txt | 1 + README.md | 6 ++++-- clay.h | 10 +++------- examples/clay-official-website/CMakeLists.txt | 2 -- .../raylib-sidebar-scrolling-container/CMakeLists.txt | 1 + 6 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index e94e0128..9d138300 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -1,5 +1,3 @@ -# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. -# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml name: CMake on multiple platforms on: diff --git a/CMakeLists.txt b/CMakeLists.txt index 6adf9f9d..cce9bb9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(clay) 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/clay-official-website") diff --git a/README.md b/README.md index 63e5c6e5..396c0efc 100644 --- a/README.md +++ b/README.md @@ -394,13 +394,15 @@ The supported directives are: - `CLAY_EXTEND_CONFIG_IMAGE` - Provide additional struct members to `CLAY_IMAGE_CONFIG` that will be passed through with output render commands. - `CLAY_EXTEND_CONFIG_CUSTOM` - Provide additional struct members to `CLAY_IMAGE_CONFIG` that will be passed through with output render commands. -### Bindings +### Bindings for non C -Clay is usable out of the box as a `.h` include in both C99 and C++ with designated initializer support. +Clay is usable out of the box as a `.h` include in both C99 and C++20 with designated initializer support. There are also supported bindings for other languages, including: - [Odin Bindings](https://github.com/nicbarker/clay/tree/main/bindings/odin) +Unfortunately clay does **not** support Microsoft C11 or C17 via MSVC at this time. + ### Debug Tools Clay includes built-in UI debugging tools, similar to the "inspector" in browsers such as Chrome or Firefox. These tools are included in `clay.h`, and work by injecting additional render commands into the output [Clay_RenderCommandArray](#clay_rendercommandarray). diff --git a/clay.h b/clay.h index bd9d3f9c..2bb857d4 100644 --- a/clay.h +++ b/clay.h @@ -28,12 +28,6 @@ #define CLAY_WASM_EXPORT(null) #endif -#ifdef _MSC_VER -#define CLAY_PACKED_ENUM : uint8_t -#else -#define CLAY_PACKED_ENUM __attribute__((__packed__)) -#endif - // Public Macro API ------------------------ #define CLAY_LAYOUT(...) Clay__StoreLayoutConfig(CLAY__INIT(Clay_LayoutConfig) {__VA_ARGS__ }) @@ -113,11 +107,13 @@ static int CLAY__ELEMENT_DEFINITION_LATCH = 0; Clay__CloseElementWithChildren() #ifdef __cplusplus -#define CLAY__ALIGNMENT(type) alignof(type) #define CLAY__INIT(type) type +#define CLAY__ALIGNMENT(type) alignof(type) +#define CLAY_PACKED_ENUM : uint8_t #else #define CLAY__INIT(type) (type) #define CLAY__ALIGNMENT(type) (offsetof(struct { char c; type x; }, x)) +#define CLAY_PACKED_ENUM __attribute__((__packed__)) #endif #ifdef __cplusplus diff --git a/examples/clay-official-website/CMakeLists.txt b/examples/clay-official-website/CMakeLists.txt index bca47c8d..65087bbc 100644 --- a/examples/clay-official-website/CMakeLists.txt +++ b/examples/clay-official-website/CMakeLists.txt @@ -5,9 +5,7 @@ set(CMAKE_C_STANDARD 99) add_executable(clay_official_website main.c) -if(!MSVC) target_compile_options(clay_official_website PUBLIC -Wall -Werror -Wno-unknown-pragmas) -endif() target_include_directories(clay_official_website PUBLIC .) set(CMAKE_CXX_FLAGS_RELEASE "-O3") \ No newline at end of file diff --git a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt index 9d185d18..f93f628a 100644 --- a/examples/raylib-sidebar-scrolling-container/CMakeLists.txt +++ b/examples/raylib-sidebar-scrolling-container/CMakeLists.txt @@ -1,5 +1,6 @@ cmake_minimum_required(VERSION 3.28) project(clay_examples_raylib_sidebar_scrolling_container C) +set(CMAKE_C_STANDARD 99) # Adding Raylib include(FetchContent)