Compare commits

...

4 Commits

Author SHA1 Message Date
Patrick Cleavelin ad8ddae790 LOTS OF STUFF
* Move all global variables to UI_Context struct
* Add string formatting to API
* Allocate formatted (and const too, gross) strings via a frame allocator
* Add higher level Grid component

still lots of jank and built-in assumptions
2023-07-11 16:06:40 -05:00
Patrick Cleavelin 8e7a5bb3a8 upgrade raylib bindings to f3a2786 2023-07-11 16:03:53 -05:00
Patrick Cleavelin 570830f91c scrolling! 2023-07-03 14:52:31 -05:00
Patrick Cleavelin 0d27a14687 upgrade zig to f571438fc, add grid components 2023-07-02 17:45:47 -05:00
3 changed files with 894 additions and 526 deletions

@ -1 +1 @@
Subproject commit 85750745b3a621e2107083e0589cf5fc3a1a73e7
Subproject commit f3a27866a77862a93f10f29fe5d69b5f16a38a3b

73
src/components.zig Normal file
View File

@ -0,0 +1,73 @@
const ui = @import("lib.zig");
const raylib = ui.raylib;
pub const Grid = struct {
fn MakeColumnHeader(ctx: *ui.UIContext, columns: [][]const u8) !void {
_ = try ctx.PushBox("GridColumnHeader", .{ .drawBackground = true, .drawBorder = false }, .leftToRight, .fitToChildren);
defer ctx.PopBox();
try ctx.PushStyle(.{ //
.color = raylib.WHITE, //
.text_color = .{ .r = 0x18, .g = 0x90, .b = 0xff, .a = 0xff }, //
.text_size = 12, //
.text_padding = 12, //
});
defer ctx.PopStyle();
for (columns) |column| {
try MakeLabel(ctx, column, @as(i32, @intCast(columns.len)));
}
}
pub fn MakeButton(ctx: *ui.UIContext, label: []const u8, items: i32) !bool {
return try ctx.MakeBox(label, .{
.clickable = true,
.drawText = true,
}, .leftToRight, .{ .percentOfParent = ui.Vec2{ .x = 1.0 / @as(f32, @floatFromInt(items)), .y = 1.0 } });
}
pub fn MakeFormattedLabel(ctx: *ui.UIContext, comptime str: []const u8, args: anytype, items: i32) !void {
_ = try ctx.MakeFormattedLabelWithLayout(str, args, .{ .percentOfParent = ui.Vec2{ .x = 1.0 / @as(f32, @floatFromInt(items)), .y = 1.0 } });
}
pub fn MakeLabel(ctx: *ui.UIContext, label: []const u8, items: i32) !void {
_ = try ctx.MakeLabelWithLayout(label, .{ .percentOfParent = ui.Vec2{ .x = 1.0 / @as(f32, @floatFromInt(items)), .y = 1.0 } });
}
pub fn MakeGrid(ctx: *ui.UIContext, comptime T: type, columns: [][]const u8, data: []T, MakeBody: *const fn (ctx: *ui.UIContext, data: *const T, size: i32) anyerror!void) !void {
_ = try ctx.PushBox("GridContainer", .{ .drawBackground = true }, .topToBottom, .fill);
defer ctx.PopBox();
try MakeColumnHeader(ctx, columns);
{
try ctx.PushStyle(.{ //
.color = raylib.WHITE, //
.hover_color = .{ .r = 0x1a, .g = 0x7c, .b = 0xd3, .a = 0xff }, //
.text_color = raylib.BLACK, //
.text_size = 12, //
.text_padding = 12, //
});
defer ctx.PopStyle();
_ = try ctx.PushBox("Grid", .{ .drawBackground = true, .scrollable = true }, .topToBottom, .fill);
defer ctx.PopBox();
try ctx.PushStyle(.{ //
.color = raylib.WHITE, //
.hover_color = raylib.LIGHTGRAY, //
.text_color = raylib.BLACK, //
.text_size = 12, //
.text_padding = 12, //
});
for (data) |item| {
_ = try ctx.PushBox("GridItem", .{ .drawBackground = true, .drawBorder = false, .hoverable = true }, .leftToRight, .fitToChildren);
defer ctx.PopBox();
try MakeBody(ctx, &item, @as(i32, @intCast(columns.len)));
}
ctx.PopStyle();
}
}
};

File diff suppressed because it is too large Load Diff