Skip to repository content103 lines · 2.8 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T02:37:24.383Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
popover_menu.rs
1use gpui::{
2 Anchor, AnyView, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, Pixels, Point,
3 Subscription,
4};
5use ui::{
6 FluentBuilder as _, IntoElement, PopoverMenu, PopoverMenuHandle, PopoverTrigger, prelude::*,
7};
8
9use crate::{Picker, PickerDelegate};
10
11pub struct PickerPopoverMenu<T, TT, P>
12where
13 T: PopoverTrigger + ButtonCommon,
14 TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
15 P: PickerDelegate,
16{
17 picker: Entity<Picker<P>>,
18 trigger: T,
19 tooltip: TT,
20 handle: Option<PopoverMenuHandle<Picker<P>>>,
21 anchor: Anchor,
22 offset: Option<Point<Pixels>>,
23 _subscriptions: Vec<Subscription>,
24}
25
26impl<T, TT, P> PickerPopoverMenu<T, TT, P>
27where
28 T: PopoverTrigger + ButtonCommon,
29 TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
30 P: PickerDelegate,
31{
32 pub fn new(
33 picker: Entity<Picker<P>>,
34 trigger: T,
35 tooltip: TT,
36 anchor: Anchor,
37 cx: &mut App,
38 ) -> Self {
39 picker.update(cx, |picker, _| picker.set_popover());
40 Self {
41 _subscriptions: vec![cx.subscribe(&picker, |picker, &DismissEvent, cx| {
42 picker.update(cx, |_, cx| cx.emit(DismissEvent));
43 })],
44 picker,
45 trigger,
46 tooltip,
47 handle: None,
48 offset: Some(Point {
49 x: px(0.0),
50 y: px(-2.0),
51 }),
52 anchor,
53 }
54 }
55
56 pub fn with_handle(mut self, handle: PopoverMenuHandle<Picker<P>>) -> Self {
57 self.handle = Some(handle);
58 self
59 }
60
61 pub fn offset(mut self, offset: Point<Pixels>) -> Self {
62 self.offset = Some(offset);
63 self
64 }
65}
66
67impl<T, TT, P> EventEmitter<DismissEvent> for PickerPopoverMenu<T, TT, P>
68where
69 T: PopoverTrigger + ButtonCommon,
70 TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
71 P: PickerDelegate,
72{
73}
74
75impl<T, TT, P> Focusable for PickerPopoverMenu<T, TT, P>
76where
77 T: PopoverTrigger + ButtonCommon,
78 TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
79 P: PickerDelegate,
80{
81 fn focus_handle(&self, cx: &App) -> FocusHandle {
82 self.picker.focus_handle(cx)
83 }
84}
85
86impl<T, TT, P> RenderOnce for PickerPopoverMenu<T, TT, P>
87where
88 T: PopoverTrigger + ButtonCommon,
89 TT: Fn(&mut Window, &mut App) -> AnyView + 'static,
90 P: PickerDelegate,
91{
92 fn render(self, _window: &mut Window, _cx: &mut App) -> impl IntoElement {
93 let picker = self.picker.clone();
94
95 PopoverMenu::new("popover-menu")
96 .menu(move |_window, _cx| Some(picker.clone()))
97 .trigger_with_tooltip(self.trigger, self.tooltip)
98 .anchor(self.anchor)
99 .when_some(self.handle, |menu, handle| menu.with_handle(handle))
100 .when_some(self.offset, |menu, offset| menu.offset(offset))
101 }
102}
103