diff --git a/examples/demo.zig b/examples/demo.zig index 08bf84e..995a5f4 100644 --- a/examples/demo.zig +++ b/examples/demo.zig @@ -75,7 +75,7 @@ pub fn main() !void { }, .{})); defer box.deinit(); - var scrollable: App.Scrollable = .{ .container = box }; + var scrollable: App.Scrollable = .init(box); var container = try App.Container.init(allocator, .{ .layout = .{ diff --git a/examples/elements/scrollable.zig b/examples/elements/scrollable.zig index def557f..575b33e 100644 --- a/examples/elements/scrollable.zig +++ b/examples/elements/scrollable.zig @@ -156,10 +156,10 @@ pub fn main() !void { defer container.deinit(); // place empty container containing the element of the scrollable Container. - var scrollable_top: App.Scrollable = .{ .container = top_box }; + var scrollable_top: App.Scrollable = .init(top_box); try container.append(try App.Container.init(allocator, .{}, scrollable_top.element())); - var scrollable_bottom: App.Scrollable = .{ .container = bottom_box }; + var scrollable_bottom: App.Scrollable = .init(bottom_box); try container.append(try App.Container.init(allocator, .{}, scrollable_bottom.element())); try app.start(); diff --git a/examples/styles/palette.zig b/examples/styles/palette.zig index 044f6e8..49cf418 100644 --- a/examples/styles/palette.zig +++ b/examples/styles/palette.zig @@ -63,7 +63,7 @@ pub fn main() !void { if (comptime field.value == 0) continue; // zterm.Color.default == 0 -> skip try box.append(try App.Container.init(allocator, .{ .rectangle = .{ .fill = @enumFromInt(field.value) } }, .{})); } - var scrollable: App.Scrollable = .{ .container = box }; + var scrollable: App.Scrollable = .init(box); try container.append(try App.Container.init(allocator, .{}, scrollable.element())); try app.start(); diff --git a/examples/styles/text.zig b/examples/styles/text.zig index 6f29c09..ace417c 100644 --- a/examples/styles/text.zig +++ b/examples/styles/text.zig @@ -118,7 +118,7 @@ pub fn main() !void { }, text_styles.element()); defer box.deinit(); - var scrollable: App.Scrollable = .{ .container = box }; + var scrollable: App.Scrollable = .init(box); try container.append(try App.Container.init(allocator, .{}, scrollable.element())); try app.start(); diff --git a/src/color.zig b/src/color.zig index f75e704..3623056 100644 --- a/src/color.zig +++ b/src/color.zig @@ -20,6 +20,8 @@ pub const Color = enum(u8) { white, // TODO add further colors as described in https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b # Color / Graphics Mode - 256 Colors + // TODO might be useful to use the std.ascii stuff! + pub inline fn write(this: Color, writer: anytype, comptime coloring: enum { fg, bg, ul }) !void { if (this == .default) { switch (coloring) { diff --git a/src/element.zig b/src/element.zig index e45f133..818a693 100644 --- a/src/element.zig +++ b/src/element.zig @@ -78,6 +78,10 @@ pub fn Scrollable(Event: type) type { /// The actual `Container`, that is scrollable. container: Container(Event), + pub fn init(container: Container(Event)) @This() { + return .{ .container = container }; + } + pub fn element(this: *@This()) Element(Event) { return .{ .ptr = this, @@ -222,7 +226,7 @@ test "scrollable vertical" { }, .{})); defer box.deinit(); - var scrollable: Scrollable(event.SystemEvent) = .{ .container = box }; + var scrollable: Scrollable(event.SystemEvent) = .init(box); var container: Container(event.SystemEvent) = try .init(allocator, .{ .border = .{ @@ -300,7 +304,7 @@ test "scrollable horizontal" { }, .{})); defer box.deinit(); - var scrollable: Scrollable(event.SystemEvent) = .{ .container = box }; + var scrollable: Scrollable(event.SystemEvent) = .init(box); var container: Container(event.SystemEvent) = try .init(allocator, .{ .border = .{ diff --git a/src/input.zig b/src/input.zig index b294260..056b656 100644 --- a/src/input.zig +++ b/src/input.zig @@ -68,6 +68,8 @@ pub const Key = packed struct { return std.meta.eql(this, other); } + // TODO might be useful to use the std.ascii stuff! + /// Determine if the `Key` is an ascii character that can be printed to /// the screen. This means that the code point of the `Key` is an ascii /// character between 32 - 255 (with the exception of 127 = Delete) and no diff --git a/src/style.zig b/src/style.zig index 9d7fa37..9e5f53b 100644 --- a/src/style.zig +++ b/src/style.zig @@ -44,6 +44,8 @@ pub fn eql(this: Style, other: Style) bool { return std.meta.eql(this, other); } +// TODO might be useful to use the std.ascii stuff! + pub fn value(this: Style, writer: anytype, cp: u21) !void { var buffer: [4]u8 = undefined; const bytes = try std.unicode.utf8Encode(cp, &buffer);