added missing clay function bindings

This commit is contained in:
johan0A 2025-01-31 15:44:56 +01:00
parent aabbf2c66e
commit a0fc7c7157
2 changed files with 28 additions and 25 deletions

View file

@ -53,6 +53,7 @@ const border_data = cl.BorderData{ .width = 2, .color = COLOR_RED };
var window_height: isize = 0;
var window_width: isize = 0;
var mobile_screen: bool = false;
fn landingPageBlob(index: u32, font_size: u16, font_id: u16, color: cl.Color, image_size: f32, max_width: f32, text: []const u8, image: *rl.Texture2D) void {
cl.UI(&.{
@ -451,7 +452,6 @@ fn rendererPageMobile() void {
}
fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
const mobileScreen = window_width < 750;
cl.beginLayout();
cl.UI(&.{
@ -475,7 +475,7 @@ fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
}));
cl.UI(&.{ .ID("HeaderSpacer"), .layout(.{ .sizing = .{ .w = .grow } }) })({});
if (!mobileScreen) {
if (!mobile_screen) {
cl.UI(&.{ .ID("LinkExamplesInner"), .layout(.{}), .rectangle(.{ .color = .{ 0, 0, 0, 0 } }) })({
cl.text("Examples", .text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }));
});
@ -514,7 +514,7 @@ fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
.rectangle(.{ .color = COLOR_LIGHT }),
.border(.{ .between_children = .{ .width = 2, .color = COLOR_RED } }),
})({
if (!mobileScreen) {
if (!mobile_screen) {
landingPageDesktop();
featureBlocksDesktop();
declarativeSyntaxPageDesktop();
@ -598,6 +598,7 @@ pub fn main() anyerror!void {
window_width = rl.getScreenWidth();
window_height = rl.getScreenHeight();
mobile_screen = (window_width - if (debug_mode_enabled) @as(i32, @intCast(cl.Clay__debugViewWidth)) else 0) < 750;
const mouse_pos = rl.getMousePosition();
cl.setPointerState(.{

View file

@ -1,6 +1,10 @@
const std = @import("std");
const builtin = @import("builtin");
pub extern var CLAY_LAYOUT_DEFAULT: LayoutConfig;
pub extern var Clay__debugViewHighlightColor: Color;
pub extern var Clay__debugViewWidth: u32;
/// for direct calls to the clay c library
pub const cdefs = struct {
// TODO: should use @extern instead but zls does not yet support it well and that is more important
@ -17,7 +21,7 @@ pub const cdefs = struct {
pub extern fn Clay_GetElementId(idString: String) ElementId;
pub extern fn Clay_GetElementIdWithIndex(idString: String, index: u32) ElementId;
pub extern fn Clay_Hovered() bool;
pub extern fn Clay_OnHover(onHoverFunction: ?*const fn (ElementId, PointerData, isize) callconv(.c) void, userData: isize) void;
pub extern fn Clay_OnHover(onHoverFunction: ?*const fn (ElementId, PointerData, *anyopaque) callconv(.c) void, userData: *anyopaque) void;
pub extern fn Clay_PointerOver(elementId: ElementId) bool;
pub extern fn Clay_GetScrollContainerData(id: ElementId) ScrollContainerData;
pub extern fn Clay_SetMeasureTextFunction(measureTextFunction: *const fn (*String, *TextElementConfig) callconv(.c) Dimensions) void;
@ -49,10 +53,6 @@ pub const cdefs = struct {
pub extern fn Clay__HashString(key: String, offset: u32, seed: u32) ElementId;
pub extern fn Clay__OpenTextElement(text: String, textConfig: *TextElementConfig) void;
pub extern fn Clay__GetParentElementId() u32;
pub extern var CLAY_LAYOUT_DEFAULT: LayoutConfig;
pub extern var Clay__debugViewHighlightColor: Color;
pub extern var Clay__debugViewWidth: u32;
};
pub const EnumBackingType = u8;
@ -463,10 +463,10 @@ pub const Config = union(ElementConfigType) {
return Config{ .custom_config = cdefs.Clay__StoreCustomElementConfig(config) };
}
pub fn ID(string: []const u8) Config {
return Config{ .id = hashString(makeClayString(string), 0, 0) };
return Config{ .id = cdefs.Clay__HashString(makeClayString(string), 0, 0) };
}
pub fn IDI(string: []const u8, index: u32) Config {
return Config{ .id = hashString(makeClayString(string), index, 0) };
return Config{ .id = cdefs.Clay__HashString(makeClayString(string), index, 0) };
}
pub fn layout(config: LayoutConfig) Config {
return Config{ .layout_config = cdefs.Clay__StoreLayoutConfig(config) };
@ -474,14 +474,28 @@ pub const Config = union(ElementConfigType) {
};
pub const minMemorySize = cdefs.Clay_MinMemorySize;
pub const setPointerState = cdefs.Clay_SetPointerState;
pub const initialize = cdefs.Clay_Initialize;
pub const getCurrentContext = cdefs.Clay_GetCurrentContext;
pub const setCurrentContext = cdefs.Clay_SetCurrentContext;
pub const updateScrollContainers = cdefs.Clay_UpdateScrollContainers;
pub const setLayoutDimensions = cdefs.Clay_SetLayoutDimensions;
pub const beginLayout = cdefs.Clay_BeginLayout;
pub const endLayout = cdefs.Clay_EndLayout;
pub const hovered = cdefs.Clay_Hovered;
pub const onHover = cdefs.Clay_OnHover;
pub const pointerOver = cdefs.Clay_PointerOver;
pub const getScrollContainerData = cdefs.Clay_GetScrollContainerData;
pub const setQueryScrollOffsetFunction = cdefs.Clay_SetQueryScrollOffsetFunction;
pub const renderCommandArrayGet = cdefs.Clay_RenderCommandArray_Get;
pub const setDebugModeEnabled = cdefs.Clay_SetDebugModeEnabled;
pub const hashString = cdefs.Clay__HashString;
pub const isDebugModeEnabled = cdefs.Clay_IsDebugModeEnabled;
pub const setCullingEnabled = cdefs.Clay_SetCullingEnabled;
pub const getMaxElementCount = cdefs.Clay_GetMaxElementCount;
pub const setMaxElementCount = cdefs.Clay_SetMaxElementCount;
pub const getMaxMeasureTextCacheWordCount = cdefs.Clay_GetMaxMeasureTextCacheWordCount;
pub const setMaxMeasureTextCacheWordCount = cdefs.Clay_SetMaxMeasureTextCacheWordCount;
pub const resetMeasureTextCache = cdefs.Clay_ResetMeasureTextCache;
pub fn createArenaWithCapacityAndMemory(buffer: []u8) Arena {
return cdefs.Clay_CreateArenaWithCapacityAndMemory(@intCast(buffer.len), buffer.ptr);
@ -504,18 +518,6 @@ pub inline fn UI(configs: []const Config) fn (void) void {
}.f;
}
pub fn endLayout() ClayArray(RenderCommand) {
return cdefs.Clay_EndLayout();
}
pub fn setPointerState(position: Vector2, pointer_down: bool) void {
cdefs.Clay_SetPointerState(position, pointer_down);
}
pub fn updateScrollContainers(is_pointer_active: bool, scroll_delta: Vector2, delta_time: f32) void {
cdefs.Clay_UpdateScrollContainers(is_pointer_active, scroll_delta, delta_time);
}
pub fn setMeasureTextFunction(comptime measureTextFunction: fn ([]const u8, *TextElementConfig) Dimensions) void {
cdefs.Clay_SetMeasureTextFunction(struct {
pub fn f(string: *String, config: *TextElementConfig) callconv(.C) Dimensions {
@ -536,11 +538,11 @@ pub fn text(string: []const u8, config: Config) void {
}
pub fn ID(string: []const u8) ElementId {
return hashString(makeClayString(string), 0, 0);
return cdefs.Clay__HashString(makeClayString(string), 0, 0);
}
pub fn IDI(string: []const u8, index: u32) ElementId {
return hashString(makeClayString(string), index, 0);
return cdefs.Clay__HashString(makeClayString(string), index, 0);
}
pub fn getElementId(string: []const u8) ElementId {