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
- Use slint material rust template (https://github.com/slint-ui/material-rust-template.git)
- Replace lib.rs:
slint::include_modules!();
pub fn main() {
let ui = MainWindow::new().unwrap();
ui.run().unwrap();
}
- 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"}]
}
];
}
}
- Click on the slint logo to open the ModalNavigationDrawer and select an item (Group2, Item1)
- ModalNavigationDrawer closes
- Click on the slint logo again to open the ModalNavigationDrawer again
- 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 (57b0f12)
- Platform/OS: Linux
- Programming Language: Rust
- Backend/Renderer:
Product Impact
No response
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
Expected
The ModalNavigationDrawer keeps the current_group and current_index (Group2, Item1)
Observed
Creating modal navigation draweris visible two times. This means the current_group and current_index gets a reset, because the object gets recreatedWorkaround
Store the current_group and current_index externally and use it when the object gets recreated
Reproducible Code (if applicable)
Environment Details
Product Impact
No response