pub struct ContextMenu<A = ()> { /* private fields */ }Expand description
A retained right-click menu attached to an optional host child.
Visibility can be controlled, two-way bound, or internal. A right click can
open/re-anchor bound and internal menus; a controlled false value prevents
opening, while controlled true permits re-anchoring. When no pointer or
explicit anchor exists, the menu starts at the host’s bottom-left corner.
Escape/outside dismissal can write only bound or internal state.
§Examples
use ailloli_ui_widgets::controls::{ContextMenu, ContextMenuEntry, ContextMenuItem};
use ailloli_ui_widgets::text::Text;
let menu = ContextMenu::<()>::new(Text::new("File"))
.entries(vec![ContextMenuEntry::Item(ContextMenuItem::new("Open"))]);
let _ = menu;Implementations§
Source§impl<A: 'static> ContextMenu<A>
impl<A: 'static> ContextMenu<A>
Sourcepub fn height(self, value: impl Into<Length>) -> Self
pub fn height(self, value: impl Into<Length>) -> Self
Sets preferred height from a logical-pixel or length value.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().height(40.0);
let _ = widget;Sourcepub fn min_width(self, value: impl Into<Length>) -> Self
pub fn min_width(self, value: impl Into<Length>) -> Self
Sets the minimum width bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_width(40.0);
let _ = widget;Sourcepub fn max_width(self, value: impl Into<Length>) -> Self
pub fn max_width(self, value: impl Into<Length>) -> Self
Sets the maximum width bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_width(320.0);
let _ = widget;Sourcepub fn min_height(self, value: impl Into<Length>) -> Self
pub fn min_height(self, value: impl Into<Length>) -> Self
Sets the minimum height bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().min_height(24.0);
let _ = widget;Sourcepub fn max_height(self, value: impl Into<Length>) -> Self
pub fn max_height(self, value: impl Into<Length>) -> Self
Sets the maximum height bound.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().max_height(240.0);
let _ = widget;Sourcepub fn fill(self) -> Self
pub fn fill(self) -> Self
Sets both preferred axes to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill();
let _ = widget;Sourcepub fn fill_width(self) -> Self
pub fn fill_width(self) -> Self
Sets preferred width to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_width();
let _ = widget;Sourcepub fn fill_height(self) -> Self
pub fn fill_height(self) -> Self
Sets preferred height to parent fill.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().fill_height();
let _ = widget;Sourcepub fn margin(self, value: f32) -> Self
pub fn margin(self, value: f32) -> Self
Sets uniform outer margin in logical pixels.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().margin(8.0);
let _ = widget;Sourcepub fn padding(self, value: f32) -> Self
pub fn padding(self, value: f32) -> Self
Sets uniform inner padding in logical pixels.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().padding(8.0);
let _ = widget;Sourcepub fn flex_grow(self) -> Self
pub fn flex_grow(self) -> Self
Sets flex-grow weight to one.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow();
let _ = widget;Sourcepub fn flex_grow_by(self, value: f32) -> Self
pub fn flex_grow_by(self, value: f32) -> Self
Sets a dimensionless flex-grow weight.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_grow_by(2.0);
let _ = widget;Sourcepub fn flex_shrink(self, value: f32) -> Self
pub fn flex_shrink(self, value: f32) -> Self
Sets a dimensionless flex-shrink weight.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_shrink(1.0);
let _ = widget;Sourcepub fn flex_basis(self, value: impl Into<Length>) -> Self
pub fn flex_basis(self, value: impl Into<Length>) -> Self
Sets the preferred main-axis flex basis.
§Examples
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().flex_basis(80.0);
let _ = widget;Sourcepub fn align_self(self, value: AlignItems) -> Self
pub fn align_self(self, value: AlignItems) -> Self
Overrides cross-axis alignment for this flex item.
§Examples
use ailloli_ui_core::style::AlignItems;
use ailloli_ui_widgets::layout::Container;
let widget: Container<()> = Container::new().align_self(AlignItems::Center);
let _ = widget;Source§impl<A: 'static> ContextMenu<A>
impl<A: 'static> ContextMenu<A>
Sourcepub fn new(child: impl IntoView<A>) -> Self
pub fn new(child: impl IntoView<A>) -> Self
Creates a closed menu around one host child.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
use ailloli_ui_widgets::text::Text;
let menu: ContextMenu<()> = ContextMenu::new(Text::new("Right-click"));
let _ = menu;Sourcepub fn empty() -> Self
pub fn empty() -> Self
Creates a closed menu without a child or entries.
In an unbounded host it intrinsically measures as zero by zero.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty();
let _ = menu;Sourcepub fn open(self, open: impl Into<Binding<bool>>) -> Self
pub fn open(self, open: impl Into<Binding<bool>>) -> Self
Sets controlled visibility and clears two-way bound mode.
Portal dismissal cannot mutate this binding. A controlled false value
also prevents right-click opening.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty().open(true);
let _ = menu;Sourcepub fn bind_open(self, open: impl Into<Signal<bool>>) -> Self
pub fn bind_open(self, open: impl Into<Signal<bool>>) -> Self
Installs a writable visibility signal for opening and dismissal.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::Signal;
use ailloli_ui_widgets::controls::ContextMenu;
let open = Signal::new(Rc::new(RefCell::new(false)), Rc::new(|| {}));
let menu: ContextMenu<()> = ContextMenu::empty().bind_open(open);
let _ = menu;Sourcepub fn default_open(self, open: bool) -> Self
pub fn default_open(self, open: bool) -> Self
Sets initial internal visibility when no external source exists.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty().default_open(true);
let _ = menu;Sourcepub fn anchor(self, anchor: impl Into<Binding<Point>>) -> Self
pub fn anchor(self, anchor: impl Into<Binding<Point>>) -> Self
Sets a static or reactive programmatic anchor in host coordinates.
A later right click temporarily takes precedence until the menu closes.
§Examples
use ailloli_ui_core::Point;
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty().anchor(Point::new(12.0, 24.0));
let _ = menu;Sourcepub fn bind_anchor(self, anchor: impl Into<Signal<Point>>) -> Self
pub fn bind_anchor(self, anchor: impl Into<Signal<Point>>) -> Self
Installs a writable anchor signal and marks the anchor explicit.
The menu reads it reactively but does not write it during pointer opens.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_core::Point;
use ailloli_ui_runtime::component::Signal;
use ailloli_ui_widgets::controls::ContextMenu;
let anchor = Signal::new(Rc::new(RefCell::new(Point::new(1.0, 2.0))), Rc::new(|| {}));
let menu: ContextMenu<()> = ContextMenu::empty().bind_anchor(anchor);
let _ = menu;Sourcepub fn entries(
self,
entries: impl Into<Binding<Vec<ContextMenuEntry<A>>>>,
) -> Self
pub fn entries( self, entries: impl Into<Binding<Vec<ContextMenuEntry<A>>>>, ) -> Self
Sets the static or reactive complete entry collection.
Empty collections keep open state but publish no visible menu content.
§Examples
use ailloli_ui_widgets::controls::{ContextMenu, ContextMenuEntry, ContextMenuItem};
let entries = vec![ContextMenuEntry::Item(ContextMenuItem::new("Open"))];
let menu: ContextMenu<()> = ContextMenu::empty().entries(entries);
let _ = menu;Sourcepub fn bind_entries(
self,
entries: impl Into<Signal<Vec<ContextMenuEntry<A>>>>,
) -> Self
pub fn bind_entries( self, entries: impl Into<Signal<Vec<ContextMenuEntry<A>>>>, ) -> Self
Installs a writable signal as the live complete entry collection.
The menu only reads the signal; it never mutates its entries.
§Examples
use std::{cell::RefCell, rc::Rc};
use ailloli_ui_runtime::component::Signal;
use ailloli_ui_widgets::controls::{ContextMenu, ContextMenuEntry};
let entries = Signal::new(
Rc::new(RefCell::new(Vec::<ContextMenuEntry<()>>::new())),
Rc::new(|| {}),
);
let menu: ContextMenu<()> = ContextMenu::empty().bind_entries(entries);
let _ = menu;Sourcepub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
pub fn disabled(self, disabled: impl Into<Binding<bool>>) -> Self
Sets static or reactive disabled state.
Disabled state prevents right-click opening/focus and closes an existing portal programmatically without changing controlled visibility.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty().disabled(true);
let _ = menu;Replaces the complete popup and row style.
§Examples
use ailloli_ui_widgets::controls::{ContextMenu, ContextMenuStyle};
let menu: ContextMenu<()> = ContextMenu::empty().context_menu_style(ContextMenuStyle::default());
let _ = menu;Sets root-menu width in both the menu and nested popup styles.
This does not change submenu_width. The value is in logical pixels and
is not clamped.
§Examples
use ailloli_ui_widgets::controls::ContextMenu;
let menu: ContextMenu<()> = ContextMenu::empty().menu_width(300.0);
let _ = menu;