Compare commits

...

6 Commits

Author SHA1 Message Date
Bach Le
b7113fb64d
Merge 3edfe3f296 into 902ff3b0a9 2024-12-31 17:06:11 -08:00
Stowy
902ff3b0a9
Fixed compilation using clang on windows (#134)
Some checks failed
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 12s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 10s
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Has been cancelled
2024-12-31 17:51:18 +13:00
SuperOpt
2938c00dc8
[Renderers/Cairo] Add FindCairo.cmake (#122) 2024-12-31 13:32:56 +13:00
SuperOpt
ba78b35604
C++ projects should use CXX flags (#136) 2024-12-31 13:29:49 +13:00
Bach Le
3edfe3f296
Merge branch 'main' into local-id-fix 2024-11-18 16:36:32 +08:00
Bach Le
d8cfd6dbb9 Fix local id calculation 2024-11-18 08:57:40 +08:00
5 changed files with 50 additions and 7 deletions

View File

@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.27) cmake_minimum_required(VERSION 3.27)
project(clay) project(clay)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
add_subdirectory("examples/cpp-project-example") add_subdirectory("examples/cpp-project-example")
# Don't try to compile C99 projects using MSVC # Don't try to compile C99 projects using MSVC

9
clay.h
View File

@ -84,7 +84,7 @@
#define CLAY_ID_LOCAL(label) CLAY_IDI_LOCAL(label, 0) #define CLAY_ID_LOCAL(label) CLAY_IDI_LOCAL(label, 0)
#define CLAY_IDI_LOCAL(label, index) Clay__AttachId(Clay__HashString(CLAY_STRING(label), Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&Clay__openLayoutElementStack, Clay__openLayoutElementStack.length - 2))->children.length + 1, Clay__GetOpenLayoutElement()->id)) #define CLAY_IDI_LOCAL(label, index) Clay__AttachId(Clay__HashString(CLAY_STRING(label), index, Clay__GetParentElementId()))
#define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0])) #define CLAY__STRING_LENGTH(s) ((sizeof(s) / sizeof((s)[0])) - sizeof((s)[0]))
@ -134,7 +134,7 @@ CLAY__ALIGNMENT_STRUCT(bool);
CLAY__ALIGNMENT_STRUCT(uint8_t); CLAY__ALIGNMENT_STRUCT(uint8_t);
CLAY__ALIGNMENT_STRUCT(int32_t); CLAY__ALIGNMENT_STRUCT(int32_t);
#ifdef _MSC_VER #if defined(_MSC_VER) && !defined(__clang__)
#define CLAY_PACKED_ENUM __pragma(pack(push, 1)) enum __pragma(pack(pop)) #define CLAY_PACKED_ENUM __pragma(pack(push, 1)) enum __pragma(pack(pop))
#else #else
#define CLAY_PACKED_ENUM enum __attribute__((__packed__)) #define CLAY_PACKED_ENUM enum __attribute__((__packed__))
@ -504,6 +504,7 @@ Clay_BorderElementConfig * Clay__StoreBorderElementConfig(Clay_BorderElementConf
Clay_ElementId Clay__HashString(Clay_String key, uint32_t offset, uint32_t seed); Clay_ElementId Clay__HashString(Clay_String key, uint32_t offset, uint32_t seed);
void Clay__Noop(void); void Clay__Noop(void);
void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig); void Clay__OpenTextElement(Clay_String text, Clay_TextElementConfig *textConfig);
uint32_t Clay__GetParentElementId(void);
extern Clay_Color Clay__debugViewHighlightColor; extern Clay_Color Clay__debugViewHighlightColor;
extern uint32_t Clay__debugViewWidth; extern uint32_t Clay__debugViewWidth;
@ -1476,6 +1477,10 @@ Clay_LayoutElement* Clay__GetOpenLayoutElement(void) {
return Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&Clay__openLayoutElementStack, Clay__openLayoutElementStack.length - 1)); return Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&Clay__openLayoutElementStack, Clay__openLayoutElementStack.length - 1));
} }
uint32_t Clay__GetParentElementId(void) {
return Clay_LayoutElementArray_Get(&Clay__layoutElements, Clay__int32_tArray_Get(&Clay__openLayoutElementStack, Clay__openLayoutElementStack.length - 2))->id;
}
bool Clay__ElementHasConfig(Clay_LayoutElement *element, Clay__ElementConfigType type) { bool Clay__ElementHasConfig(Clay_LayoutElement *element, Clay__ElementConfigType type) {
return (element->configsEnabled & type); return (element->configsEnabled & type);
} }

32
cmake/FindCairo.cmake Normal file
View File

@ -0,0 +1,32 @@
# Defines:
# CAIRO_FOUND - System has Cairo
# CAIRO_INCLUDE_DIRS - Cairo include directories
# CAIRO_LIBRARY - Cairo library
# Cairo::Cairo - Imported target
find_path(CAIRO_INCLUDE_DIRS
NAMES cairo/cairo.h
PATHS ${CAIRO_ROOT_DIR}
PATH_SUFFIXES include
)
find_library(CAIRO_LIBRARY
NAMES cairo
PATHS ${CAIRO_ROOT_DIR}
PATH_SUFFIXES lib lib64
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Cairo
REQUIRED_VARS CAIRO_LIBRARY CAIRO_INCLUDE_DIRS
)
if(Cairo_FOUND AND NOT TARGET Cairo::Cairo)
add_library(Cairo::Cairo UNKNOWN IMPORTED)
set_target_properties(Cairo::Cairo PROPERTIES
IMPORTED_LOCATION "${CAIRO_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CAIRO_INCLUDE_DIRS}"
)
endif()
mark_as_advanced(CAIRO_INCLUDE_DIRS CAIRO_LIBRARY)

View File

@ -2,13 +2,17 @@ cmake_minimum_required(VERSION 3.27)
project(clay_examples_cairo_pdf_rendering C) project(clay_examples_cairo_pdf_rendering C)
set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD 99)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../cmake")
add_executable(clay_examples_cairo_pdf_rendering main.c) add_executable(clay_examples_cairo_pdf_rendering main.c)
find_package(Cairo REQUIRED)
target_compile_options(clay_examples_cairo_pdf_rendering PUBLIC) target_compile_options(clay_examples_cairo_pdf_rendering PUBLIC)
target_include_directories(clay_examples_cairo_pdf_rendering PUBLIC .) target_include_directories(clay_examples_cairo_pdf_rendering PUBLIC . ${CAIRO_INCLUDE_DIRS})
target_link_libraries(clay_examples_cairo_pdf_rendering PUBLIC cairo)
target_link_libraries(clay_examples_cairo_pdf_rendering PUBLIC Cairo::Cairo)
set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces") set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -Wno-error=missing-braces")
set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_C_FLAGS_RELEASE "-O3")

View File

@ -8,5 +8,5 @@ add_executable(clay_examples_cpp_project_example main.cpp)
target_include_directories(clay_examples_cpp_project_example PUBLIC .) target_include_directories(clay_examples_cpp_project_example PUBLIC .)
set(CMAKE_C_FLAGS_DEBUG "-Werror -Wall -Wno-error=missing-braces") set(CMAKE_CXX_FLAGS_DEBUG "-Werror -Wall -Wno-error=missing-braces")
set(CMAKE_C_FLAGS_RELEASE "-O3") set(CMAKE_CXX_FLAGS_RELEASE "-O3")