Skip to content

Commit

Permalink
Avoid index out of range panic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewdavidmackenzie committed Dec 31, 2024
1 parent 3485f3a commit c08ed73
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/widget/menu/menu_bar_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,31 @@ where
let menu_state = menu_tree.state.downcast_ref::<MenuState>();

if let Some(active) = menu_state.active {
let next_item = &menu.items[active];
let next_tree = &mut menu_tree.children[active];
let next_parent_bounds = {
let slice_node = &menu_nodes.last().unwrap().children()[0];
let Some(node) = slice_node
.children()
.get(active - menu_state.slice.start_index)
else {
return;
if active < menu.items.len() {
let next_item = &menu.items[active];
let next_tree = &mut menu_tree.children[active];
let next_parent_bounds = {
let slice_node = &menu_nodes.last().unwrap().children()[0];
let Some(node) = slice_node
.children()
.get(active - menu_state.slice.start_index)
else {
return;
};

node.bounds() + (slice_node.bounds().position() - Point::ORIGIN)
};

node.bounds() + (slice_node.bounds().position() - Point::ORIGIN)
};
rec(
renderer,
next_item,
next_tree,
menu_nodes,
check_bounds_width,
next_parent_bounds,
direction,
viewport,
);
rec(
renderer,
next_item,
next_tree,
menu_nodes,
check_bounds_width,
next_parent_bounds,
direction,
viewport,
);
}
}
}
}
Expand Down

0 comments on commit c08ed73

Please sign in to comment.