Skip to main content

euv_ui/component/context_menu/view/
struct.rs

1use super::*;
2
3/// Lifecycle-owned pending touch gesture and its cancellable browser timer.
4#[derive(Data, Default)]
5pub(crate) struct ContextMenuLongPress {
6    /// Original viewport coordinates and the gesture start time.
7    #[get(pub(crate), type(copy))]
8    #[get_mut(pub(crate))]
9    #[set(pub(crate))]
10    pub(crate) origin: Option<(i32, i32, f64)>,
11    /// Browser timeout identifier, absent on native hosts.
12    #[get(pub(crate))]
13    #[get_mut(pub(crate))]
14    #[set(pub(crate))]
15    pub(crate) timer: Option<i32>,
16    /// Owned callback; never forgotten or captured strongly by itself.
17    #[get(skip)]
18    #[get_mut(pub(crate))]
19    #[set(pub(crate))]
20    pub(crate) callback: Option<Closure<dyn FnMut()>>,
21}
22
23/// Props of the [`euv_context_menu`] component.
24#[derive(Clone, CustomDebug, Default)]
25pub struct EuvContextMenuProps {
26    /// Whether the menu is open.
27    pub open: Signal<bool>,
28}
29
30/// Props of the [`euv_context_menu_trigger`] component.
31#[derive(Clone, CustomDebug, Default)]
32pub struct EuvContextMenuTriggerProps {
33    /// Whether the menu is open.
34    pub open: Signal<bool>,
35    /// Whether pointer, keyboard, and touch opening are disabled.
36    pub disabled: bool,
37    /// The label shown inside the trigger.
38    pub label: &'static str,
39}
40
41/// Props of the [`euv_context_menu_content`] component.
42#[derive(Clone, CustomDebug, Default)]
43pub struct EuvContextMenuContentProps {
44    /// Whether the menu is open.
45    pub open: Signal<bool>,
46}
47
48/// Props of the [`euv_context_menu_group`] component.
49///
50/// The group holds the rows that belong to one heading.
51#[derive(Clone, Copy, CustomDebug, Default)]
52pub struct EuvContextMenuGroupProps {
53    /// The accessible name of the group.
54    pub label: &'static str,
55}
56
57/// Props of the [`euv_context_menu_radio_group`] component.
58///
59/// The group holds the rows that share one radio selection.
60#[derive(Clone, CustomDebug, Default)]
61pub struct EuvContextMenuRadioGroupProps {
62    /// The accessible name of the group.
63    pub label: &'static str,
64    /// Shared selection handle, also passed to every item in this group.
65    pub selection: EuvContextMenuRadioGroupState,
66}
67
68/// Explicit group context shared by the container and its radio items.
69///
70/// Create this handle with [`use_context_menu_radio_group`] and clone it for
71/// each part. The framework has no inherited component-context API.
72#[derive(Clone, CustomDebug, Default)]
73pub struct EuvContextMenuRadioGroupState {
74    /// The single source of truth for all checked states in this group.
75    pub value: Signal<String>,
76    /// Whether selection is controlled by the caller's change callback.
77    pub controlled: bool,
78    /// Called only when activation requests a different value.
79    #[debug(skip)]
80    pub on_value_change: Option<Rc<dyn Fn(String)>>,
81}
82
83/// Props of the [`euv_context_menu_sub`] component.
84///
85/// The sub-menu holds the rows of a nested menu.
86#[derive(Clone, Copy, CustomDebug, Default)]
87pub struct EuvContextMenuSubProps {
88    /// Whether the sub-menu is open.
89    pub open: Signal<bool>,
90    /// Immediate owning popup's open signal: root for first-level submenus,
91    /// containing submenu for deeper levels. Must differ from `open`.
92    /// Closing this owner resets the entire descendant branch, not selection.
93    pub parent_open: Signal<bool>,
94}
95
96/// Hook-owned guard independent of the app cleanup registry's strong slot handle.
97#[derive(Data)]
98pub(crate) struct ContextMenuSubBindingScope {
99    #[get(pub(crate))]
100    pub(crate) slot: Rc<RefCell<Option<ContextMenuSubBinding>>>,
101}
102
103/// Owned subscriptions connecting one submenu to its immediate parent.
104#[derive(Data)]
105pub(crate) struct ContextMenuSubBinding {
106    /// Parent popup state, independent of radio selection.
107    #[get(pub(crate), type(copy))]
108    pub(crate) parent_open: Signal<bool>,
109    /// This submenu's actual controlled state.
110    #[get(pub(crate), type(copy))]
111    pub(crate) open: Signal<bool>,
112    /// Listener detached when this binding is replaced or unmounted.
113    #[get(pub(crate), type(copy))]
114    pub(crate) parent_subscription: usize,
115    /// Guard preventing a hidden branch from being opened programmatically.
116    #[get(pub(crate), type(copy))]
117    pub(crate) open_subscription: usize,
118    /// Browser ownership identity and weak controller for synchronous teardown.
119    #[cfg(target_arch = "wasm32")]
120    #[get(pub(crate))]
121    pub(crate) hover_owner: Rc<ContextMenuHoverOwner>,
122}
123
124/// Props of the [`euv_context_menu_sub_trigger`] component.
125#[derive(Clone, Copy, CustomDebug)]
126pub struct EuvContextMenuSubTriggerProps {
127    /// The label shown inside the row.
128    pub label: &'static str,
129    /// Whether the sub-menu is open.
130    pub open: Signal<bool>,
131    /// Whether activation and navigation skip this trigger.
132    pub disabled: bool,
133    /// Whether hover-capable mouse or pen movement opens this submenu.
134    pub open_on_hover: bool,
135    /// Hover entry delay in milliseconds; defaults to 100.
136    pub delay_ms: u32,
137    /// Hover dismissal delay in milliseconds; defaults to zero.
138    pub close_delay_ms: u32,
139}
140
141/// Props of the [`euv_context_menu_sub_content`] component.
142#[derive(Clone, Copy, CustomDebug, Default)]
143pub struct EuvContextMenuSubContentProps {
144    /// Whether the sub-menu is open.
145    pub open: Signal<bool>,
146}
147
148/// Props of the [`euv_context_menu_item`] component.
149#[derive(Clone, CustomDebug)]
150pub struct EuvContextMenuItemProps {
151    /// The shared open-state signal for the context menu.
152    pub open: Signal<bool>,
153    /// The value the row stands for.
154    pub value: &'static str,
155    /// The label shown inside the row.
156    pub label: &'static str,
157    /// Whether the row is disabled.
158    pub disabled: bool,
159    /// Whether choosing the row closes the menu. Defaults to true.
160    pub close_on_click: bool,
161    /// Optional callback receiving the chosen value.
162    #[debug(skip)]
163    pub on_select: Option<Rc<dyn Fn(&'static str)>>,
164}
165
166/// Props of the [`euv_context_menu_checkbox_item`] component.
167#[derive(Clone, CustomDebug, Default)]
168pub struct EuvContextMenuCheckboxItemProps {
169    /// The shared open-state signal for the context menu.
170    pub open: Signal<bool>,
171    /// Whether choosing the row closes the menu. Defaults to false.
172    pub close_on_click: bool,
173    /// The label shown inside the row.
174    pub label: &'static str,
175    /// Whether the box is checked.
176    pub checked: Signal<bool>,
177    /// Optional callback fired when the row is chosen.
178    #[debug(skip)]
179    pub on_select: Option<Rc<dyn Fn(bool)>>,
180}
181
182/// Props of the [`euv_context_menu_radio_item`] component.
183#[derive(Clone, CustomDebug, Default)]
184pub struct EuvContextMenuRadioItemProps {
185    /// The label shown inside the row.
186    pub label: &'static str,
187    /// The unique value this row represents within its group.
188    pub value: &'static str,
189    /// The same selection handle supplied to the containing radio group.
190    pub selection: EuvContextMenuRadioGroupState,
191    /// Whether activation and keyboard navigation skip this row.
192    pub disabled: bool,
193    /// The root menu's shared open state, including for submenu items.
194    pub open: Signal<bool>,
195    /// Whether activation closes the menu, including an already-selected row.
196    /// Defaults to false.
197    pub close_on_click: bool,
198}
199
200/// Props of the [`euv_context_menu_label`] component.
201#[derive(Clone, Copy, CustomDebug, Default)]
202pub struct EuvContextMenuLabelProps {
203    /// The text of the heading.
204    pub text: &'static str,
205}
206
207/// Props of the [`euv_context_menu_separator`] component.
208#[derive(Clone, Copy, CustomDebug, Default)]
209pub struct EuvContextMenuSeparatorProps {
210    /// The label reported to assistive technology, if any.
211    pub label: &'static str,
212}
213
214/// Props of the [`euv_context_menu_shortcut`] component.
215#[derive(Clone, Copy, CustomDebug, Default)]
216pub struct EuvContextMenuShortcutProps {
217    /// The key hint text.
218    pub text: &'static str,
219}
220
221/// Lifecycle-owned submenu hover controller. All asynchronous callbacks hold Weak handles.
222#[cfg(target_arch = "wasm32")]
223#[derive(Data)]
224pub(crate) struct ContextMenuSubHover {
225    #[get(pub(super))]
226    #[set(pub(super))]
227    #[get_mut(pub(super))]
228    pub(super) open: Signal<bool>,
229    #[get(pub(super))]
230    #[set(pub(super))]
231    #[get_mut(pub(super))]
232    pub(super) parent: Rc<ContextMenuHoverOwner>,
233    #[get(pub(super))]
234    #[set(pub(super))]
235    #[get_mut(pub(super))]
236    pub(super) target: NodeRef<Element>,
237    #[get(pub(super))]
238    #[set(pub(super))]
239    #[get_mut(pub(super))]
240    pub(super) options: Cell<(bool, bool, u32, u32)>,
241    #[get(pub(super))]
242    #[set(pub(super))]
243    #[get_mut(pub(super))]
244    pub(super) mounted: Cell<bool>,
245    #[get(pub(super))]
246    #[set(pub(super))]
247    #[get_mut(pub(super))]
248    pub(super) timer: Cell<Option<i32>>,
249    #[get(pub(super))]
250    #[set(pub(super))]
251    #[get_mut(pub(super))]
252    pub(super) intent: Cell<Option<bool>>,
253    #[get(pub(super))]
254    #[set(pub(super))]
255    #[get_mut(pub(super))]
256    pub(super) anchor: Cell<Option<(f64, f64)>>,
257    #[get(pub(super))]
258    #[set(pub(super))]
259    #[get_mut(pub(super))]
260    pub(super) callback: RefCell<Option<Closure<dyn FnMut()>>>,
261    /// Listener and subscription teardown runs before callback storage drops.
262    #[get(pub(super))]
263    pub(super) cleanup: RefCell<Option<Box<dyn FnOnce()>>>,
264}
265
266/// Binding-owned identity; the controller never strongly owns its binding.
267#[cfg(target_arch = "wasm32")]
268#[derive(Data)]
269pub(crate) struct ContextMenuHoverOwner {
270    #[get(pub(crate), type(copy))]
271    pub(crate) parent: Signal<bool>,
272    #[get(pub(crate))]
273    pub(crate) controller: RefCell<Option<Weak<ContextMenuSubHover>>>,
274}