ai: mouse clickable chart timeframes
This commit is contained in:
parent
5aed55665c
commit
6b06b97061
1 changed files with 31 additions and 0 deletions
|
|
@ -286,6 +286,7 @@ const App = struct {
|
|||
chart_symbol: [16]u8 = undefined, // symbol the chart was rendered for
|
||||
chart_symbol_len: usize = 0,
|
||||
chart_timeframe_rendered: ?chart_mod.Timeframe = null, // timeframe the chart was rendered for
|
||||
chart_timeframe_row: ?usize = null, // screen row of the timeframe selector (for mouse clicks)
|
||||
chart_dirty: bool = true, // needs re-render
|
||||
chart_price_min: f64 = 0,
|
||||
chart_price_max: f64 = 0,
|
||||
|
|
@ -408,6 +409,35 @@ const App = struct {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Quote tab: click on timeframe selector to switch timeframes
|
||||
if (self.active_tab == .quote and mouse.row > 0) {
|
||||
if (self.chart_timeframe_row) |tf_row| {
|
||||
const content_row = @as(usize, @intCast(mouse.row)) + self.scroll_offset;
|
||||
if (content_row == tf_row) {
|
||||
// " Chart: [6M] YTD 1Y 3Y 5Y ([ ] to change)"
|
||||
// Prefix " Chart: " = 9 chars, then each TF takes label_len+2 (brackets/spaces) + 1 gap
|
||||
const col = @as(usize, @intCast(mouse.col));
|
||||
const prefix_len: usize = 9; // " Chart: "
|
||||
if (col >= prefix_len) {
|
||||
const timeframes = [_]chart_mod.Timeframe{ .@"6M", .ytd, .@"1Y", .@"3Y", .@"5Y" };
|
||||
var x: usize = prefix_len;
|
||||
for (timeframes) |tf| {
|
||||
const lbl_len = tf.label().len;
|
||||
const slot_width = lbl_len + 2 + 1; // [XX] + space or XX + space
|
||||
if (col >= x and col < x + slot_width) {
|
||||
if (tf != self.chart_timeframe) {
|
||||
self.chart_timeframe = tf;
|
||||
self.setStatus(tf.label());
|
||||
return ctx.consumeAndRedraw();
|
||||
}
|
||||
break;
|
||||
}
|
||||
x += slot_width;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Options tab: single-click to select and expand/collapse
|
||||
if (self.active_tab == .options and mouse.row > 0) {
|
||||
const content_row = @as(usize, @intCast(mouse.row)) + self.scroll_offset;
|
||||
|
|
@ -2472,6 +2502,7 @@ const App = struct {
|
|||
const hint = " ([ ] to change)";
|
||||
@memcpy(tf_buf[tf_pos..][0..hint.len], hint);
|
||||
tf_pos += hint.len;
|
||||
self.chart_timeframe_row = lines.items.len; // track which row the timeframe line is on
|
||||
try lines.append(arena, .{ .text = try arena.dupe(u8, tf_buf[0..tf_pos]), .style = th.mutedStyle() });
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue