mirror of
https://github.com/nicbarker/clay.git
synced 2025-04-20 05:08:04 +00:00
C++ only on windows
This commit is contained in:
parent
fffe566931
commit
ee1e1bb95f
@ -1,12 +1,9 @@
|
|||||||
cmake_minimum_required(VERSION 3.28)
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(clay)
|
||||||
|
|
||||||
if (MSVC)
|
if(MSVC)
|
||||||
project(clay CXX)
|
add_subdirectory("examples/cpp-project-example")
|
||||||
set(CMAKE_CXX_STANDARD 20)
|
elseif()
|
||||||
else ()
|
|
||||||
project(clay C)
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
add_subdirectory("examples/raylib-sidebar-scrolling-container")
|
add_subdirectory("examples/raylib-sidebar-scrolling-container")
|
||||||
add_subdirectory("examples/clay-official-website")
|
add_subdirectory("examples/clay-official-website")
|
||||||
|
endif()
|
28
clay.h
28
clay.h
@ -452,7 +452,11 @@ extern uint32_t Clay__debugViewWidth;
|
|||||||
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
#define CLAY__MAX(x, y) (((x) > (y)) ? (x) : (y))
|
||||||
#define CLAY__MIN(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;
|
bool Clay__warningsEnabled = true;
|
||||||
|
|
||||||
@ -614,14 +618,14 @@ typedef enum CLAY_PACKED_ENUM {
|
|||||||
} Clay__LayoutElementType;
|
} Clay__LayoutElementType;
|
||||||
|
|
||||||
Clay_RenderCommandType Clay__LayoutElementTypeToRenderCommandType[] = {
|
Clay_RenderCommandType Clay__LayoutElementTypeToRenderCommandType[] = {
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE,
|
CLAY_RENDER_COMMAND_TYPE_NONE,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_RECTANGLE] = CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
CLAY_RENDER_COMMAND_TYPE_RECTANGLE,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_FLOATING_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE,
|
CLAY_RENDER_COMMAND_TYPE_NONE,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_SCROLL_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_NONE,
|
CLAY_RENDER_COMMAND_TYPE_NONE,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_BORDER_CONTAINER] = CLAY_RENDER_COMMAND_TYPE_BORDER,
|
CLAY_RENDER_COMMAND_TYPE_BORDER,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_IMAGE] = CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
CLAY_RENDER_COMMAND_TYPE_IMAGE,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_TEXT] = CLAY_RENDER_COMMAND_TYPE_TEXT,
|
CLAY_RENDER_COMMAND_TYPE_TEXT,
|
||||||
[CLAY__LAYOUT_ELEMENT_TYPE_CUSTOM] = CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
CLAY_RENDER_COMMAND_TYPE_CUSTOM,
|
||||||
};
|
};
|
||||||
|
|
||||||
Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){};
|
Clay_LayoutConfig CLAY_LAYOUT_DEFAULT = (Clay_LayoutConfig){};
|
||||||
@ -1414,7 +1418,7 @@ uint32_t Clay__HashTextWithConfig(Clay_String *text, Clay_TextElementConfig *con
|
|||||||
union {
|
union {
|
||||||
float fontSize;
|
float fontSize;
|
||||||
uint32_t bits;
|
uint32_t bits;
|
||||||
} fontSizeBits = { .fontSize = config->fontSize };
|
} fontSizeBits = { .fontSize = (float)config->fontSize };
|
||||||
uint32_t hash = 0;
|
uint32_t hash = 0;
|
||||||
uint64_t pointerAsNumber = (uint64_t)text->chars;
|
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) {
|
Clay__LayoutElementTreeRootArray_Add(&Clay__layoutElementTreeRoots, (Clay__LayoutElementTreeRoot) {
|
||||||
.layoutElementIndex = Clay__layoutElements.length - 1,
|
.layoutElementIndex = Clay__layoutElements.length - 1,
|
||||||
.parentId = parent->id,
|
.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,
|
.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;
|
highlightedRow = -1;
|
||||||
}
|
}
|
||||||
Clay__RenderDebugLayoutData layoutData = {};
|
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_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_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_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)) {
|
||||||
|
12
examples/cpp-project-example/CMakeLists.txt
Normal file
12
examples/cpp-project-example/CMakeLists.txt
Normal file
@ -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")
|
10
examples/cpp-project-example/main.cpp
Normal file
10
examples/cpp-project-example/main.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#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;
|
||||||
|
}
|
@ -1,5 +1,7 @@
|
|||||||
cmake_minimum_required(VERSION 3.28)
|
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
|
# Adding Raylib
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
@ -17,13 +19,8 @@ FetchContent_Declare(
|
|||||||
|
|
||||||
FetchContent_MakeAvailable(raylib)
|
FetchContent_MakeAvailable(raylib)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 99)
|
|
||||||
|
|
||||||
add_executable(clay_examples_raylib_sidebar_scrolling_container main.c multi-compilation-unit.c)
|
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_include_directories(clay_examples_raylib_sidebar_scrolling_container PUBLIC .)
|
||||||
|
|
||||||
target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib)
|
target_link_libraries(clay_examples_raylib_sidebar_scrolling_container PUBLIC raylib)
|
||||||
|
Loading…
Reference in New Issue
Block a user