second pass
This commit is contained in:
parent
f6a86434e2
commit
3cf1e2c74e
13 changed files with 407 additions and 884 deletions
|
@ -1,86 +0,0 @@
|
|||
const std = @import("std");
|
||||
const B = std.Build;
|
||||
|
||||
pub fn build(b: *B) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{});
|
||||
|
||||
{
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "debug",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
addDependencies(exe, b, target, optimize);
|
||||
|
||||
b.installArtifact(exe);
|
||||
const run_cmd = b.addRunArtifact(exe);
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
||||
if (b.args) |args| {
|
||||
run_cmd.addArgs(args);
|
||||
}
|
||||
|
||||
const run_step = b.step("run", "Run the app");
|
||||
run_step.dependOn(&run_cmd.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe_unit_tests = b.addTest(.{
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
addDependencies(exe_unit_tests, b, target, optimize);
|
||||
|
||||
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
|
||||
const test_step = b.step("test", "Run unit tests");
|
||||
test_step.dependOn(&run_exe_unit_tests.step);
|
||||
}
|
||||
|
||||
{
|
||||
const exe_check = b.addExecutable(.{
|
||||
.name = "check",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
addDependencies(exe_check, b, target, optimize);
|
||||
|
||||
const tests_check = b.addTest(.{
|
||||
.name = "check",
|
||||
.root_source_file = b.path("src/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
addDependencies(tests_check, b, target, optimize);
|
||||
|
||||
const check = b.step("check", "Check if exe and tests compile");
|
||||
check.dependOn(&exe_check.step);
|
||||
check.dependOn(&tests_check.step);
|
||||
}
|
||||
}
|
||||
|
||||
fn addDependencies(
|
||||
compile_step: *B.Step.Compile,
|
||||
b: *B,
|
||||
target: B.ResolvedTarget,
|
||||
optimize: std.builtin.OptimizeMode,
|
||||
) void {
|
||||
const zclay_dep = b.dependency("zclay", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const zclay = zclay_dep.module("zclay");
|
||||
compile_step.root_module.addImport("zclay", zclay);
|
||||
|
||||
const raylib_dep = b.dependency("raylib-zig", .{
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
const raylib = raylib_dep.module("raylib");
|
||||
compile_step.root_module.addImport("raylib", raylib);
|
||||
const raylib_artifact = raylib_dep.artifact("raylib");
|
||||
compile_step.linkLibrary(raylib_artifact);
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
.{
|
||||
.name = "zig-exe-template",
|
||||
.version = "0.0.0",
|
||||
.dependencies = .{
|
||||
.zclay = .{
|
||||
.path = "../../",
|
||||
},
|
||||
.@"raylib-zig" = .{
|
||||
.url = "https://github.com/Not-Nik/raylib-zig/archive/35332edacf2e03236220f12a8dd3410b1c39d9eb.tar.gz",
|
||||
.hash = "1220c34fe472645e173a7168eb513ca8343af3c3f61b618daedda30ec3932b002637",
|
||||
},
|
||||
},
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
"LICENSE",
|
||||
"README.md",
|
||||
},
|
||||
}
|
|
@ -1,154 +0,0 @@
|
|||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
const cl = @import("zclay");
|
||||
const renderer = @import("raylib_render_clay.zig");
|
||||
|
||||
const FONT_ID_BODY_30 = 6;
|
||||
|
||||
const COLOR_LIGHT = cl.Color{ 244, 235, 230, 255 };
|
||||
const COLOR_LIGHT_HOVER = cl.Color{ 224, 215, 210, 255 };
|
||||
const COLOR_BUTTON_HOVER = cl.Color{ 238, 227, 225, 255 };
|
||||
const COLOR_BROWN = cl.Color{ 61, 26, 5, 255 };
|
||||
const COLOR_RED = cl.Color{ 168, 66, 28, 255 };
|
||||
const COLOR_RED_HOVER = cl.Color{ 148, 46, 8, 255 };
|
||||
const COLOR_ORANGE = cl.Color{ 225, 138, 50, 255 };
|
||||
const COLOR_BLUE = cl.Color{ 111, 173, 162, 255 };
|
||||
const COLOR_TEAL = cl.Color{ 111, 173, 162, 255 };
|
||||
const COLOR_BLUE_DARK = cl.Color{ 2, 32, 82, 255 };
|
||||
const COLOR_ZIG_LOGO = cl.Color{ 247, 164, 29, 255 };
|
||||
|
||||
// Colors for top stripe
|
||||
const COLORS_TOP_BORDER = [_]cl.Color{
|
||||
.{ 240, 213, 137, 255 },
|
||||
.{ 236, 189, 80, 255 },
|
||||
.{ 225, 138, 50, 255 },
|
||||
.{ 223, 110, 44, 255 },
|
||||
.{ 168, 66, 28, 255 },
|
||||
};
|
||||
|
||||
const border_data = cl.BorderData{ .width = 2, .color = COLOR_RED };
|
||||
|
||||
var window_height: isize = 0;
|
||||
var window_width: isize = 0;
|
||||
|
||||
fn LandingPageBlob_(index: u32, font_size: u16, font_id: u16, color: cl.Color, max_width: f32, text: []const u8) void {
|
||||
// std.debug.print("\nBLOB START\n", .{});
|
||||
if (cl.OPEN(&.{
|
||||
.IDI("HeroBlob", index),
|
||||
.layout(.{ .sizing = .{ .w = .growMinMax(.{ .max = max_width }) }, .padding = .all(16), .child_gap = 16, .child_alignment = .{ .y = .CENTER } }),
|
||||
.border(.outside(color, 2, 0)),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
cl.text(text, cl.Config.text(.{ .font_size = font_size, .font_id = font_id, .color = color }));
|
||||
}
|
||||
// std.debug.print("BLOB END\n\n", .{});
|
||||
}
|
||||
|
||||
fn LandingPageBlob(index: u32, font_size: u16, font_id: u16, color: cl.Color, max_width: f32, text: []const u8) void {
|
||||
// std.debug.print("\nBLOB START\n", .{});
|
||||
cl.UI(&.{
|
||||
.IDI("HeroBlob", index),
|
||||
.layout(.{ .sizing = .{ .w = .growMinMax(.{ .max = max_width }) }, .padding = .all(16), .child_gap = 16, .child_alignment = .{ .y = .CENTER } }),
|
||||
.border(.outside(color, 2, 0)),
|
||||
})({
|
||||
cl.text(text, cl.Config.text(.{ .font_size = font_size, .font_id = font_id, .color = color }));
|
||||
});
|
||||
// std.debug.print("BLOB END\n\n", .{});
|
||||
}
|
||||
|
||||
fn createLayout() cl.ClayArray(cl.RenderCommand) {
|
||||
cl.beginLayout();
|
||||
// cl.UI(&.{
|
||||
// .ID("ScrollContainerBackgroundRectangle"),
|
||||
// .scroll(.{ .vertical = true }),
|
||||
// .layout(.{ .sizing = .grow, .direction = .TOP_TO_BOTTOM, .child_gap = 10 }),
|
||||
// .rectangle(.{ .color = COLOR_LIGHT }),
|
||||
// })({
|
||||
// LandingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 510, "The official Clay website recreated with zclay: clay-zig-bindings");
|
||||
// @call(.always_inline, LandingPageBlob, .{ 2, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 510, "The official Clay website recreated with zclay: clay-zig-bindings" });
|
||||
// });
|
||||
|
||||
if (cl.OPEN(&.{
|
||||
.ID("ScrollContainerBackgroundRectangle"),
|
||||
.scroll(.{ .vertical = true }),
|
||||
.layout(.{ .sizing = .grow, .direction = .TOP_TO_BOTTOM, .child_gap = 10 }),
|
||||
.rectangle(.{ .color = COLOR_LIGHT }),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
// LandingPageBlob_(1, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 510, "The official Clay website recreated with zclay: clay-zig-bindings");
|
||||
// std.debug.print("\n==\n\n", .{});
|
||||
@call(.always_inline, LandingPageBlob_, .{ 2, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 510, "The official Clay website recreated with zclay: clay-zig-bindings" });
|
||||
}
|
||||
|
||||
return cl.endLayout();
|
||||
}
|
||||
|
||||
fn loadFont(file_data: ?[]const u8, font_id: u16, font_size: i32) void {
|
||||
renderer.raylib_fonts[font_id] = rl.loadFontFromMemory(".ttf", file_data, font_size * 2, null);
|
||||
rl.setTextureFilter(renderer.raylib_fonts[font_id].?.texture, .bilinear);
|
||||
}
|
||||
|
||||
fn loadImage(comptime path: [:0]const u8) rl.Texture2D {
|
||||
const texture = rl.loadTextureFromImage(rl.loadImageFromMemory(@ptrCast(std.fs.path.extension(path)), @embedFile(path)));
|
||||
rl.setTextureFilter(texture, .bilinear);
|
||||
return texture;
|
||||
}
|
||||
|
||||
pub fn main() anyerror!void {
|
||||
const allocator = std.heap.page_allocator;
|
||||
|
||||
// init clay
|
||||
const min_memory_size: u32 = cl.minMemorySize();
|
||||
const memory = try allocator.alloc(u8, min_memory_size);
|
||||
defer allocator.free(memory);
|
||||
const arena: cl.Arena = cl.createArenaWithCapacityAndMemory(min_memory_size, @ptrCast(memory));
|
||||
cl.initialize(arena, .{ .h = 1000, .w = 1000 });
|
||||
cl.setMeasureTextFunction(renderer.measureText);
|
||||
|
||||
// init raylib
|
||||
rl.setConfigFlags(.{
|
||||
.msaa_4x_hint = true,
|
||||
.window_resizable = true,
|
||||
});
|
||||
rl.initWindow(1000, 1000, "Raylib zig Example");
|
||||
rl.setWindowMinSize(300, 100);
|
||||
rl.setTargetFPS(60);
|
||||
|
||||
// load assets
|
||||
loadFont(@embedFile("resources/Quicksand-Semibold.ttf"), FONT_ID_BODY_30, 30);
|
||||
|
||||
var debug_mode_enabled = false;
|
||||
while (!rl.windowShouldClose()) {
|
||||
if (rl.isKeyPressed(.d)) {
|
||||
debug_mode_enabled = !debug_mode_enabled;
|
||||
cl.setDebugModeEnabled(debug_mode_enabled);
|
||||
}
|
||||
|
||||
window_width = rl.getScreenWidth();
|
||||
window_height = rl.getScreenHeight();
|
||||
|
||||
const mouse_pos = rl.getMousePosition();
|
||||
cl.setPointerState(.{
|
||||
.x = mouse_pos.x,
|
||||
.y = mouse_pos.y,
|
||||
}, rl.isMouseButtonDown(.left));
|
||||
|
||||
const scroll_delta = rl.getMouseWheelMoveV().multiply(.{ .x = 6, .y = 6 });
|
||||
cl.updateScrollContainers(
|
||||
false,
|
||||
.{ .x = scroll_delta.x, .y = scroll_delta.y },
|
||||
rl.getFrameTime(),
|
||||
);
|
||||
|
||||
cl.setLayoutDimensions(.{
|
||||
.w = @floatFromInt(window_width),
|
||||
.h = @floatFromInt(window_height),
|
||||
});
|
||||
var render_commands = createLayout();
|
||||
|
||||
rl.beginDrawing();
|
||||
renderer.clayRaylibRender(&render_commands, allocator);
|
||||
rl.endDrawing();
|
||||
// @panic("");
|
||||
}
|
||||
}
|
|
@ -1,234 +0,0 @@
|
|||
const std = @import("std");
|
||||
const rl = @import("raylib");
|
||||
const cl = @import("zclay");
|
||||
const math = std.math;
|
||||
|
||||
pub fn clayColorToRaylibColor(color: cl.Color) rl.Color {
|
||||
return rl.Color{
|
||||
.r = @intFromFloat(color[0]),
|
||||
.g = @intFromFloat(color[1]),
|
||||
.b = @intFromFloat(color[2]),
|
||||
.a = @intFromFloat(color[3]),
|
||||
};
|
||||
}
|
||||
|
||||
pub var raylib_fonts: [10]?rl.Font = .{null} ** 10;
|
||||
|
||||
pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), allocator: std.mem.Allocator) void {
|
||||
var i: usize = 0;
|
||||
while (i < render_commands.length) : (i += 1) {
|
||||
const render_command = cl.renderCommandArrayGet(render_commands, @intCast(i));
|
||||
const bounding_box = render_command.bounding_box;
|
||||
switch (render_command.command_type) {
|
||||
.None => {},
|
||||
.Text => {
|
||||
const text = render_command.text.chars[0..@intCast(render_command.text.length)];
|
||||
const cloned = allocator.dupeZ(c_char, text) catch unreachable;
|
||||
defer allocator.free(cloned);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_element_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_element_config.line_height);
|
||||
rl.drawTextEx(
|
||||
fontToUse,
|
||||
@ptrCast(@alignCast(cloned.ptr)),
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
@floatFromInt(render_command.config.text_element_config.font_size),
|
||||
@floatFromInt(render_command.config.text_element_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_element_config.color),
|
||||
);
|
||||
},
|
||||
.Image => {
|
||||
const image_texture: *const rl.Texture2D = @ptrCast(
|
||||
@alignCast(render_command.config.image_element_config.image_data),
|
||||
);
|
||||
rl.drawTextureEx(
|
||||
image_texture.*,
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
0,
|
||||
bounding_box.width / @as(f32, @floatFromInt(image_texture.width)),
|
||||
rl.Color.white,
|
||||
);
|
||||
},
|
||||
.ScissorStart => {
|
||||
rl.beginScissorMode(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
@intFromFloat(math.round(bounding_box.width)),
|
||||
@intFromFloat(math.round(bounding_box.height)),
|
||||
);
|
||||
},
|
||||
.ScissorEnd => rl.endScissorMode(),
|
||||
.Rectangle => {
|
||||
const config = render_command.config.rectangle_element_config;
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
const radius: f32 = (config.corner_radius.top_left * 2) / @min(bounding_box.width, bounding_box.height);
|
||||
rl.drawRectangleRounded(
|
||||
rl.Rectangle{
|
||||
.x = bounding_box.x,
|
||||
.y = bounding_box.y,
|
||||
.width = bounding_box.width,
|
||||
.height = bounding_box.height,
|
||||
},
|
||||
radius,
|
||||
8,
|
||||
clayColorToRaylibColor(config.color),
|
||||
);
|
||||
} else {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(bounding_box.x),
|
||||
@intFromFloat(bounding_box.y),
|
||||
@intFromFloat(bounding_box.width),
|
||||
@intFromFloat(bounding_box.height),
|
||||
clayColorToRaylibColor(config.color),
|
||||
);
|
||||
}
|
||||
},
|
||||
.Border => {
|
||||
const config = render_command.config.border_element_config;
|
||||
if (config.left.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y + config.corner_radius.top_left)),
|
||||
@intCast(config.left.width),
|
||||
@intFromFloat(math.round(bounding_box.height - config.corner_radius.top_left - config.corner_radius.bottom_left)),
|
||||
clayColorToRaylibColor(config.left.color),
|
||||
);
|
||||
}
|
||||
if (config.right.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x + bounding_box.width - @as(f32, @floatFromInt(config.right.width)))),
|
||||
@intFromFloat(math.round(bounding_box.y + config.corner_radius.top_right)),
|
||||
@intCast(config.right.width),
|
||||
@intFromFloat(math.round(bounding_box.height - config.corner_radius.top_right - config.corner_radius.bottom_right)),
|
||||
clayColorToRaylibColor(config.right.color),
|
||||
);
|
||||
}
|
||||
if (config.top.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x + config.corner_radius.top_left)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
@intFromFloat(math.round(bounding_box.width - config.corner_radius.top_left - config.corner_radius.top_right)),
|
||||
@intCast(config.top.width),
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.bottom.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x + config.corner_radius.bottom_left)),
|
||||
@intFromFloat(math.round(bounding_box.y + bounding_box.height - @as(f32, @floatFromInt(config.bottom.width)))),
|
||||
@intFromFloat(math.round(bounding_box.width - config.corner_radius.bottom_left - config.corner_radius.bottom_right)),
|
||||
@intCast(config.bottom.width),
|
||||
clayColorToRaylibColor(config.bottom.color),
|
||||
);
|
||||
}
|
||||
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(bounding_box.x + config.corner_radius.top_left),
|
||||
.y = math.round(bounding_box.y + config.corner_radius.top_left),
|
||||
},
|
||||
math.round(config.corner_radius.top_left - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.top_left,
|
||||
180,
|
||||
270,
|
||||
10,
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.corner_radius.top_right > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(bounding_box.x + bounding_box.width - config.corner_radius.top_right),
|
||||
.y = math.round(bounding_box.y + config.corner_radius.top_right),
|
||||
},
|
||||
math.round(config.corner_radius.top_right - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.top_right,
|
||||
270,
|
||||
360,
|
||||
10,
|
||||
clayColorToRaylibColor(config.top.color),
|
||||
);
|
||||
}
|
||||
if (config.corner_radius.bottom_left > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(bounding_box.x + config.corner_radius.bottom_left),
|
||||
.y = math.round(bounding_box.y + bounding_box.height - config.corner_radius.bottom_left),
|
||||
},
|
||||
math.round(config.corner_radius.bottom_left - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.bottom_left,
|
||||
90,
|
||||
180,
|
||||
10,
|
||||
clayColorToRaylibColor(config.bottom.color),
|
||||
);
|
||||
}
|
||||
if (config.corner_radius.bottom_right > 0) {
|
||||
rl.drawRing(
|
||||
rl.Vector2{
|
||||
.x = math.round(bounding_box.x + bounding_box.width - config.corner_radius.bottom_right),
|
||||
.y = math.round(bounding_box.y + bounding_box.height - config.corner_radius.bottom_right),
|
||||
},
|
||||
math.round(config.corner_radius.bottom_right - @as(f32, @floatFromInt(config.top.width))),
|
||||
config.corner_radius.bottom_right,
|
||||
0.1,
|
||||
90,
|
||||
10,
|
||||
clayColorToRaylibColor(config.bottom.color),
|
||||
);
|
||||
}
|
||||
},
|
||||
.Custom => {
|
||||
// Implement custom element rendering here
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn measureText(clay_text: []const u8, config: *cl.TextElementConfig) cl.Dimensions {
|
||||
const font = raylib_fonts[config.font_id].?;
|
||||
const text: []const u8 = clay_text;
|
||||
const font_size: f32 = @floatFromInt(config.font_size);
|
||||
const letter_spacing: f32 = @floatFromInt(config.letter_spacing);
|
||||
const line_height = config.line_height;
|
||||
|
||||
var temp_byte_counter: usize = 0;
|
||||
var byte_counter: usize = 0;
|
||||
var text_width: f32 = 0.0;
|
||||
var temp_text_width: f32 = 0.0;
|
||||
var text_height: f32 = font_size;
|
||||
const scale_factor: f32 = font_size / @as(f32, @floatFromInt(font.baseSize));
|
||||
|
||||
var utf8 = std.unicode.Utf8View.initUnchecked(text).iterator();
|
||||
|
||||
while (utf8.nextCodepoint()) |codepoint| {
|
||||
byte_counter += std.unicode.utf8CodepointSequenceLength(codepoint) catch 1;
|
||||
const index: usize = @intCast(
|
||||
rl.getGlyphIndex(font, @as(i32, @intCast(codepoint))),
|
||||
);
|
||||
|
||||
if (codepoint != '\n') {
|
||||
if (font.glyphs[index].advanceX != 0) {
|
||||
text_width += @floatFromInt(font.glyphs[index].advanceX);
|
||||
} else {
|
||||
text_width += font.recs[index].width + @as(f32, @floatFromInt(font.glyphs[index].offsetX));
|
||||
}
|
||||
} else {
|
||||
if (temp_text_width < text_width) temp_text_width = text_width;
|
||||
byte_counter = 0;
|
||||
text_width = 0;
|
||||
text_height += font_size + @as(f32, @floatFromInt(line_height));
|
||||
}
|
||||
|
||||
if (temp_byte_counter < byte_counter) temp_byte_counter = byte_counter;
|
||||
}
|
||||
|
||||
if (temp_text_width < text_width) temp_text_width = text_width;
|
||||
|
||||
std.debug.print("\"{s}\" => .w = {d}\n", .{ clay_text, temp_text_width * scale_factor + (@as(f32, @floatFromInt(temp_byte_counter)) - 1) * letter_spacing });
|
||||
|
||||
return cl.Dimensions{
|
||||
.h = text_height,
|
||||
.w = temp_text_width * scale_factor + (@as(f32, @floatFromInt(temp_byte_counter)) - 1) * letter_spacing,
|
||||
};
|
||||
}
|
Binary file not shown.
|
@ -54,7 +54,7 @@ const border_data = cl.BorderData{ .width = 2, .color = COLOR_RED };
|
|||
var window_height: isize = 0;
|
||||
var window_width: isize = 0;
|
||||
|
||||
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 {
|
||||
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(&.{
|
||||
.IDI("HeroBlob", index),
|
||||
.layout(.{ .sizing = .{ .w = .growMinMax(.{ .max = max_width }) }, .padding = .all(16), .child_gap = 16, .child_alignment = .{ .y = .CENTER } }),
|
||||
|
@ -65,7 +65,7 @@ fn LandingPageBlob(index: u32, font_size: u16, font_id: u16, color: cl.Color, im
|
|||
.layout(.{ .sizing = .{ .w = .fixed(image_size) } }),
|
||||
.image(.{ .image_data = image, .source_dimensions = .{ .w = 128, .h = 128 } }),
|
||||
})({});
|
||||
cl.text(text, cl.Config.text(.{ .font_size = font_size, .font_id = font_id, .color = color }));
|
||||
cl.text(text, .text(.{ .font_size = font_size, .font_id = font_id, .color = color }));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ fn landingPageDesktop() void {
|
|||
}),
|
||||
.border(.{ .left = border_data, .right = border_data }),
|
||||
})({
|
||||
LandingPageBlob(0, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 64, 510, "The official Clay website recreated with zclay: clay-zig-bindings", &zig_logo_image6);
|
||||
landingPageBlob(0, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 64, 510, "The official Clay website recreated with zclay: clay-zig-bindings", &zig_logo_image6);
|
||||
|
||||
cl.UI(&.{
|
||||
.ID("ClayPresentation"),
|
||||
|
@ -106,12 +106,12 @@ fn landingPageDesktop() void {
|
|||
})({
|
||||
cl.text(
|
||||
"Clay is a flex-box style UI auto layout library in C, with declarative syntax and microsecond performance.",
|
||||
cl.Config.text(.{ .font_size = 56, .font_id = FONT_ID_TITLE_56, .color = COLOR_RED }),
|
||||
.text(.{ .font_size = 56, .font_id = FONT_ID_TITLE_56, .color = COLOR_RED }),
|
||||
);
|
||||
cl.UI(&.{ .ID("ClayPresentation_Spacer"), .layout(.{ .sizing = .{ .w = .grow, .h = .fixed(32) } }) })({});
|
||||
cl.text(
|
||||
"Clay is laying out this webpage right now!",
|
||||
cl.Config.text(.{ .font_size = 36, .font_id = FONT_ID_BODY_36, .color = COLOR_ORANGE }),
|
||||
.text(.{ .font_size = 36, .font_id = FONT_ID_BODY_36, .color = COLOR_ORANGE }),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -119,11 +119,11 @@ fn landingPageDesktop() void {
|
|||
.ID("HeroImageOuter"),
|
||||
.layout(.{ .sizing = .{ .w = .percent(0.45) }, .direction = .TOP_TO_BOTTOM, .child_alignment = .{ .x = .CENTER }, .child_gap = 16 }),
|
||||
})({
|
||||
LandingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_5, 32, 480, "High performance", &checkImage5);
|
||||
LandingPageBlob(2, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_4, 32, 480, "Flexbox-style responsive layout", &checkImage4);
|
||||
LandingPageBlob(3, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_3, 32, 480, "Declarative syntax", &checkImage3);
|
||||
LandingPageBlob(4, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_2, 32, 480, "Single .h file for C/C++", &checkImage2);
|
||||
LandingPageBlob(5, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_1, 32, 480, "Compile to 15kb .wasm", &checkImage1);
|
||||
landingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_5, 32, 480, "High performance", &checkImage5);
|
||||
landingPageBlob(2, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_4, 32, 480, "Flexbox-style responsive layout", &checkImage4);
|
||||
landingPageBlob(3, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_3, 32, 480, "Declarative syntax", &checkImage3);
|
||||
landingPageBlob(4, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_2, 32, 480, "Single .h file for C/C++", &checkImage2);
|
||||
landingPageBlob(5, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_1, 32, 480, "Compile to 15kb .wasm", &checkImage1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -141,19 +141,19 @@ fn landingPageMobile() void {
|
|||
.child_gap = 16,
|
||||
}),
|
||||
})({
|
||||
LandingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 64, 510, "The official Clay website recreated with zclay: clay-zig-bindings", &zig_logo_image6);
|
||||
landingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_ZIG_LOGO, 64, 510, "The official Clay website recreated with zclay: clay-zig-bindings", &zig_logo_image6);
|
||||
cl.UI(&.{
|
||||
.ID("LeftText"),
|
||||
.layout(.{ .sizing = .{ .w = .grow }, .direction = .TOP_TO_BOTTOM, .child_gap = 8 }),
|
||||
})({
|
||||
cl.text(
|
||||
"Clay is a flex-box style UI auto layout library in C, with declarative syntax and microsecond performance.",
|
||||
cl.Config.text(.{ .font_size = 56, .font_id = FONT_ID_TITLE_56, .color = COLOR_RED }),
|
||||
.text(.{ .font_size = 56, .font_id = FONT_ID_TITLE_56, .color = COLOR_RED }),
|
||||
);
|
||||
cl.UI(&.{ .ID("LeftText_Spacer"), .layout(.{ .sizing = .{ .w = .grow, .h = .fixed(32) } }) })({});
|
||||
cl.text(
|
||||
"Clay is laying out this webpage .right now!",
|
||||
cl.Config.text(.{ .font_size = 36, .font_id = FONT_ID_BODY_36, .color = COLOR_ORANGE }),
|
||||
.text(.{ .font_size = 36, .font_id = FONT_ID_BODY_36, .color = COLOR_ORANGE }),
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -161,11 +161,11 @@ fn landingPageMobile() void {
|
|||
.ID("HeroImageOuter"),
|
||||
.layout(.{ .sizing = .{ .w = .grow }, .direction = .TOP_TO_BOTTOM, .child_alignment = .{ .x = .CENTER }, .child_gap = 16 }),
|
||||
})({
|
||||
LandingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_5, 32, 480, "High performance", &checkImage5);
|
||||
LandingPageBlob(2, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_4, 32, 480, "Flexbox-style responsive layout", &checkImage4);
|
||||
LandingPageBlob(3, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_3, 32, 480, "Declarative syntax", &checkImage3);
|
||||
LandingPageBlob(4, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_2, 32, 480, "Single .h file for C/C++", &checkImage2);
|
||||
LandingPageBlob(5, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_1, 32, 480, "Compile to 15kb .wasm", &checkImage1);
|
||||
landingPageBlob(1, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_5, 32, 480, "High performance", &checkImage5);
|
||||
landingPageBlob(2, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_4, 32, 480, "Flexbox-style responsive layout", &checkImage4);
|
||||
landingPageBlob(3, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_3, 32, 480, "Declarative syntax", &checkImage3);
|
||||
landingPageBlob(4, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_2, 32, 480, "Single .h file for C/C++", &checkImage2);
|
||||
landingPageBlob(5, 30, FONT_ID_BODY_30, COLOR_BLOB_BORDER_1, 32, 480, "Compile to 15kb .wasm", &checkImage1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -399,7 +399,7 @@ fn rendererPage(title_text_config: cl.TextElementConfig, width_sizing: cl.Sizing
|
|||
.text(.{ .font_size = 28, .font_id = FONT_ID_BODY_36, .color = COLOR_RED }),
|
||||
);
|
||||
cl.text(
|
||||
"There's even an HTML renderer - you're looking at it .right now!",
|
||||
"There's even an HTML renderer - you're looking at it right now!",
|
||||
.text(.{ .font_size = 28, .font_id = FONT_ID_BODY_36, .color = COLOR_RED }),
|
||||
);
|
||||
});
|
||||
|
@ -468,7 +468,7 @@ fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
|
|||
.child_gap = 24,
|
||||
}),
|
||||
})({
|
||||
cl.text("Clay", cl.Config.text(.{
|
||||
cl.text("Clay", .text(.{
|
||||
.font_id = FONT_ID_BODY_24,
|
||||
.font_size = 24,
|
||||
.color = .{ 61, 26, 5, 255 },
|
||||
|
@ -477,10 +477,10 @@ fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
|
|||
|
||||
if (!mobileScreen) {
|
||||
cl.UI(&.{ .ID("LinkExamplesInner"), .layout(.{}), .rectangle(.{ .color = .{ 0, 0, 0, 0 } }) })({
|
||||
cl.text("Examples", cl.Config.text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }));
|
||||
cl.text("Examples", .text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }));
|
||||
});
|
||||
cl.UI(&.{ .ID("LinkDocsOuter"), .layout(.{}), .rectangle(.{ .color = .{ 0, 0, 0, 0 } }) })({
|
||||
cl.text("Docs", cl.Config.text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }));
|
||||
cl.text("Docs", .text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ fn createLayout(lerp_value: f32) cl.ClayArray(cl.RenderCommand) {
|
|||
})({
|
||||
cl.text(
|
||||
"Github",
|
||||
cl.Config.text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }),
|
||||
.text(.{ .font_id = FONT_ID_BODY_24, .font_size = 24, .color = .{ 61, 26, 5, 255 } }),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
@ -550,8 +550,8 @@ pub fn main() anyerror!void {
|
|||
const min_memory_size: u32 = cl.minMemorySize();
|
||||
const memory = try allocator.alloc(u8, min_memory_size);
|
||||
defer allocator.free(memory);
|
||||
const arena: cl.Arena = cl.createArenaWithCapacityAndMemory(min_memory_size, @ptrCast(memory));
|
||||
cl.initialize(arena, .{ .h = 1000, .w = 1000 });
|
||||
const arena: cl.Arena = cl.createArenaWithCapacityAndMemory(memory);
|
||||
_ = cl.initialize(arena, .{ .h = 1000, .w = 1000 }, .{});
|
||||
cl.setMeasureTextFunction(renderer.measureText);
|
||||
|
||||
// init raylib
|
||||
|
|
|
@ -20,25 +20,25 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
const render_command = cl.renderCommandArrayGet(render_commands, @intCast(i));
|
||||
const bounding_box = render_command.bounding_box;
|
||||
switch (render_command.command_type) {
|
||||
.None => {},
|
||||
.Text => {
|
||||
.none => {},
|
||||
.text => {
|
||||
const text = render_command.text.chars[0..@intCast(render_command.text.length)];
|
||||
const cloned = allocator.dupeZ(c_char, text) catch unreachable;
|
||||
const cloned = allocator.dupeZ(u8, text) catch unreachable;
|
||||
defer allocator.free(cloned);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_element_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_element_config.line_height);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_config.line_height);
|
||||
rl.drawTextEx(
|
||||
fontToUse,
|
||||
@ptrCast(@alignCast(cloned.ptr)),
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
@floatFromInt(render_command.config.text_element_config.font_size),
|
||||
@floatFromInt(render_command.config.text_element_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_element_config.color),
|
||||
@floatFromInt(render_command.config.text_config.font_size),
|
||||
@floatFromInt(render_command.config.text_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_config.color),
|
||||
);
|
||||
},
|
||||
.Image => {
|
||||
.image => {
|
||||
const image_texture: *const rl.Texture2D = @ptrCast(
|
||||
@alignCast(render_command.config.image_element_config.image_data),
|
||||
@alignCast(render_command.config.image_config.image_data),
|
||||
);
|
||||
rl.drawTextureEx(
|
||||
image_texture.*,
|
||||
|
@ -48,7 +48,7 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
rl.Color.white,
|
||||
);
|
||||
},
|
||||
.ScissorStart => {
|
||||
.scissor_start => {
|
||||
rl.beginScissorMode(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
|
@ -56,9 +56,9 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
@intFromFloat(math.round(bounding_box.height)),
|
||||
);
|
||||
},
|
||||
.ScissorEnd => rl.endScissorMode(),
|
||||
.Rectangle => {
|
||||
const config = render_command.config.rectangle_element_config;
|
||||
.scissor_end => rl.endScissorMode(),
|
||||
.rectangle => {
|
||||
const config = render_command.config.rectangle_config;
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
const radius: f32 = (config.corner_radius.top_left * 2) / @min(bounding_box.width, bounding_box.height);
|
||||
rl.drawRectangleRounded(
|
||||
|
@ -82,8 +82,8 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
);
|
||||
}
|
||||
},
|
||||
.Border => {
|
||||
const config = render_command.config.border_element_config;
|
||||
.border => {
|
||||
const config = render_command.config.border_config;
|
||||
if (config.left.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
|
@ -178,7 +178,7 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
);
|
||||
}
|
||||
},
|
||||
.Custom => {
|
||||
.custom => {
|
||||
// Implement custom element rendering here
|
||||
},
|
||||
}
|
||||
|
|
|
@ -12,23 +12,22 @@ const sidebar_item_layout: cl.LayoutConfig = .{ .sizing = .{ .w = .grow, .h = .f
|
|||
|
||||
// Re-useable components are just normal functions
|
||||
fn sidebarItemComponent(index: usize) void {
|
||||
cl.singleElem(&.{
|
||||
cl.UI(&.{
|
||||
.IDI("SidebarBlob", @intCast(index)),
|
||||
.layout(sidebar_item_layout),
|
||||
.rectangle(.{ .color = orange }),
|
||||
});
|
||||
})({});
|
||||
}
|
||||
|
||||
// An example function to begin the "root" of your layout tree
|
||||
fn createLayout(profile_picture: *const rl.Texture2D) cl.ClayArray(cl.RenderCommand) {
|
||||
cl.beginLayout();
|
||||
if (cl.OPEN(&.{
|
||||
cl.UI(&.{
|
||||
.ID("OuterContainer"),
|
||||
.layout(.{ .direction = .LEFT_TO_RIGHT, .sizing = .grow, .padding = .all(16), .child_gap = 16 }),
|
||||
.rectangle(.{ .color = white }),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
if (cl.OPEN(&.{
|
||||
})({
|
||||
cl.UI(&.{
|
||||
.ID("SideBar"),
|
||||
.layout(.{
|
||||
.direction = .TOP_TO_BOTTOM,
|
||||
|
@ -38,34 +37,31 @@ fn createLayout(profile_picture: *const rl.Texture2D) cl.ClayArray(cl.RenderComm
|
|||
.child_gap = 16,
|
||||
}),
|
||||
.rectangle(.{ .color = light_grey }),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
if (cl.OPEN(&.{
|
||||
})({
|
||||
cl.UI(&.{
|
||||
.ID("ProfilePictureOuter"),
|
||||
.layout(.{ .sizing = .{ .w = .grow }, .padding = .all(16), .child_alignment = .{ .x = .LEFT, .y = .CENTER }, .child_gap = 16 }),
|
||||
.rectangle(.{ .color = red }),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
cl.singleElem(&.{
|
||||
})({
|
||||
cl.UI(&.{
|
||||
.ID("ProfilePicture"),
|
||||
.layout(.{ .sizing = .{ .h = .fixed(60), .w = .fixed(60) } }),
|
||||
.image(.{ .source_dimensions = .{ .h = 60, .w = 60 }, .image_data = @ptrCast(profile_picture) }),
|
||||
});
|
||||
cl.text("Clay - UI Library", cl.Config.text(.{ .font_size = 24, .color = light_grey }));
|
||||
}
|
||||
})({});
|
||||
cl.text("Clay - UI Library", .text(.{ .font_size = 24, .color = light_grey }));
|
||||
});
|
||||
|
||||
for (0..5) |i| sidebarItemComponent(i);
|
||||
}
|
||||
});
|
||||
|
||||
if (cl.OPEN(&.{
|
||||
cl.UI(&.{
|
||||
.ID("MainContent"),
|
||||
.layout(.{ .sizing = .grow }),
|
||||
.rectangle(.{ .color = light_grey }),
|
||||
})) {
|
||||
defer cl.CLOSE();
|
||||
})({
|
||||
//...
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
return cl.endLayout();
|
||||
}
|
||||
|
||||
|
@ -87,8 +83,8 @@ pub fn main() anyerror!void {
|
|||
const min_memory_size: u32 = cl.minMemorySize();
|
||||
const memory = try allocator.alloc(u8, min_memory_size);
|
||||
defer allocator.free(memory);
|
||||
const arena: cl.Arena = cl.createArenaWithCapacityAndMemory(min_memory_size, @ptrCast(memory));
|
||||
cl.initialize(arena, .{ .h = 1000, .w = 1000 });
|
||||
const arena: cl.Arena = cl.createArenaWithCapacityAndMemory(memory);
|
||||
_ = cl.initialize(arena, .{ .h = 1000, .w = 1000 }, .{});
|
||||
cl.setMeasureTextFunction(renderer.measureText);
|
||||
|
||||
// init raylib
|
||||
|
|
|
@ -20,25 +20,25 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
const render_command = cl.renderCommandArrayGet(render_commands, @intCast(i));
|
||||
const bounding_box = render_command.bounding_box;
|
||||
switch (render_command.command_type) {
|
||||
.None => {},
|
||||
.Text => {
|
||||
.none => {},
|
||||
.text => {
|
||||
const text = render_command.text.chars[0..@intCast(render_command.text.length)];
|
||||
const cloned = allocator.dupeZ(c_char, text) catch unreachable;
|
||||
const cloned = allocator.dupeZ(u8, text) catch unreachable;
|
||||
defer allocator.free(cloned);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_element_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_element_config.line_height);
|
||||
const fontToUse: rl.Font = raylib_fonts[render_command.config.text_config.font_id].?;
|
||||
rl.setTextLineSpacing(render_command.config.text_config.line_height);
|
||||
rl.drawTextEx(
|
||||
fontToUse,
|
||||
@ptrCast(@alignCast(cloned.ptr)),
|
||||
rl.Vector2{ .x = bounding_box.x, .y = bounding_box.y },
|
||||
@floatFromInt(render_command.config.text_element_config.font_size),
|
||||
@floatFromInt(render_command.config.text_element_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_element_config.color),
|
||||
@floatFromInt(render_command.config.text_config.font_size),
|
||||
@floatFromInt(render_command.config.text_config.letter_spacing),
|
||||
clayColorToRaylibColor(render_command.config.text_config.color),
|
||||
);
|
||||
},
|
||||
.Image => {
|
||||
.image => {
|
||||
const image_texture: *const rl.Texture2D = @ptrCast(
|
||||
@alignCast(render_command.config.image_element_config.image_data),
|
||||
@alignCast(render_command.config.image_config.image_data),
|
||||
);
|
||||
rl.drawTextureEx(
|
||||
image_texture.*,
|
||||
|
@ -48,7 +48,7 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
rl.Color.white,
|
||||
);
|
||||
},
|
||||
.ScissorStart => {
|
||||
.scissor_start => {
|
||||
rl.beginScissorMode(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
@intFromFloat(math.round(bounding_box.y)),
|
||||
|
@ -56,9 +56,9 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
@intFromFloat(math.round(bounding_box.height)),
|
||||
);
|
||||
},
|
||||
.ScissorEnd => rl.endScissorMode(),
|
||||
.Rectangle => {
|
||||
const config = render_command.config.rectangle_element_config;
|
||||
.scissor_end => rl.endScissorMode(),
|
||||
.rectangle => {
|
||||
const config = render_command.config.rectangle_config;
|
||||
if (config.corner_radius.top_left > 0) {
|
||||
const radius: f32 = (config.corner_radius.top_left * 2) / @min(bounding_box.width, bounding_box.height);
|
||||
rl.drawRectangleRounded(
|
||||
|
@ -82,8 +82,8 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
);
|
||||
}
|
||||
},
|
||||
.Border => {
|
||||
const config = render_command.config.border_element_config;
|
||||
.border => {
|
||||
const config = render_command.config.border_config;
|
||||
if (config.left.width > 0) {
|
||||
rl.drawRectangle(
|
||||
@intFromFloat(math.round(bounding_box.x)),
|
||||
|
@ -178,7 +178,7 @@ pub fn clayRaylibRender(render_commands: *cl.ClayArray(cl.RenderCommand), alloca
|
|||
);
|
||||
}
|
||||
},
|
||||
.Custom => {
|
||||
.custom => {
|
||||
// Implement custom element rendering here
|
||||
},
|
||||
}
|
||||
|
@ -227,6 +227,6 @@ pub fn measureText(clay_text: []const u8, config: *cl.TextElementConfig) cl.Dime
|
|||
|
||||
return cl.Dimensions{
|
||||
.h = text_height,
|
||||
.w = temp_text_width * scale_factor + @as(f32, @floatFromInt(temp_byte_counter - 1)) * letter_spacing,
|
||||
.w = temp_text_width * scale_factor + (@as(f32, @floatFromInt(temp_byte_counter)) - 1) * letter_spacing,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue