unconditional debounce
This commit is contained in:
parent
43ab8d1957
commit
d442119d70
1 changed files with 10 additions and 13 deletions
23
src/tui.zig
23
src/tui.zig
|
|
@ -350,11 +350,11 @@ pub const App = struct {
|
||||||
fn handleMouse(self: *App, ctx: *vaxis.vxfw.EventContext, mouse: vaxis.Mouse) void {
|
fn handleMouse(self: *App, ctx: *vaxis.vxfw.EventContext, mouse: vaxis.Mouse) void {
|
||||||
switch (mouse.button) {
|
switch (mouse.button) {
|
||||||
.wheel_up => {
|
.wheel_up => {
|
||||||
self.moveBy(-3, true);
|
self.moveBy(-3);
|
||||||
return ctx.consumeAndRedraw();
|
return ctx.consumeAndRedraw();
|
||||||
},
|
},
|
||||||
.wheel_down => {
|
.wheel_down => {
|
||||||
self.moveBy(3, true);
|
self.moveBy(3);
|
||||||
return ctx.consumeAndRedraw();
|
return ctx.consumeAndRedraw();
|
||||||
},
|
},
|
||||||
.left => {
|
.left => {
|
||||||
|
|
@ -563,11 +563,11 @@ pub const App = struct {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.select_next => {
|
.select_next => {
|
||||||
self.moveBy(1, false);
|
self.moveBy(1);
|
||||||
return ctx.consumeAndRedraw();
|
return ctx.consumeAndRedraw();
|
||||||
},
|
},
|
||||||
.select_prev => {
|
.select_prev => {
|
||||||
self.moveBy(-1, false);
|
self.moveBy(-1);
|
||||||
return ctx.consumeAndRedraw();
|
return ctx.consumeAndRedraw();
|
||||||
},
|
},
|
||||||
.expand_collapse => {
|
.expand_collapse => {
|
||||||
|
|
@ -705,17 +705,14 @@ pub const App = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move cursor/scroll. Positive = down, negative = up.
|
/// Move cursor/scroll. Positive = down, negative = up.
|
||||||
/// For portfolio and options tabs, moves the row cursor by 1.
|
/// For portfolio and options tabs, moves the row cursor by 1 with
|
||||||
|
/// debounce to absorb duplicate events from mouse wheel ticks.
|
||||||
/// For other tabs, adjusts scroll_offset by |n|.
|
/// For other tabs, adjusts scroll_offset by |n|.
|
||||||
/// When from_wheel is true, debounces on cursor tabs to absorb
|
fn moveBy(self: *App, n: isize) void {
|
||||||
/// duplicate events that terminals send per physical scroll tick.
|
|
||||||
fn moveBy(self: *App, n: isize, from_wheel: bool) void {
|
|
||||||
if (self.active_tab == .portfolio or self.active_tab == .options) {
|
if (self.active_tab == .portfolio or self.active_tab == .options) {
|
||||||
if (from_wheel) {
|
const now = std.time.nanoTimestamp();
|
||||||
const now = std.time.nanoTimestamp();
|
if (now - self.last_wheel_ns < 1 * std.time.ns_per_ms) return;
|
||||||
if (now - self.last_wheel_ns < 1 * std.time.ns_per_ms) return;
|
self.last_wheel_ns = now;
|
||||||
self.last_wheel_ns = now;
|
|
||||||
}
|
|
||||||
if (self.active_tab == .portfolio) {
|
if (self.active_tab == .portfolio) {
|
||||||
stepCursor(&self.cursor, self.portfolio_rows.items.len, n);
|
stepCursor(&self.cursor, self.portfolio_rows.items.len, n);
|
||||||
self.ensureCursorVisible();
|
self.ensureCursorVisible();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue