refactor: add tui.set_focus_by_mouse_event and tui.set_focus_by_widget

This commit is contained in:
CJ van den Berg 2025-11-06 18:24:31 +01:00
parent ef991a8bee
commit 9e7639e034
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -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; 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 { fn send_widgets(self: *Self, from: tp.pid_ref, m: tp.message) error{Exit}!bool {
const frame = tracy.initZone(@src(), .{ .name = "tui widgets" }); const frame = tracy.initZone(@src(), .{ .name = "tui widgets" });
defer frame.deinit(); defer frame.deinit();