From 9e7639e034627bfaddf59161a7d5c0b432fa3293 Mon Sep 17 00:00:00 2001 From: CJ van den Berg Date: Thu, 6 Nov 2025 18:24:31 +0100 Subject: [PATCH] refactor: add tui.set_focus_by_mouse_event and tui.set_focus_by_widget --- src/tui/tui.zig | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/tui/tui.zig b/src/tui/tui.zig index 6baec6b..d2820af 100644 --- a/src/tui/tui.zig +++ b/src/tui/tui.zig @@ -663,6 +663,20 @@ fn is_live_widget_ptr(self: *Self, w_: *Widget) bool { return if (self.mainview_) |*mv| mv.walk(&ctx, Ctx.find) else false; } +pub const FocusAction = enum { same, changed, notfound }; + +pub fn set_focus_by_widget(w: *Widget) FocusAction { + const self = current(); + const mv = self.mainview_ orelse return .notfound; + return mv.focus_view_by_widget(w); +} + +pub fn set_focus_by_mouse_event() FocusAction { + const self = current(); + const mv = mainview() orelse return .notfound; + return mv.focus_view_by_widget(self.hover_focus orelse return .notfound); +} + fn send_widgets(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool { const frame = tracy.initZone(@src(), .{ .name = "tui widgets" }); defer frame.deinit();