ref(event): split Size into two Points (one for the size and one for the anchor / origin)
All checks were successful
Zig Project Action / Lint, Spell-check and test zig project (push) Successful in 39s

This commit is contained in:
2025-03-04 00:04:56 +01:00
parent 91ac6241f4
commit 591b990087
23 changed files with 477 additions and 459 deletions

View File

@@ -11,7 +11,7 @@ const isTaggedUnion = event.isTaggedUnion;
const Mouse = input.Mouse;
const Key = input.Key;
const Size = @import("size.zig").Size;
const Point = @import("point.zig").Point;
const log = std.log.scoped(.app);
@@ -51,7 +51,6 @@ pub fn App(comptime E: type) type {
quit_event: std.Thread.ResetEvent,
termios: ?std.posix.termios = null,
attached_handler: bool = false,
prev_size: Size,
pub const SignalHandler = struct {
context: *anyopaque,
@@ -64,7 +63,6 @@ pub fn App(comptime E: type) type {
.quit_event = .{},
.termios = null,
.attached_handler = false,
.prev_size = .{},
};
pub fn start(this: *@This()) !void {
@@ -101,9 +99,7 @@ pub fn App(comptime E: type) type {
try terminal.enableMouseSupport();
// send initial size afterwards
const size = terminal.getTerminalSize();
this.postEvent(.{ .resize = size });
this.prev_size = size;
this.postEvent(.{ .size = terminal.getTerminalSize() });
}
pub fn interrupt(this: *@This()) !void {
@@ -148,11 +144,7 @@ pub fn App(comptime E: type) type {
fn winsizeCallback(ptr: *anyopaque) void {
const this: *@This() = @ptrCast(@alignCast(ptr));
const size = terminal.getTerminalSize();
if (size.cols != this.prev_size.cols or size.rows != this.prev_size.rows) {
this.postEvent(.{ .resize = size });
this.prev_size = size;
}
this.postEvent(.{ .size = terminal.getTerminalSize() });
}
var winch_handler: ?SignalHandler = null;
@@ -302,8 +294,8 @@ pub fn App(comptime E: type) type {
const mouse: Mouse = .{
.button = button,
.col = px -| 1,
.row = py -| 1,
.x = px -| 1,
.y = py -| 1,
.kind = blk: {
if (motion and button != Mouse.Button.none) {
break :blk .drag;
@@ -334,19 +326,13 @@ pub fn App(comptime E: type) type {
if (std.mem.eql(u8, "48", ps)) {
// in band window resize
// CSI 48 ; height ; width ; height_pix ; width_pix t
const height_char = iter.next() orelse break;
const width_char = iter.next() orelse break;
const height_char = iter.next() orelse break;
// TODO only post the event if the size has changed?
// because there might be too many resize events (which force a re-draw of the entire screen)
const size: Size = .{
.rows = std.fmt.parseUnsigned(u16, height_char, 10) catch break,
.cols = std.fmt.parseUnsigned(u16, width_char, 10) catch break,
};
if (size.cols != this.prev_size.cols or size.rows != this.prev_size.rows) {
this.postEvent(.{ .resize = size });
this.prev_size = size;
}
this.postEvent(.{ .size = .{
.x = std.fmt.parseUnsigned(u16, width_char, 10) catch break,
.y = std.fmt.parseUnsigned(u16, height_char, 10) catch break,
} });
}
},
'u' => {