Compare commits

...

5 Commits

Author SHA1 Message Date
Courtney Strachan
05c7e0e1aa
Merge 6cd721e647 into 3f01ee4a4e 2025-01-08 21:34:33 +00:00
Nic Barker
3f01ee4a4e Disable cairo example because of github actions issues
Some checks failed
CMake on multiple platforms / build (Release, cl, cl, windows-latest) (push) Waiting to run
CMake on multiple platforms / build (Release, clang, clang++, ubuntu-latest) (push) Failing after 15s
CMake on multiple platforms / build (Release, gcc, g++, ubuntu-latest) (push) Failing after 12s
2025-01-09 10:08:51 +13:00
FintasticMan
a431254de4
[Core] Add check for supported C/C++ versions (#144) 2025-01-09 10:05:50 +13:00
David Styrbjörn
7cc719e61f
[Documentation] Updated example for Clay_SetPointerState (#169) 2025-01-09 09:56:24 +13:00
Courtney Strachan
6cd721e647 Added missing public and private API function bindings 2025-01-07 22:37:58 -05:00
4 changed files with 61 additions and 21 deletions

View File

@ -8,7 +8,7 @@ add_subdirectory("examples/cpp-project-example")
# Don't try to compile C99 projects using MSVC # Don't try to compile C99 projects using MSVC
if(NOT MSVC) if(NOT MSVC)
add_subdirectory("examples/raylib-sidebar-scrolling-container") add_subdirectory("examples/raylib-sidebar-scrolling-container")
add_subdirectory("examples/cairo-pdf-rendering") # add_subdirectory("examples/cairo-pdf-rendering") Some issue with github actions populating cairo, disable for now
add_subdirectory("examples/clay-official-website") add_subdirectory("examples/clay-official-website")
add_subdirectory("examples/introducing-clay-video-demo") add_subdirectory("examples/introducing-clay-video-demo")
add_subdirectory("examples/SDL2-video-demo") add_subdirectory("examples/SDL2-video-demo")

View File

@ -100,7 +100,7 @@ Clay_RenderCommandArray CreateLayout() {
CLAY_RECTANGLE({ .color = COLOR_LIGHT }) CLAY_RECTANGLE({ .color = COLOR_LIGHT })
) { ) {
CLAY(CLAY_ID("ProfilePictureOuter"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_GROW() }, .padding = {16, 16}, .childGap = 16, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }), CLAY_RECTANGLE({ .color = COLOR_RED })) { CLAY(CLAY_ID("ProfilePictureOuter"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_GROW() }, .padding = {16, 16}, .childGap = 16, .childAlignment = { .y = CLAY_ALIGN_Y_CENTER }), CLAY_RECTANGLE({ .color = COLOR_RED })) {
CLAY(CLAY_ID("ProfilePicture"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}), CLAY_IMAGE({ .imageData = &profilePicture, .height = 60, .width = 60 })) {} CLAY(CLAY_ID("ProfilePicture"), CLAY_LAYOUT({ .sizing = { .width = CLAY_SIZING_FIXED(60), .height = CLAY_SIZING_FIXED(60) }}), CLAY_IMAGE({ .imageData = &profilePicture, .sourceDimensions = {60, 60} })) {}
CLAY_TEXT(CLAY_STRING("Clay - UI Library"), CLAY_TEXT_CONFIG({ .fontSize = 24, .textColor = {255, 255, 255, 255} })); CLAY_TEXT(CLAY_STRING("Clay - UI Library"), CLAY_TEXT_CONFIG({ .fontSize = 24, .textColor = {255, 255, 255, 255} }));
} }
@ -1059,11 +1059,11 @@ CLAY(CLAY_IMAGE({ .image = { .format = IMAGE_FORMAT_RGBA, .internalData = &image
// Load an image somewhere in your code // Load an image somewhere in your code
Image profilePicture = LoadImage("profilePicture.png"); Image profilePicture = LoadImage("profilePicture.png");
// Declare a reusable image config // Declare a reusable image config
Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .height = 60, .width = 60 }; Clay_ImageElementConfig imageConfig = (Clay_ImageElementConfig) { .imageData = &profilePicture, .sourceDimensions = {60, 60} };
// Declare an image element using a reusable config // Declare an image element using a reusable config
CLAY(CLAY_IMAGE(imageConfig)) {} CLAY(CLAY_IMAGE(imageConfig)) {}
// Declare an image element using an inline config // Declare an image element using an inline config
CLAY(CLAY_IMAGE({ .imageData = &profilePicture, .height = 60, .width = 60 })) {} CLAY(CLAY_IMAGE({ .imageData = &profilePicture, .sourceDimensions = {60, 60} })) {}
// Rendering example // Rendering example
Image *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData; Image *imageToRender = renderCommand->elementConfig.imageElementConfig->imageData;
``` ```

View File

@ -269,6 +269,18 @@ TypedConfig :: struct {
id: ElementId, id: ElementId,
} }
PointerDataInteractionState :: enum EnumBackingType {
PRESSED_THIS_FRAME,
PRESSED,
RELEASED_THIS_FRAME,
RELEASED,
}
PointerData :: struct {
position: Vector2,
state: PointerDataInteractionState,
}
ErrorType :: enum { ErrorType :: enum {
TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED, TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED,
ARENA_CAPACITY_EXCEEDED, ARENA_CAPACITY_EXCEEDED,
@ -282,12 +294,12 @@ ErrorType :: enum {
ErrorData :: struct { ErrorData :: struct {
errorType: ErrorType, errorType: ErrorType,
errorText: String, errorText: String,
userData: rawptr userData: rawptr,
} }
ErrorHandler :: struct { ErrorHandler :: struct {
handler: proc "c" (errorData: ErrorData), handler: proc "c" (errorData: ErrorData),
userData: rawptr userData: rawptr,
} }
@(link_prefix = "Clay_", default_calling_convention = "c") @(link_prefix = "Clay_", default_calling_convention = "c")
@ -300,24 +312,31 @@ foreign Clay {
SetLayoutDimensions :: proc(dimensions: Dimensions) --- SetLayoutDimensions :: proc(dimensions: Dimensions) ---
BeginLayout :: proc() --- BeginLayout :: proc() ---
EndLayout :: proc() -> ClayArray(RenderCommand) --- EndLayout :: proc() -> ClayArray(RenderCommand) ---
PointerOver :: proc(id: ElementId) -> bool ---
GetElementId :: proc(id: String) -> ElementId --- GetElementId :: proc(id: String) -> ElementId ---
GetElementIdWithIndex :: proc(id: String, index: u32) -> ElementId ---
Hovered :: proc() -> bool ---
OnHover :: proc(onHoverFunction: proc "c" (elementId: ElementId, pointerInfo: PointerData, userData: rawptr), userData: rawptr) ---
PointerOver :: proc(id: ElementId) -> bool ---
GetScrollContainerData :: proc(id: ElementId) -> ScrollContainerData --- GetScrollContainerData :: proc(id: ElementId) -> ScrollContainerData ---
SetMeasureTextFunction :: proc(measureTextFunction: proc "c" (text: ^String, config: ^TextElementConfig) -> Dimensions) --- SetMeasureTextFunction :: proc(measureTextFunction: proc "c" (text: ^String, config: ^TextElementConfig) -> Dimensions) ---
SetQueryScrollOffsetFunction :: proc(queryScrollOffsetFunction: proc "c" (elementId: u32) -> Vector2) ---
RenderCommandArray_Get :: proc(array: ^ClayArray(RenderCommand), index: i32) -> ^RenderCommand --- RenderCommandArray_Get :: proc(array: ^ClayArray(RenderCommand), index: i32) -> ^RenderCommand ---
SetDebugModeEnabled :: proc(enabled: bool) --- SetDebugModeEnabled :: proc(enabled: bool) ---
IsDebugModeEnabled :: proc() -> bool ---
SetCullingEnabled :: proc(enabled: bool) ---
SetMaxElementCount :: proc(maxElementCount: i32) ---
SetMaxMeasureTextCacheWordCount :: proc(maxMeasureTextCacheWordCount: i32) ---
} }
@(link_prefix = "Clay_", default_calling_convention = "c", private) @(link_prefix = "Clay_", default_calling_convention = "c", private)
foreign Clay { foreign Clay {
_OpenElement :: proc() --- _OpenElement :: proc() ---
_CloseElement :: proc() --- _CloseElement :: proc() ---
_StoreLayoutConfig :: proc(config: LayoutConfig) -> ^LayoutConfig ---
_ElementPostConfiguration :: proc() --- _ElementPostConfiguration :: proc() ---
_OpenTextElement :: proc(text: String, textConfig: ^TextElementConfig) ---
_AttachId :: proc(id: ElementId) --- _AttachId :: proc(id: ElementId) ---
_AttachLayoutConfig :: proc(layoutConfig: ^LayoutConfig) --- _AttachLayoutConfig :: proc(layoutConfig: ^LayoutConfig) ---
_AttachElementConfig :: proc(config: rawptr, type: ElementConfigType) --- _AttachElementConfig :: proc(config: rawptr, type: ElementConfigType) ---
_StoreLayoutConfig :: proc(config: LayoutConfig) -> ^LayoutConfig ---
_StoreRectangleElementConfig :: proc(config: RectangleElementConfig) -> ^RectangleElementConfig --- _StoreRectangleElementConfig :: proc(config: RectangleElementConfig) -> ^RectangleElementConfig ---
_StoreTextElementConfig :: proc(config: TextElementConfig) -> ^TextElementConfig --- _StoreTextElementConfig :: proc(config: TextElementConfig) -> ^TextElementConfig ---
_StoreImageElementConfig :: proc(config: ImageElementConfig) -> ^ImageElementConfig --- _StoreImageElementConfig :: proc(config: ImageElementConfig) -> ^ImageElementConfig ---
@ -326,7 +345,8 @@ foreign Clay {
_StoreScrollElementConfig :: proc(config: ScrollElementConfig) -> ^ScrollElementConfig --- _StoreScrollElementConfig :: proc(config: ScrollElementConfig) -> ^ScrollElementConfig ---
_StoreBorderElementConfig :: proc(config: BorderElementConfig) -> ^BorderElementConfig --- _StoreBorderElementConfig :: proc(config: BorderElementConfig) -> ^BorderElementConfig ---
_HashString :: proc(toHash: String, index: u32, seed: u32) -> ElementId --- _HashString :: proc(toHash: String, index: u32, seed: u32) -> ElementId ---
_GetOpenLayoutElementId :: proc() -> u32 --- _OpenTextElement :: proc(text: String, textConfig: ^TextElementConfig) ---
_GetParentElementId :: proc() -> u32 ---
} }
@(require_results, deferred_none = _CloseElement) @(require_results, deferred_none = _CloseElement)
@ -347,7 +367,7 @@ UI :: proc(configs: ..TypedConfig) -> bool {
} }
Layout :: proc(config: LayoutConfig) -> TypedConfig { Layout :: proc(config: LayoutConfig) -> TypedConfig {
return {type = ElementConfigType.Layout, config = _StoreLayoutConfig(config) } return {type = ElementConfigType.Layout, config = _StoreLayoutConfig(config)}
} }
Rectangle :: proc(config: RectangleElementConfig) -> TypedConfig { Rectangle :: proc(config: RectangleElementConfig) -> TypedConfig {
@ -383,23 +403,35 @@ Border :: proc(config: BorderElementConfig) -> TypedConfig {
} }
BorderOutside :: proc(outsideBorders: BorderData) -> TypedConfig { BorderOutside :: proc(outsideBorders: BorderData) -> TypedConfig {
return { type = ElementConfigType.Border, config = _StoreBorderElementConfig((BorderElementConfig){left = outsideBorders, right = outsideBorders, top = outsideBorders, bottom = outsideBorders}) } return {
type = ElementConfigType.Border,
config = _StoreBorderElementConfig((BorderElementConfig){left = outsideBorders, right = outsideBorders, top = outsideBorders, bottom = outsideBorders}),
}
} }
BorderOutsideRadius :: proc(outsideBorders: BorderData, radius: f32) -> TypedConfig { BorderOutsideRadius :: proc(outsideBorders: BorderData, radius: f32) -> TypedConfig {
return { type = ElementConfigType.Border, config = _StoreBorderElementConfig( return {
(BorderElementConfig){left = outsideBorders, right = outsideBorders, top = outsideBorders, bottom = outsideBorders, cornerRadius = {radius, radius, radius, radius}}, type = ElementConfigType.Border,
) } config = _StoreBorderElementConfig(
(BorderElementConfig){left = outsideBorders, right = outsideBorders, top = outsideBorders, bottom = outsideBorders, cornerRadius = {radius, radius, radius, radius}},
),
}
} }
BorderAll :: proc(allBorders: BorderData) -> TypedConfig { BorderAll :: proc(allBorders: BorderData) -> TypedConfig {
return { type = ElementConfigType.Border, config = _StoreBorderElementConfig((BorderElementConfig){left = allBorders, right = allBorders, top = allBorders, bottom = allBorders, betweenChildren = allBorders}) } return {
type = ElementConfigType.Border,
config = _StoreBorderElementConfig((BorderElementConfig){left = allBorders, right = allBorders, top = allBorders, bottom = allBorders, betweenChildren = allBorders}),
}
} }
BorderAllRadius :: proc(allBorders: BorderData, radius: f32) -> TypedConfig { BorderAllRadius :: proc(allBorders: BorderData, radius: f32) -> TypedConfig {
return { type = ElementConfigType.Border, config = _StoreBorderElementConfig( return {
(BorderElementConfig){left = allBorders, right = allBorders, top = allBorders, bottom = allBorders, cornerRadius = {radius, radius, radius, radius}}, type = ElementConfigType.Border,
) } config = _StoreBorderElementConfig(
(BorderElementConfig){left = allBorders, right = allBorders, top = allBorders, bottom = allBorders, cornerRadius = {radius, radius, radius, radius}},
),
}
} }
CornerRadiusAll :: proc(radius: f32) -> CornerRadius { CornerRadiusAll :: proc(radius: f32) -> CornerRadius {
@ -427,5 +459,5 @@ MakeString :: proc(label: string) -> String {
} }
ID :: proc(label: string, index: u32 = 0) -> TypedConfig { ID :: proc(label: string, index: u32 = 0) -> TypedConfig {
return { type = ElementConfigType.Id, id = _HashString(MakeString(label), index, 0) } return {type = ElementConfigType.Id, id = _HashString(MakeString(label), index, 0)}
} }

8
clay.h
View File

@ -21,6 +21,14 @@
#ifndef CLAY_HEADER #ifndef CLAY_HEADER
#define CLAY_HEADER #define CLAY_HEADER
#if !( \
(defined(__cplusplus) && __cplusplus >= 202002L) || \
(defined(__STDC__) && __STDC__ == 1 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
defined(_MSC_VER) \
)
#error "Clay requires C99, C++20, or MSVC"
#endif
#ifdef CLAY_WASM #ifdef CLAY_WASM
#define CLAY_WASM_EXPORT(name) __attribute__((export_name(name))) #define CLAY_WASM_EXPORT(name) __attribute__((export_name(name)))
#else #else