menu_provider

Function menu_provider 

Source
pub fn menu_provider(
    args: impl Into<MenuProviderArgs>,
    state: MenuState,
    main_content: impl FnOnce() + Send + Sync + 'static,
    menu_content: impl FnOnce(&mut MenuScope<'_, '_>) + Send + Sync + 'static,
)
Expand description

Provides a Material Design 3 menu overlay anchored to a rectangle.

§Usage

Wrap page content and show contextual or overflow actions aligned to a trigger element.

§Parameters

  • args — configures placement, styling, and dismissal behavior; see MenuProviderArgs.
  • state — a clonable MenuState controlling open/close and anchor position.
  • main_content — closure rendering the underlying page UI.
  • menu_content — closure that receives a MenuScope to register menu items.

§Examples

use std::sync::Arc;
use tessera_ui::Dp;
use tessera_ui_basic_components::{
    menus::{
        menu_item, menu_provider, MenuAnchor, MenuItemArgsBuilder, MenuPlacement,
        MenuProviderArgsBuilder, MenuScope, MenuState,
    },
    ripple_state::RippleState,
    text::text,
};

let state = MenuState::new();
state.open_at(MenuAnchor::from_dp((Dp(8.0), Dp(24.0)), (Dp(120.0), Dp(36.0))));
let state_for_menu = state.clone();

let args = MenuProviderArgsBuilder::default()
    .placement(MenuPlacement::BelowStart)
    .build()
    .unwrap();

menu_provider(
    args,
    state.clone(),
    || {
        text("Main content");
    },
    move |menu_scope: &mut MenuScope<'_, '_>| {
        let menu_state = state_for_menu.clone();
        menu_scope.item(move || {
            menu_item(
                MenuItemArgsBuilder::default()
                    .label("Edit")
                    .on_click(Arc::new(|| {}))
                    .build()
                    .unwrap(),
                Some(menu_state.clone()),
                RippleState::new(),
            );
        });
    },
);

assert!(state.is_open());
state.close();
assert!(!state.is_open());