add(Scrollable): init function with corresponding usages
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 42s

This commit is contained in:
2025-03-29 21:21:23 +01:00
parent 0b7d032b11
commit 962a384ecf
8 changed files with 17 additions and 7 deletions

View File

@@ -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) {

View File

@@ -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 = .{

View File

@@ -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

View File

@@ -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);