From 6b4b1f76bb6bf969fb5106f95fb3f9ad077fac08 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 3 Jul 2026 15:17:46 -0300 Subject: fixing mouse drag on web --- pane_ui.zig | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'pane_ui.zig') diff --git a/pane_ui.zig b/pane_ui.zig index f53fa269..6091cb5f 100644 --- a/pane_ui.zig +++ b/pane_ui.zig @@ -7,6 +7,8 @@ pub const PREFIX_W: u16 = 5; pub const Rect = struct { x: u16, y: u16, w: u16, h: u16 }; +pub const MousePos = struct { col: u16, row: u16 }; + pub const ScrollbarButton = enum { left, middle, right }; pub const Scrollbar = struct { @@ -165,6 +167,13 @@ pub fn paneAtSlots(rects: anytype, slots: anytype, col: u16, row: u16) ?usize { return null; } +pub fn clampMousePos(screen_w: u16, screen_h: u16, mouse: anytype) MousePos { + return .{ + .col = if (mouse.col < 0) 0 else @min(@as(u16, @intCast(mouse.col)), screen_w -| 1), + .row = if (mouse.row < 0) 0 else @min(@as(u16, @intCast(mouse.row)), screen_h -| 1), + }; +} + pub fn inMoveBox(r: Rect, col: u16, row: u16) bool { return col < r.x + GUTTER and row < r.y + BOX_H; } @@ -271,3 +280,23 @@ pub fn drawHoverResizeHints( } } } + +pub fn drawInteractionPreview( + win: anytype, + l: anytype, + rects: anytype, + col_x: anytype, + col_w: anytype, + screen_h: u16, + drag: anytype, + hover_col: u16, + hover_row: u16, + move_color: [3]u8, +) void { + switch (drag) { + .border_v => |d| drawBorderV(win, d.cur_x, screen_h), + .border_h => |d| drawBorderH(win, col_x[d.col], col_w[d.col], d.cur_y), + .move => |d| drawMovePreview(win, l, col_x, col_w, d.cur_x, d.cur_y, move_color), + else => drawHoverResizeHints(win, l, rects, col_x, col_w, screen_h, hover_col, hover_row), + } +} -- cgit v1.3