diff --git a/build.zig b/build.zig index 9a716c1..c41ab42 100644 --- a/build.zig +++ b/build.zig @@ -4,6 +4,17 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const Examples = enum { + Layout, + Scrollable, + }; + + const example = b.option(Examples, "example", "Example to build and/or run.") orelse .Layout; + + const options = b.addOptions(); + options.addOption(Examples, "example", example); + + // dependencies const zg = b.dependency("zg", .{ .target = target, .optimize = optimize, @@ -17,27 +28,30 @@ pub fn build(b: *std.Build) void { }); lib.addImport("code_point", zg.module("code_point")); - // main executable (usually used for testing) - const exe = b.addExecutable(.{ - .name = "zterm", - .root_source_file = b.path("src/main.zig"), + // Examples.Scrollable + const scrollable = b.addExecutable(.{ + .name = "scrollable", + .root_source_file = b.path("examples/scrollable.zig"), .target = target, .optimize = optimize, }); - exe.root_module.addImport("zterm", lib); + scrollable.root_module.addImport("zterm", lib); - // TODO: add example execution through optional argument to `zig run` to run - // an example application instead of the main executable - - // example applications (usually used for documentation and demonstrations) - const container = b.addExecutable(.{ - .name = "container", - .root_source_file = b.path("examples/container.zig"), + // Examples.Layout + const layout = b.addExecutable(.{ + .name = "layout", + .root_source_file = b.path("examples/layout.zig"), .target = target, .optimize = optimize, }); - container.root_module.addImport("zterm", lib); - b.installArtifact(container); + layout.root_module.addImport("zterm", lib); + + // mapping of user selected example to compile step + const exe = switch (example) { + .Layout => layout, + .Scrollable => scrollable, + }; + b.installArtifact(exe); // zig build run const run_cmd = b.addRunArtifact(exe); diff --git a/examples/container.zig b/examples/layout.zig similarity index 100% rename from examples/container.zig rename to examples/layout.zig diff --git a/src/main.zig b/examples/scrollable.zig similarity index 97% rename from src/main.zig rename to examples/scrollable.zig index f5eefee..bc93d58 100644 --- a/src/main.zig +++ b/examples/scrollable.zig @@ -79,11 +79,10 @@ pub fn main() !void { .rectangle = .{ .fill = .blue }, .layout = .{ .gap = 1, - // FIX: horizontal rendering? - .direction = .horizontal, + .direction = .vertical, .padding = .vertical(1), }, - .min_size = .{ .cols = 150 }, + .min_size = .{ .rows = 50 }, }, .{}); try box.append(try App.Container.init(allocator, .{ .rectangle = .{ .fill = .light_green }, @@ -98,7 +97,7 @@ pub fn main() !void { var scrollable: App.Scrollable = .{ .container = box, - .horizontal = true, + .vertical = true, }; var container = try App.Container.init(allocator, .{