slint-ui/slint

ModalNavigationDrawer does not store current group and index

Aperta

#10.009 aperta il 9 nov 2025

 (4 commenti) (0 reazioni) (1 assegnatario)Rust (881 fork)batch import
a:material-componentsgood first issue

Metriche repository

Star
 (22.596 stelle)
Metriche merge PR
 (Merge medio 4g 18h) (254 PR mergiate in 30 g)

Descrizione

Bug Description

When an item in a ModalNavigationDrawer gets selected, the ModalNavigationDrawer calls the closed() function of the PopupWindow which deletes the object. When calling show() again for the ModalNavigationDrawer it gets recreated and the default indices are set to zero and therefore the first element of the first group gets always the selection.

Steps to reproduce

  1. Use slint material rust template (https://github.com/slint-ui/material-rust-template.git)
  2. Replace lib.rs:
slint::include_modules!();

pub fn main() {
    let ui = MainWindow::new().unwrap();
    ui.run().unwrap();
}
  1. Replace main.slint:
import { MaterialWindow, ModalNavigationDrawer, IconButton } from "../material-1.0/material.slint";

export component MainWindow inherits MaterialWindow {
    preferred-width: 600px;
    preferred-height: 400px;

    IconButton {
        icon: @image-url("slint-logo.svg");
        clicked => {
            modal_navigation_drawer.show();
        }
    }

    modal_navigation_drawer := ModalNavigationDrawer {
        x: -root.absolute_position.x;
        y: -root.absolute_position.y;
        width: root.width;
        height: root.height;
        position_right: false;

        init => {
            debug("Creating modal navigation drawer");
        }

        groups: [
            {
                title: "Provider",
                items: [ {text: "Group 0, Item 0"}, {text: "Group 0, Item 1"}]
            },
            {
                items: [ {text: "Group 1, Item 0"}, {text: "Group 1, Item 1"}]
            }
        ];
    }
}
  1. Click on the slint logo to open the ModalNavigationDrawer and select an item (Group2, Item1)
    • ModalNavigationDrawer closes
  2. Click on the slint logo again to open the ModalNavigationDrawer again
  3. Check debug print and selected item

Expected

The ModalNavigationDrawer keeps the current_group and current_index (Group2, Item1)

Observed

Creating modal navigation drawer is visible two times. This means the current_group and current_index gets a reset, because the object gets recreated

Workaround

Store the current_group and current_index externally and use it when the object gets recreated

import { MaterialWindow, ModalNavigationDrawer, IconButton } from "../material-1.0/material.slint";

export component MainWindow inherits MaterialWindow {
    preferred-width: 600px;
    preferred-height: 400px;

    IconButton {
        icon: @image-url("slint-logo.svg");
        clicked => {
            modal_navigation_drawer.show();
        }
    }

    // Storing the current group and current index
    property <int> current_group;
    property <int> current_index;

    modal_navigation_drawer := ModalNavigationDrawer {
        x: -root.absolute_position.x;
        y: -root.absolute_position.y;
        width: root.width;
        height: root.height;
        position_right: false;
        current_group: parent.current_group;
        current_index: parent.current_index;

        init => {
            debug("Creating modal navigation drawer");
        }

        changed current_group => {
            parent.current_group = self.current_group;
        }

        changed current_index => {
            parent.current_index = self.current_index;
        }

        groups: [
            {
                title: "Provider",
                items: [ {text: "Group 0, Item 0"}, {text: "Group 0, Item 1"}]
            },
            {
                items: [ {text: "Group 1, Item 0"}, {text: "Group 1, Item 1"}]
            }
        ];
    }
}

Reproducible Code (if applicable)

Environment Details

  • Slint Version: 1.15 master (57b0f12e0f8448195098000e35a906cf5e59ce74)
  • Platform/OS: Linux
  • Programming Language: Rust
  • Backend/Renderer:

Product Impact

No response

Guida contributor