setup for zig's package manager, added default to some clay config types and changed namings for clay functions
This commit is contained in:
parent
c4ed8c9df2
commit
e89422deda
6 changed files with 79 additions and 85 deletions
|
@ -12,16 +12,16 @@ pub fn build(b: *B) void {
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
});
|
});
|
||||||
|
|
||||||
clay_lib.addIncludePath(b.path("./c_files/include/"));
|
clay_lib.addIncludePath(b.path("./vendor/include/"));
|
||||||
clay_lib.addCSourceFile(.{
|
clay_lib.addCSourceFile(.{
|
||||||
.file = b.path("./c_files/source/clay.c"),
|
.file = b.path("./vendor/source/clay.c"),
|
||||||
});
|
});
|
||||||
|
|
||||||
break :blk clay_lib;
|
break :blk clay_lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
const module = b.addModule("zig-package-template", .{
|
const module = b.addModule("zclay", .{
|
||||||
.root_source_file = b.path("src/root.zig"),
|
.root_source_file = b.path("src/root.zig"),
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
.{
|
.{
|
||||||
.name = "zig-package-template",
|
.name = "zclay",
|
||||||
.version = "0.0.0",
|
.version = "0.0.0",
|
||||||
.dependencies = .{},
|
.dependencies = .{},
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"build.zig",
|
"build.zig",
|
||||||
"build.zig.zon",
|
"build.zig.zon",
|
||||||
"src",
|
"src",
|
||||||
|
"vendor",
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
"README.md",
|
"README.md",
|
||||||
},
|
},
|
||||||
|
|
154
src/root.zig
154
src/root.zig
|
@ -30,15 +30,15 @@ pub const BoundingBox = extern struct {
|
||||||
pub const Color = [4]f32;
|
pub const Color = [4]f32;
|
||||||
|
|
||||||
pub const CornerRadius = extern struct {
|
pub const CornerRadius = extern struct {
|
||||||
topLeft: f32,
|
topLeft: f32 = 0,
|
||||||
topRight: f32,
|
topRight: f32 = 0,
|
||||||
bottomLeft: f32,
|
bottomLeft: f32 = 0,
|
||||||
bottomRight: f32,
|
bottomRight: f32 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const BorderData = extern struct {
|
pub const BorderData = extern struct {
|
||||||
width: u32,
|
width: u32 = 0,
|
||||||
color: Color,
|
color: Color = .{ 255, 255, 255, 255 },
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ElementId = extern struct {
|
pub const ElementId = extern struct {
|
||||||
|
@ -62,8 +62,8 @@ pub const RenderCommandType = enum(EnumBackingType) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const RectangleElementConfig = extern struct {
|
pub const RectangleElementConfig = extern struct {
|
||||||
color: Color,
|
color: Color = .{ 255, 255, 255, 255 },
|
||||||
cornerRadius: CornerRadius,
|
cornerRadius: CornerRadius = .{},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const TextWrapMode = enum(EnumBackingType) {
|
pub const TextWrapMode = enum(EnumBackingType) {
|
||||||
|
@ -180,8 +180,8 @@ pub const Sizing = extern struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Padding = extern struct {
|
pub const Padding = extern struct {
|
||||||
x: u16,
|
x: u16 = 0,
|
||||||
y: u16,
|
y: u16 = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LayoutDirection = enum(EnumBackingType) {
|
pub const LayoutDirection = enum(EnumBackingType) {
|
||||||
|
@ -202,16 +202,19 @@ pub const LayoutAlignmentY = enum(EnumBackingType) {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const ChildAlignment = extern struct {
|
pub const ChildAlignment = extern struct {
|
||||||
x: LayoutAlignmentX,
|
x: LayoutAlignmentX = .CENTER,
|
||||||
y: LayoutAlignmentY,
|
y: LayoutAlignmentY = .CENTER,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LayoutConfig = extern struct {
|
pub const LayoutConfig = extern struct {
|
||||||
sizing: Sizing,
|
sizing: Sizing = .{
|
||||||
padding: Padding,
|
.height = .{ .constraints = .{ .sizePercent = 100 }, .type = .GROW },
|
||||||
childGap: u16,
|
.width = .{ .constraints = .{ .sizePercent = 100 }, .type = .GROW },
|
||||||
layoutDirection: LayoutDirection,
|
},
|
||||||
childAlignment: ChildAlignment,
|
padding: Padding = .{},
|
||||||
|
childGap: u16 = 0,
|
||||||
|
layoutDirection: LayoutDirection = .TOP_TO_BOTTOM,
|
||||||
|
childAlignment: ChildAlignment = .{},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn ClayArray(comptime T: type) type {
|
pub fn ClayArray(comptime T: type) type {
|
||||||
|
@ -263,41 +266,41 @@ const extern_elements = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Public function declarations
|
// Public function declarations
|
||||||
pub const MinMemorySize = extern_elements.Clay_MinMemorySize;
|
pub const minMemorySize = extern_elements.Clay_MinMemorySize;
|
||||||
pub const CreateArenaWithCapacityAndMemory = extern_elements.Clay_CreateArenaWithCapacityAndMemory;
|
pub const createArenaWithCapacityAndMemory = extern_elements.Clay_CreateArenaWithCapacityAndMemory;
|
||||||
pub const SetPointerState = extern_elements.Clay_SetPointerState;
|
pub const setPointerState = extern_elements.Clay_SetPointerState;
|
||||||
pub const Initialize = extern_elements.Clay_Initialize;
|
pub const initialize = extern_elements.Clay_Initialize;
|
||||||
pub const UpdateScrollContainers = extern_elements.Clay_UpdateScrollContainers;
|
pub const updateScrollContainers = extern_elements.Clay_UpdateScrollContainers;
|
||||||
pub const SetLayoutDimensions = extern_elements.Clay_SetLayoutDimensions;
|
pub const setLayoutDimensions = extern_elements.Clay_SetLayoutDimensions;
|
||||||
pub const BeginLayout = extern_elements.Clay_BeginLayout;
|
pub const beginLayout = extern_elements.Clay_BeginLayout;
|
||||||
pub const EndLayout = extern_elements.Clay_EndLayout;
|
pub const endLayout = extern_elements.Clay_EndLayout;
|
||||||
pub const PointerOver = extern_elements.Clay_PointerOver;
|
pub const pointerOver = extern_elements.Clay_PointerOver;
|
||||||
pub const GetScrollContainerData = extern_elements.Clay_GetScrollContainerData;
|
pub const getScrollContainerData = extern_elements.Clay_GetScrollContainerData;
|
||||||
pub const SetMeasureTextFunction = extern_elements.Clay_SetMeasureTextFunction;
|
pub const setMeasureTextFunction = extern_elements.Clay_SetMeasureTextFunction;
|
||||||
pub const RenderCommandArray_Get = extern_elements.Clay_RenderCommandArray_Get;
|
pub const renderCommandArray_Get = extern_elements.Clay_RenderCommandArray_Get;
|
||||||
pub const SetDebugModeEnabled = extern_elements.Clay_SetDebugModeEnabled;
|
pub const setDebugModeEnabled = extern_elements.Clay_SetDebugModeEnabled;
|
||||||
|
|
||||||
// Private function declarations
|
// Private function declarations
|
||||||
pub const OpenContainerElement = extern_elements.Clay__OpenContainerElement;
|
pub const rontainer = extern_elements.Clay__OpenContainerElement;
|
||||||
pub const OpenRectangleElement = extern_elements.Clay__OpenRectangleElement;
|
pub const rectangle = extern_elements.Clay__OpenRectangleElement;
|
||||||
pub const OpenTextElement = extern_elements.Clay__OpenTextElement;
|
pub const text = extern_elements.Clay__OpenTextElement;
|
||||||
pub const OpenImageElement = extern_elements.Clay__OpenImageElement;
|
pub const image = extern_elements.Clay__OpenImageElement;
|
||||||
pub const OpenScrollElement = extern_elements.Clay__OpenScrollElement;
|
pub const scroll = extern_elements.Clay__OpenScrollElement;
|
||||||
pub const OpenFloatingElement = extern_elements.Clay__OpenFloatingElement;
|
pub const floating = extern_elements.Clay__OpenFloatingElement;
|
||||||
pub const OpenBorderElement = extern_elements.Clay__OpenBorderElement;
|
pub const border = extern_elements.Clay__OpenBorderElement;
|
||||||
pub const OpenCustomElement = extern_elements.Clay__OpenCustomElement;
|
pub const sustomElement = extern_elements.Clay__OpenCustomElement;
|
||||||
pub const CloseElementWithChildren = extern_elements.Clay__CloseElementWithChildren;
|
pub const closeParent = extern_elements.Clay__CloseElementWithChildren;
|
||||||
pub const CloseScrollElement = extern_elements.Clay__CloseScrollElement;
|
pub const closeScroll = extern_elements.Clay__CloseScrollElement;
|
||||||
pub const CloseFloatingElement = extern_elements.Clay__CloseFloatingElement;
|
pub const sloseFloating = extern_elements.Clay__CloseFloatingElement;
|
||||||
pub const StoreLayoutConfig = extern_elements.Clay__StoreLayoutConfig;
|
pub const layout = extern_elements.Clay__StoreLayoutConfig;
|
||||||
pub const StoreRectangleElementConfig = extern_elements.Clay__StoreRectangleElementConfig;
|
pub const rectangleConfig = extern_elements.Clay__StoreRectangleElementConfig;
|
||||||
pub const StoreTextElementConfig = extern_elements.Clay__StoreTextElementConfig;
|
pub const textConfig = extern_elements.Clay__StoreTextElementConfig;
|
||||||
pub const StoreImageElementConfig = extern_elements.Clay__StoreImageElementConfig;
|
pub const imageConfig = extern_elements.Clay__StoreImageElementConfig;
|
||||||
pub const StoreFloatingElementConfig = extern_elements.Clay__StoreFloatingElementConfig;
|
pub const floatingConfig = extern_elements.Clay__StoreFloatingElementConfig;
|
||||||
pub const StoreCustomElementConfig = extern_elements.Clay__StoreCustomElementConfig;
|
pub const customConfig = extern_elements.Clay__StoreCustomElementConfig;
|
||||||
pub const StoreScrollElementConfig = extern_elements.Clay__StoreScrollElementConfig;
|
pub const scrollConfig = extern_elements.Clay__StoreScrollElementConfig;
|
||||||
pub const StoreBorderElementConfig = extern_elements.Clay__StoreBorderElementConfig;
|
pub const borderConfig = extern_elements.Clay__StoreBorderElementConfig;
|
||||||
pub const HashString = extern_elements.Clay__HashString;
|
pub const hashString = extern_elements.Clay__HashString;
|
||||||
|
|
||||||
fn measureText(str: *String, conf: *TextElementConfig) callconv(.C) Dimensions {
|
fn measureText(str: *String, conf: *TextElementConfig) callconv(.C) Dimensions {
|
||||||
_ = str;
|
_ = str;
|
||||||
|
@ -309,44 +312,33 @@ fn measureText(str: *String, conf: *TextElementConfig) callconv(.C) Dimensions {
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
test {
|
||||||
std.debug.print("{}", .{MinMemorySize()});
|
|
||||||
const allocator = std.testing.allocator;
|
const allocator = std.testing.allocator;
|
||||||
|
|
||||||
const minMemorySize: u32 = MinMemorySize();
|
const min_memory_size: u32 = minMemorySize();
|
||||||
const memory = try allocator.alloc(u8, minMemorySize);
|
const memory = try allocator.alloc(u8, min_memory_size);
|
||||||
defer allocator.free(memory);
|
defer allocator.free(memory);
|
||||||
const arena: Arena = CreateArenaWithCapacityAndMemory(minMemorySize, @ptrCast(memory));
|
const arena: Arena = createArenaWithCapacityAndMemory(min_memory_size, @ptrCast(memory));
|
||||||
SetMeasureTextFunction(measureText);
|
setMeasureTextFunction(measureText);
|
||||||
Initialize(arena, .{ .width = 1000, .height = 1000 });
|
initialize(arena, .{ .width = 1000, .height = 1000 });
|
||||||
|
|
||||||
BeginLayout();
|
beginLayout();
|
||||||
|
|
||||||
{
|
{
|
||||||
var layout_config = LayoutConfig{
|
rectangle(
|
||||||
.sizing = .{
|
ID("name"),
|
||||||
.height = .{ .constraints = .{ .sizePercent = 10 }, .type = .GROW },
|
layout(.{}),
|
||||||
.width = .{ .constraints = .{ .sizePercent = 10 }, .type = .GROW },
|
rectangleConfig(.{}),
|
||||||
},
|
|
||||||
.padding = .{ .x = 5, .y = 5 },
|
|
||||||
.childGap = 10,
|
|
||||||
.layoutDirection = .LEFT_TO_RIGHT,
|
|
||||||
.childAlignment = .{ .x = .LEFT, .y = .TOP },
|
|
||||||
};
|
|
||||||
|
|
||||||
OpenRectangleElement(
|
|
||||||
HashString(.{
|
|
||||||
.chars = @ptrCast(@constCast("string")),
|
|
||||||
.length = 6,
|
|
||||||
}, 0),
|
|
||||||
&layout_config,
|
|
||||||
@constCast(&RectangleElementConfig{
|
|
||||||
.color = .{ 200, 200, 200, 255 },
|
|
||||||
.cornerRadius = .{ .bottomLeft = 1, .topLeft = 1, .topRight = 1, .bottomRight = 1 },
|
|
||||||
}),
|
|
||||||
);
|
);
|
||||||
defer CloseElementWithChildren();
|
defer closeParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
const layout = EndLayout();
|
const _layout = endLayout();
|
||||||
std.debug.print("{any}", .{layout.internalArray[0..1]});
|
std.debug.print("{any}", .{_layout.internalArray[0..1]});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ID(name: []const u8) ElementId {
|
||||||
|
return hashString(.{
|
||||||
|
.chars = @ptrCast(@constCast(name)),
|
||||||
|
.length = @intCast(name.len),
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
1
vendor/include/README.md
vendored
Normal file
1
vendor/include/README.md
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
the clay.h in this folder has been very slightly modified for compatibility with zig cc
|
0
c_files/source/clay.c → vendor/source/clay.c
vendored
0
c_files/source/clay.c → vendor/source/clay.c
vendored
Loading…
Add table
Add a link
Reference in a new issue