Separator

A separator item is designed to provide a way to separate groups of menu items.

You can create it using either menu::Separator::new() method or via the menuitem! macro.

let sep = menu::Separator::new();

or

let sep = menuitem!("---");

or

let sep = menuitem!("type:separator");

Macro build

The following parameters are accepted by menuitem! when building a command menu item:

Parameter nameTypePositional parameterPurpose
typeStringNoThe type of the item (for a command item if this filed is being specified its value must be separator)

Events

There are no events associated with a separator.

Methods

There are no events associated with a separator.

Example

The following code creates a menu with multiple items separated between them.

use appcui::prelude::*;

#[Window(events = AppBarEvents, commands=Cmd1+Cmd2+Cmd3)]
struct MyWin {
    m_commands: Handle<MenuButton>,
}
impl MyWin {
    fn new() -> Self {
        let mut w = MyWin {
            base: window!("Test,a:c,w:40,h:8"),
            m_commands: Handle::None,
        };
        let mut m = Menu::new();
        m.add(menu::Command::new("Fist command", Key::None, mywin::Commands::Cmd1));
        m.add(menu::Separator::new());
        m.add(menuitem!("'Choice &A',F1,cmd:Cmd3,class:MyWin,selected:true"));
        m.add(menuitem!("'Choice &B',F2,cmd:Cmd3,class:MyWin,selected:false"));
        m.add(menuitem!("'Choice &C',F3,cmd:Cmd3,class:MyWin,selected:false"));
        m.add(menuitem!("---"));
        m.add(menu::Command::new("Another command", Key::None, mywin::Commands::Cmd2));
        w.m_commands = w.appbar().add(MenuButton::new("Commands", m, 0, Side::Left));

        w
    }
}
impl AppBarEvents for MyWin {
    fn on_update(&self, appbar: &mut AppBar) {
        appbar.show(self.m_commands);
    }
}

fn main() -> Result<(), appcui::system::Error> {
    let mut a = App::new().app_bar().build()?;
    a.add_window(MyWin::new());
    a.run();
    Ok(())
}