Repository: bevyengine/bevy
File: examples/ui/navigation/directional_navigation_overrides.rs (Rust)

Code before:

    // For the third page, add a notice about vertical navigation being inverted in the grid.
    if page_num == 2 {
        let footer_info = commands
            .spawn((
                Text::new(
                    "Vertical Navigation has been manually overridden to be inverted! \
                ^ moves down, and v (down) moves up.",
                ),
                Node {
                    position_type: PositionType::Absolute,
                    left: px(450),
                    top: px(600),
                    width: px(540),
                    padding: UiRect::all(px(12)),
                    ..default()
                },
                TextFont {
                    font_size: 20.0,
                    ..default()
                },
            ))
            .id();
        text_entities.push(footer_info);
    }
    if page_num == 0 {
        let footer_info = commands
            .spawn((
                Text::new(
                    "Vertical movements disabled on each button, but you can still go to the next row by going off the right side."
                ),
                Node {
                    position_type: PositionType::Absolute,
                    left: px(450),
                    top: px(600),
                    width: px(540),
                    padding: UiRect::all(px(12)),
                    ..default()
                },
                TextFont {
                    font_size: 20.0,
                    ..default()
                },
            ))
            .id();
        text_entities.push(footer_info);
    }
}

/// Creates the buttons and text for the triangle page (page 2) and places the ids into their
/// respective Vecs in `entities`.

Review comment (suggestion):
nit: instead of copying the if block, you can just have a variable that the Text is set to that is switched based on page_num i.e. something like (excuse the formatting)
let text = if page_num == 2 {
`"Vertical Navigation has been manually overridden to be inverted! \
                ^ moves down, and v (down) moves up.”,
` } else {
`"Vertical movements disabled on each button, but you can still go to the next row by going off the right side.”`
}

Code after:

    let text = match page_num {
        // For the first page, add a notice about vertical navigation being blocked off
        0 => Text::new(
            "Vertical movements disabled on each button, but you can still navigate between rows by going off the left or right sides."
        ),
        // For the third page, add a notice about vertical navigation being inverted in the grid.
        2 => Text::new(
            "Vertical Navigation has been manually overridden to be inverted! \
            ^ moves down, and v (down) moves up.",
        ),
        _ => Text::default()
    };
    let footer_info = commands
        .spawn((
            text,
            Node {
                position_type: PositionType::Absolute,
                left: px(450),
                top: px(600),
                width: px(540),
                padding: UiRect::all(px(12)),
                ..default()
            },
            TextFont {
                font_size: FontSize::Px(20.0),
                ..default()
            },
        ))
        .id();
    text_entities.push(footer_info);
}

/// Creates the buttons and text for the triangle page (page 2) and places the ids into their
/// respective Vecs in `entities`.
fn setup_buttons_for_triangle_page(
    commands: &mut Commands,
    page_num: usize,
    entities: (&mut Vec<Entity>, &mut Vec<Entity>),
) {
    let button_positions = [
        (450.0, 80.0),   // top left
        (700.0, 80.0),   // top right
        (575.0, 215.0),  // middle
        (1050.0, 350.0), // bottom right
    ];
    let (page_button_entities, text_entities) = entities;
    for (i, (left, top)) in button_positions.iter().enumerate() {
        let button_entity =
            spawn_auto_nav_button(commands, format!("Btn {}", i + 1), left, top, page_num);
        page_button_entities.push(button_entity);