Skip to main content

mnemonic

Function mnemonic 

Source
pub fn mnemonic(
    child: impl IntoUiNode,
    mnemonic: impl IntoVar<Mnemonic>,
) -> UiNode
Expand description

P Defines the mnemonic char key that clicks the widget when pressed and focus is within the parent mnemonic scope.

Stack! {
    mnemonic_scope = true;
    alt_focus_scope = true;
    children = ui_vec![Button! {
        mnemonic = true;
        child = Label!("_Open File");
    },];
}

In the example above the Button! will be clicked when focus is within the parent Stack! and the O key is pressed.

Note that true converts into Mnemonic::FromTxt with _ marker, and if no valid char is defined in the inner mnemonic_txt text the behavior falls back to Mnemonic::Auto, so a simple mnemonic = true enables the most common use case for this feature.

Note the use of Label! instead of Text!, the Label! widget automatically sets mnemonic_txt, removes the markers from the rendered text and marks the mnemonic char with an underline.

The Menu! and related widgets automatically enables mnemonic for inner buttons, but you still must use Label! instead of Text!.

Note that the focus event inside the parent mnemonic_scope must be keyboard highlight, that is, for a Menu!, the mnemonics are only active when when focus enters by pressing Alt.