mod: bump zig version to 0.16.0
This commit is contained in:
+43
-42
@@ -20,7 +20,7 @@ pub fn Element(Model: type, Event: type) type {
|
||||
minSize: ?*const fn (ctx: *anyopaque, model: *const Model, size: Point) Point = null,
|
||||
resize: ?*const fn (ctx: *anyopaque, model: *const Model, size: Point) void = null,
|
||||
reposition: ?*const fn (ctx: *anyopaque, model: *const Model, origin: Point) void = null,
|
||||
handle: ?*const fn (ctx: *anyopaque, model: *Model, event: Event) anyerror!void = null,
|
||||
handle: ?*const fn (ctx: *anyopaque, io: std.Io, model: *Model, event: Event) anyerror!void = null,
|
||||
content: ?*const fn (ctx: *anyopaque, model: *const Model, cells: []Cell, size: Point) anyerror!void = null,
|
||||
};
|
||||
|
||||
@@ -78,9 +78,9 @@ pub fn Element(Model: type, Event: type) type {
|
||||
/// error may then be used by the application to display information
|
||||
/// about the error to the user and is left intentionally up to the
|
||||
/// implementation to decide.
|
||||
pub inline fn handle(this: @This(), model: *Model, event: Event) !void {
|
||||
pub inline fn handle(this: @This(), io: std.Io, model: *Model, event: Event) !void {
|
||||
if (this.vtable.handle) |handle_fn|
|
||||
try handle_fn(this.ptr, model, event);
|
||||
try handle_fn(this.ptr, io, model, event);
|
||||
}
|
||||
|
||||
/// Write content into the `cells` of the `Container`. The associated
|
||||
@@ -202,9 +202,9 @@ pub fn Alignment(Model: type, Event: type) type {
|
||||
this.container.reposition(model, origin);
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, io: std.Io, model: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
try this.container.handle(model, event);
|
||||
try this.container.handle(io, model, event);
|
||||
}
|
||||
|
||||
fn content(ctx: *anyopaque, model: *const Model, cells: []Cell, size: Point) !void {
|
||||
@@ -332,7 +332,7 @@ pub fn Scrollable(Model: type, Event: type) type {
|
||||
this.container.reposition(model, .{});
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, io: std.Io, model: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
switch (event) {
|
||||
// TODO what about multiple scrollable `Element` usages? mouse
|
||||
@@ -403,7 +403,7 @@ pub fn Scrollable(Model: type, Event: type) type {
|
||||
this.anchor.y = @min(value, max_anchor_y);
|
||||
}
|
||||
},
|
||||
else => try this.container.handle(model, .{
|
||||
else => try this.container.handle(io, model, .{
|
||||
.mouse = .{
|
||||
.x = mouse.x + this.anchor.x,
|
||||
.y = mouse.y + this.anchor.y,
|
||||
@@ -412,7 +412,7 @@ pub fn Scrollable(Model: type, Event: type) type {
|
||||
},
|
||||
}),
|
||||
},
|
||||
else => try this.container.handle(model, event),
|
||||
else => try this.container.handle(io, model, event),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,7 +559,8 @@ pub fn TextField(Model: type, Event: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn handle(this: *@This(), model: *Model, event: Event) !void {
|
||||
pub fn handle(this: *@This(), io: std.Io, model: *Model, event: Event) !void {
|
||||
_ = io;
|
||||
_ = model;
|
||||
switch (event) {
|
||||
.key => |key| {
|
||||
@@ -654,9 +655,9 @@ pub fn TextField(Model: type, Event: type) type {
|
||||
}
|
||||
}
|
||||
|
||||
fn element_handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
||||
fn element_handle(ctx: *anyopaque, io: std.Io, model: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
try this.handle(model, event);
|
||||
try this.handle(io, model, event);
|
||||
}
|
||||
|
||||
pub fn toOwnedSlice(this: *@This(), comptime t: enum { bytes, code_points }) !switch (t) {
|
||||
@@ -777,16 +778,16 @@ pub fn Input(Model: type, Event: type, Queue: type) fn (meta.FieldEnum(Event)) t
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, model: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, io: std.Io, model: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
switch (event) {
|
||||
.key => |key| {
|
||||
// NOTE handle order of keys such that the `input.Enter` might not be processed twice! (leading to unexpected values)
|
||||
try this.text_field.handle(model, event);
|
||||
try this.text_field.handle(io, model, event);
|
||||
|
||||
// TODO enter to accept?
|
||||
// - shift+enter is not recognized by the input reader of `zterm`, so currently it is not possible to add newlines into the text box?
|
||||
if (key.eql(.{ .cp = input.Enter }) or key.eql(.{ .cp = input.KpEnter })) this.queue.push(@unionInit(
|
||||
if (key.eql(.{ .cp = input.Enter }) or key.eql(.{ .cp = input.KpEnter })) try this.queue.push(io, @unionInit(
|
||||
Event,
|
||||
@tagName(accept_event),
|
||||
switch (event_type) {
|
||||
@@ -856,11 +857,11 @@ pub fn Button(Model: type, Event: type, Queue: type) fn (meta.FieldEnum(Event))
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, _: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, io: std.Io, _: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
switch (event) {
|
||||
// TODO should this also support key presses to accept?
|
||||
.mouse => |mouse| if (mouse.button == .left and mouse.kind == .release) this.queue.push(accept_event),
|
||||
.mouse => |mouse| if (mouse.button == .left and mouse.kind == .release) try this.queue.push(io, accept_event),
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
@@ -921,7 +922,7 @@ pub fn RadioButton(Model: type, Event: type) type {
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, _: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, _: std.Io, _: *Model, event: Event) !void {
|
||||
var this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
switch (event) {
|
||||
// TODO should this also support key presses to accept?
|
||||
@@ -989,7 +990,7 @@ pub fn Selection(Model: type, Event: type) fn (type) type {
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, _: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, _: std.Io, _: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
switch (event) {
|
||||
.mouse => |mouse| if (mouse.y == 0) {
|
||||
@@ -1148,7 +1149,7 @@ pub fn Progress(Model: type, Event: type, Queue: type) fn (meta.FieldEnum(Event)
|
||||
};
|
||||
}
|
||||
|
||||
fn handle(ctx: *anyopaque, _: *Model, event: Event) !void {
|
||||
fn handle(ctx: *anyopaque, _: std.Io, _: *Model, event: Event) !void {
|
||||
const this: *@This() = @ptrCast(@alignCast(ctx));
|
||||
// TODO should this `Element` trigger a completion event? (I don't think that this is useful?)
|
||||
switch (event) {
|
||||
@@ -1265,7 +1266,7 @@ test "scrollable vertical" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.top.zon"), renderer.screen);
|
||||
|
||||
// scroll down 15 times (exactly to the end) (with both mouse and key inputs)
|
||||
for (0..7) |_| try container.handle(&model, .{
|
||||
for (0..7) |_| try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_down,
|
||||
.kind = .press,
|
||||
@@ -1273,14 +1274,14 @@ test "scrollable vertical" {
|
||||
.y = 5,
|
||||
},
|
||||
});
|
||||
for (7..15) |_| try container.handle(&model, .{
|
||||
for (7..15) |_| try container.handle(std.testing.io, model, .{
|
||||
.key = .{ .cp = 'j' },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.bottom.zon"), renderer.screen);
|
||||
|
||||
// further scrolling down will not change anything
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_down,
|
||||
.kind = .press,
|
||||
@@ -1292,34 +1293,34 @@ test "scrollable vertical" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.bottom.zon"), renderer.screen);
|
||||
|
||||
// scrolling up and down again
|
||||
for (0..5) |_| try container.handle(&model, .{
|
||||
for (0..5) |_| try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'k' },
|
||||
});
|
||||
for (0..5) |_| try container.handle(&model, .{
|
||||
for (0..5) |_| try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'j' },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.bottom.zon"), renderer.screen);
|
||||
|
||||
// scrolling half page up and down again
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'u', .mod = .{ .ctrl = true } },
|
||||
});
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'd', .mod = .{ .ctrl = true } },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.bottom.zon"), renderer.screen);
|
||||
|
||||
// scrolling page up
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'b', .mod = .{ .ctrl = true } },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.top.zon"), renderer.screen);
|
||||
|
||||
// and down again
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'f', .mod = .{ .ctrl = true } },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
@@ -1381,7 +1382,7 @@ test "scrollable vertical with scrollbar" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.scrollbar.top.zon"), renderer.screen);
|
||||
|
||||
// scroll down 15 times (exactly to the end)
|
||||
for (0..15) |_| try container.handle(&model, .{
|
||||
for (0..15) |_| try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_down,
|
||||
.kind = .press,
|
||||
@@ -1393,7 +1394,7 @@ test "scrollable vertical with scrollbar" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.vertical.scrollbar.bottom.zon"), renderer.screen);
|
||||
|
||||
// further scrolling down will not change anything
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_down,
|
||||
.kind = .press,
|
||||
@@ -1460,7 +1461,7 @@ test "scrollable horizontal" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.horizontal.left.zon"), renderer.screen);
|
||||
|
||||
// scroll right 15 times (exactly to the end)
|
||||
for (0..15) |_| try container.handle(&model, .{
|
||||
for (0..15) |_| try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_right,
|
||||
.kind = .press,
|
||||
@@ -1472,7 +1473,7 @@ test "scrollable horizontal" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.horizontal.right.zon"), renderer.screen);
|
||||
|
||||
// further scrolling right will not change anything
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_right,
|
||||
.kind = .press,
|
||||
@@ -1539,7 +1540,7 @@ test "scrollable horizontal with scrollbar" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.horizontal.scrollbar.left.zon"), renderer.screen);
|
||||
|
||||
// scroll right 15 times (exactly to the end)
|
||||
for (0..15) |_| try container.handle(&model, .{
|
||||
for (0..15) |_| try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_right,
|
||||
.kind = .press,
|
||||
@@ -1551,7 +1552,7 @@ test "scrollable horizontal with scrollbar" {
|
||||
try testing.expectEqualCells(.{}, renderer.size, @import("test/element/scrollable.horizontal.scrollbar.right.zon"), renderer.screen);
|
||||
|
||||
// further scrolling right will not change anything
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.button = .wheel_right,
|
||||
.kind = .press,
|
||||
@@ -1736,21 +1737,21 @@ test "input element" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/input.without.text.zon"), renderer.screen);
|
||||
|
||||
// press 'a' 15 times
|
||||
for (0..15) |_| try container.handle(&model, .{
|
||||
for (0..15) |_| try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'a' },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/input.with.text.zon"), renderer.screen);
|
||||
|
||||
// press 'a' 15 times
|
||||
for (0..15) |_| try container.handle(&model, .{
|
||||
for (0..15) |_| try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = 'a' },
|
||||
});
|
||||
try renderer.render(@TypeOf(container), &container, Model, &.{});
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/input.with.text.overflow.zon"), renderer.screen);
|
||||
|
||||
// test the accepting of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.key = .{ .cp = input.Enter },
|
||||
});
|
||||
const accept_event = queue.pop();
|
||||
@@ -1802,7 +1803,7 @@ test "button" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/button.zon"), renderer.screen);
|
||||
|
||||
// test the accepting of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.mouse = .{
|
||||
.x = 5,
|
||||
.y = 3,
|
||||
@@ -1860,7 +1861,7 @@ test "progress" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/progress_zero.zon"), renderer.screen);
|
||||
|
||||
// test the progress of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.progress = 25,
|
||||
});
|
||||
container.resize(&.{}, size);
|
||||
@@ -1869,7 +1870,7 @@ test "progress" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/progress_one_quarter.zon"), renderer.screen);
|
||||
|
||||
// test the progress of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.progress = 50,
|
||||
});
|
||||
container.resize(&.{}, size);
|
||||
@@ -1878,7 +1879,7 @@ test "progress" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/progress_half.zon"), renderer.screen);
|
||||
|
||||
// test the progress of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.progress = 75,
|
||||
});
|
||||
container.resize(&.{}, size);
|
||||
@@ -1887,7 +1888,7 @@ test "progress" {
|
||||
// try testing.expectEqualCells(.{}, renderer.size, @import("test/element/progress_three_quarter.zon"), renderer.screen);
|
||||
|
||||
// test the progress of the `Element`
|
||||
try container.handle(&model, .{
|
||||
try container.handle(std.testing.io, &model, .{
|
||||
.progress = 100,
|
||||
});
|
||||
container.resize(&.{}, size);
|
||||
|
||||
Reference in New Issue
Block a user