Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Navigation

A widget, that handles keyboard navigation on its descendant widgets using Tab key. It should be used as a root widget for a hierarchy, that should support Tab key navigation:

#![allow(unused)]
fn main() {
fn create_navigation_layer(ctx: &mut BuildContext) {
    NavigationLayerBuilder::new(
        WidgetBuilder::new().with_child(
            StackPanelBuilder::new(
                WidgetBuilder::new()
                    .with_child(
                        // This widget won't participate in Tab key navigation.
                        TextBuilder::new(WidgetBuilder::new())
                            .with_text("Do something?")
                            .build(ctx),
                    )
                    // The keyboard focus for the following two buttons can be cycled using Tab/Shift+Tab.
                    .with_child(
                        ButtonBuilder::new(WidgetBuilder::new().with_tab_index(Some(0)))
                            .with_text("OK")
                            .build(ctx),
                    )
                    .with_child(
                        ButtonBuilder::new(WidgetBuilder::new().with_tab_index(Some(1)))
                            .with_text("Cancel")
                            .build(ctx),
                    ),
            )
            .build(ctx),
        ),
    )
    .build(ctx);
}
}

This example shows how to create a simple confirmation dialog, that allows a user to use Tab key to cycle from one button to another. A focused button then can be “clicked” using Enter key.