-
Notifications
You must be signed in to change notification settings - Fork 9
Component Menu
MeowLynxSea edited this page Jun 18, 2026
·
2 revisions
A body-only shell that iterates MenuState.items and renders one row per item. Used inside Popover and DropdownMenu as the body content. Keyboard nav highlights the next / previous selectable item, wrapping at the ends and skipping separators.
use yororen_ui::headless::dropdown_menu::{DropdownItem, DropdownMenuItem};
use yororen_ui::headless::menu::{menu, MenuState};
let menu_state = MenuState::new(&mut **cx);
menu_state.update(cx, |s, _| {
s.set_items(vec![
DropdownItem::Item(DropdownMenuItem::new("profile", "Profile")),
DropdownItem::Item(DropdownMenuItem::new("settings", "Settings")),
DropdownItem::Separator,
DropdownItem::Item(DropdownMenuItem::new("logout", "Log out")),
]);
s.set_on_select({
let entity = cx.entity();
move |id, _, cx| entity.update(cx, |s, _| s.menu_choice = id.to_string());
});
});
menu("user-menu", menu_state).render(cx)| Method | Purpose |
|---|---|
new(app) |
Mint a fresh state. Returns Entity<Self>. |
set_items(items) |
Vec<DropdownItem> — DropdownItem::Item(DropdownMenuItem::new(id, label)), DropdownItem::Separator, or DropdownItem::Group(...). |
set_on_select(f) |
Fn(SharedString, &mut Window, &mut App) + 'static + Send + Sync. Fires on click or Enter once highlighted. |
select_highlighted(w, cx) |
Fire on_select for the highlighted item. |
highlight_next() / highlight_prev()
|
Move highlight; wraps at the ends and skips separators. |
.render(cx) returns a Stateful<Div> containing the full body — the caller does not append children. For a trigger + body pair, use DropdownMenu instead.
See also: DropdownMenu, Popover, Select.
Yororen UI v0.3.0 · repository · Apache-2.0 · This wiki documents Yororen UI v0.3.0.
This wiki documents Yororen UI v0.3.0 — the headless-core, swappable-renderer build.