2023-11-26 14:19:43 +01:00
|
|
|
const std = @import("std");
|
|
|
|
const zenolith = @import("zenolith");
|
|
|
|
const zsdl2 = @import("zenolith-sdl2");
|
|
|
|
|
|
|
|
pub const zenolith_options = struct {
|
|
|
|
pub const platform_impls = [_]type{zsdl2.Sdl2Platform};
|
|
|
|
pub const painter_impls = [_]type{zsdl2.Sdl2Painter};
|
2023-12-21 12:00:45 +01:00
|
|
|
pub const debug_render = true;
|
2023-11-26 14:19:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
pub fn main() !void {
|
|
|
|
const alloc = std.heap.c_allocator;
|
|
|
|
|
|
|
|
var platform = try zsdl2.Sdl2Platform.init(.{
|
|
|
|
.alloc = alloc,
|
|
|
|
});
|
|
|
|
defer platform.deinit();
|
|
|
|
|
2023-12-20 14:59:20 +01:00
|
|
|
var font = zenolith.text.Font.create(try platform.createFont(.{
|
2024-01-13 15:07:23 +01:00
|
|
|
.source = .{ .path = "/usr/share/fonts/liberation/LiberationSans-Regular.ttf" },
|
2023-11-26 14:19:43 +01:00
|
|
|
}), {});
|
|
|
|
defer font.deinit();
|
2024-01-10 23:30:05 +01:00
|
|
|
var zplatform = zenolith.platform.Platform.create(platform, .{});
|
2023-11-26 14:19:43 +01:00
|
|
|
|
|
|
|
const root = try zenolith.widget.Box.init(alloc, .vertical);
|
|
|
|
defer root.deinit();
|
|
|
|
|
|
|
|
{
|
|
|
|
var attrs = zenolith.attreebute.AttreebuteMap.init();
|
|
|
|
errdefer attrs.deinit(alloc);
|
|
|
|
|
|
|
|
(try attrs.mod(alloc, zenolith.attreebute.CurrentFont)).* = .{ .font = &font };
|
2024-01-13 15:07:23 +01:00
|
|
|
try zenolith.Theme.catppuccin_mocha.apply(alloc, &attrs);
|
2023-11-26 14:19:43 +01:00
|
|
|
|
|
|
|
root.data.attreebutes = attrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
root.downcast(zenolith.widget.Box).?.orth_expand = true;
|
2023-12-20 14:59:20 +01:00
|
|
|
try root.downcast(zenolith.widget.Box).?.addChildPositioned(
|
|
|
|
root,
|
|
|
|
null,
|
2024-01-13 15:07:23 +01:00
|
|
|
try zenolith.widget.Label.init(alloc, "Hello, Zenolith!"),
|
2023-12-20 14:59:20 +01:00
|
|
|
.center,
|
|
|
|
);
|
2023-11-26 14:19:43 +01:00
|
|
|
|
2024-01-13 15:07:23 +01:00
|
|
|
try root.addChild(null, try zenolith.widget.Label.init(alloc, "Labels!"));
|
2023-11-26 14:19:43 +01:00
|
|
|
|
2024-01-10 23:30:05 +01:00
|
|
|
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 1"));
|
|
|
|
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 2"));
|
|
|
|
try root.addChild(null, try zenolith.widget.Button.init(alloc, "Button 3"));
|
2023-11-26 14:19:43 +01:00
|
|
|
|
2024-01-13 19:16:59 +01:00
|
|
|
try root.addChild(null, try zenolith.widget.Spacer.init(alloc, .{ .flex = 1 }));
|
2024-01-13 15:07:23 +01:00
|
|
|
|
2023-12-20 14:59:20 +01:00
|
|
|
{
|
|
|
|
var chunk = zenolith.text.Chunk.init(alloc);
|
|
|
|
errdefer chunk.deinit();
|
|
|
|
|
|
|
|
try chunk.spans.append(.{ .span = try zenolith.text.Span.init(alloc, .{
|
|
|
|
.font = &font,
|
|
|
|
.text = "Span 1",
|
|
|
|
.style = .{ .size = 32 },
|
|
|
|
}) });
|
|
|
|
try chunk.spans.append(.{ .span = try zenolith.text.Span.init(alloc, .{
|
|
|
|
.font = &font,
|
|
|
|
.text = "Span 2",
|
|
|
|
.style = .{ .color = zenolith.Color.fromInt(0xff0000ff) },
|
|
|
|
}) });
|
|
|
|
try chunk.spans.append(.{ .span = try zenolith.text.Span.init(alloc, .{
|
|
|
|
.font = &font,
|
|
|
|
.text = "Span 3",
|
|
|
|
}), .wrap_mode = .always });
|
|
|
|
|
|
|
|
try chunk.spans.append(.{ .span = try zenolith.text.Span.init(alloc, .{
|
|
|
|
.font = &font,
|
|
|
|
.text = "abcdefghijklmnopqrstuvwxyz",
|
|
|
|
.style = .{ .size = 48 },
|
|
|
|
}), .wrap_mode = .always });
|
|
|
|
|
|
|
|
for ("abcdefghijklmnopqrstuvwxyz") |ch| {
|
|
|
|
try chunk.spans.append(.{ .span = try zenolith.text.Span.init(alloc, .{
|
|
|
|
.font = &font,
|
|
|
|
.text = &.{ch},
|
|
|
|
.style = .{ .size = 48 },
|
|
|
|
}) });
|
|
|
|
}
|
|
|
|
|
|
|
|
try root.addChild(null, try zenolith.widget.ChunkView.init(alloc, chunk));
|
|
|
|
}
|
|
|
|
|
2024-01-10 23:30:05 +01:00
|
|
|
try root.link(null, &zplatform);
|
2023-11-26 14:19:43 +01:00
|
|
|
|
2024-01-09 19:56:01 +01:00
|
|
|
try platform.run(root);
|
2023-11-26 14:19:43 +01:00
|
|
|
}
|