fix(gui): correct dispatching of mouse dragging events
This commit is contained in:
parent
9b0f40f155
commit
0a9842f34d
3 changed files with 46 additions and 5 deletions
|
|
@ -310,11 +310,11 @@ fn wioLoop() void {
|
||||||
const row_cell: i32 = @intCast(@divTrunc(@as(i32, @intCast(pos.y)), wio_font.cell_size.y));
|
const row_cell: i32 = @intCast(@divTrunc(@as(i32, @intCast(pos.y)), wio_font.cell_size.y));
|
||||||
const xoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.x)), wio_font.cell_size.x));
|
const xoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.x)), wio_font.cell_size.x));
|
||||||
const yoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.y)), wio_font.cell_size.y));
|
const yoff: i32 = @intCast(@mod(@as(i32, @intCast(pos.y)), wio_font.cell_size.y));
|
||||||
tui_pid.send(.{
|
if (input_translate.heldMouseButtonId(held_buttons)) |mb_id| {
|
||||||
"RDR", "M",
|
tui_pid.send(.{ "RDR", "D", mb_id, col_cell, row_cell, xoff, yoff }) catch {};
|
||||||
col_cell, row_cell,
|
} else {
|
||||||
xoff, yoff,
|
tui_pid.send(.{ "RDR", "M", col_cell, row_cell, xoff, yoff }) catch {};
|
||||||
}) catch {};
|
}
|
||||||
},
|
},
|
||||||
.scroll_vertical => |dy| {
|
.scroll_vertical => |dy| {
|
||||||
const btn_id: u8 = if (dy < 0) 64 else 65; // up / down scroll
|
const btn_id: u8 = if (dy < 0) 64 else 65; // up / down scroll
|
||||||
|
|
|
||||||
|
|
@ -165,3 +165,11 @@ pub fn mouseButtonId(b: wio.Button) ?u8 {
|
||||||
else => null,
|
else => null,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn heldMouseButtonId(held: ButtonSet) ?u8 {
|
||||||
|
const mouse_buttons = [_]wio.Button{ .mouse_left, .mouse_right, .mouse_middle, .mouse_back, .mouse_forward };
|
||||||
|
for (mouse_buttons) |btn| {
|
||||||
|
if (held.has(btn)) return mouseButtonId(btn);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -245,6 +245,39 @@ pub fn process_renderer_event(self: *Self, msg: []const u8) Error!void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
var args: struct {
|
||||||
|
pos: MousePos,
|
||||||
|
button_id: u8,
|
||||||
|
} = undefined;
|
||||||
|
if (try cbor.match(msg, .{
|
||||||
|
cbor.any,
|
||||||
|
"D",
|
||||||
|
cbor.extract(&args.button_id),
|
||||||
|
cbor.extract(&args.pos.col),
|
||||||
|
cbor.extract(&args.pos.row),
|
||||||
|
cbor.extract(&args.pos.xoffset),
|
||||||
|
cbor.extract(&args.pos.yoffset),
|
||||||
|
})) {
|
||||||
|
if (self.dispatch_mouse_drag) |f| f(
|
||||||
|
self.handler_ctx,
|
||||||
|
@intCast(args.pos.row),
|
||||||
|
@intCast(args.pos.col),
|
||||||
|
try self.fmtmsg(.{
|
||||||
|
"D",
|
||||||
|
input.event.press,
|
||||||
|
args.button_id,
|
||||||
|
input.utils.button_id_string(@enumFromInt(args.button_id)),
|
||||||
|
args.pos.col,
|
||||||
|
args.pos.row,
|
||||||
|
args.pos.xoffset,
|
||||||
|
args.pos.yoffset,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var args: struct {
|
var args: struct {
|
||||||
pos: MousePos,
|
pos: MousePos,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue