diff options
| author | Gabriel Schneider <[email protected]> | 2026-07-03 15:17:46 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-01 15:02:07 -0300 |
| commit | 6b4b1f76bb6bf969fb5106f95fb3f9ad077fac08 (patch) | |
| tree | 423fa58bc169d44d7581ab50970f154e962646ab /pane_ui.zig | |
| parent | d1ed5bd8f55935e6470c4a7559216119571a084f (diff) | |
| download | pardes-6b4b1f76bb6bf969fb5106f95fb3f9ad077fac08.tar.gz pardes-6b4b1f76bb6bf969fb5106f95fb3f9ad077fac08.zip | |
fixing mouse drag on web
Diffstat (limited to 'pane_ui.zig')
| -rw-r--r-- | pane_ui.zig | 29 |
1 files changed, 29 insertions, 0 deletions
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), + } +} |
