fix(tui): prevent button active state from sticking
This commit is contained in:
parent
34bbfd49ad
commit
701107253f
3 changed files with 10 additions and 12 deletions
|
@ -91,17 +91,15 @@ pub fn State(ctx_type: type) type {
|
|||
pub fn receive(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
|
||||
var btn: u32 = 0;
|
||||
if (try m.match(.{ "B", event_type.PRESS, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.active = true;
|
||||
if (btn == key.BUTTON1) self.active = true;
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "B", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.call_click_handler(btn);
|
||||
self.active = false;
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "D", event_type.RELEASE, tp.extract(&btn), tp.any, tp.any, tp.any, tp.any, tp.any })) {
|
||||
self.call_click_handler(btn);
|
||||
self.active = false;
|
||||
tui.need_render();
|
||||
return true;
|
||||
} else if (try m.match(.{ "H", tp.extract(&self.hover) })) {
|
||||
|
@ -113,6 +111,7 @@ pub fn State(ctx_type: type) type {
|
|||
}
|
||||
|
||||
fn call_click_handler(self: *Self, btn: u32) void {
|
||||
if (btn == key.BUTTON1) self.active = false;
|
||||
if (!self.hover) return;
|
||||
switch (btn) {
|
||||
key.BUTTON1 => self.opts.on_click(&self.opts.ctx, self),
|
||||
|
|
|
@ -367,20 +367,19 @@ fn dispatch_mouse(ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) voi
|
|||
const m: tp.message = .{ .buf = cbor_msg };
|
||||
const from = tp.self_pid();
|
||||
self.unrendered_input_events_count += 1;
|
||||
self.send_mouse(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
||||
if (self.drag_source) |_|
|
||||
self.send_mouse_drag(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e)
|
||||
else
|
||||
self.send_mouse(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
||||
self.drag_source = null;
|
||||
}
|
||||
|
||||
fn dispatch_mouse_drag(ctx: *anyopaque, y: c_int, x: c_int, dragging: bool, cbor_msg: []const u8) void {
|
||||
fn dispatch_mouse_drag(ctx: *anyopaque, y: c_int, x: c_int, cbor_msg: []const u8) void {
|
||||
const self: *Self = @ptrCast(@alignCast(ctx));
|
||||
const m: tp.message = .{ .buf = cbor_msg };
|
||||
const from = tp.self_pid();
|
||||
self.unrendered_input_events_count += 1;
|
||||
if (dragging) {
|
||||
if (self.drag_source == null) self.drag_source = self.find_coord_widget(@intCast(y), @intCast(x));
|
||||
} else {
|
||||
self.drag_source = null;
|
||||
}
|
||||
if (self.drag_source == null) self.drag_source = self.find_coord_widget(@intCast(y), @intCast(x));
|
||||
self.send_mouse_drag(y, x, from, m) catch |e| self.logger.err("dispatch mouse", e);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue