Skip to content

Commit

Permalink
Merge pull request #313 from andrewdavidmackenzie/main
Browse files Browse the repository at this point in the history
Avoid index out of range panic
  • Loading branch information
genusistimelord authored Jan 1, 2025
2 parents 3485f3a + 557f1d1 commit 7dde7a1
Showing 1 changed file with 55 additions and 49 deletions.
104 changes: 55 additions & 49 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 Expand Up @@ -246,35 +248,39 @@ where
let menu_state = menu_tree.state.downcast_mut::<MenuState>();

let rec_event = if let Some(active) = menu_state.active {
let next_tree = &mut menu_tree.children[active];
let next_item = &mut menu.items[active];
let next_parent_bounds = {
let Some(layout) = slice_layout
.children()
.nth(active - menu_state.slice.start_index)
else {
prev_bounds_list.pop();
return RecEvent::Event;
};
if active < menu_tree.children.len() {
let next_tree = &mut menu_tree.children[active];
let next_item = &mut menu.items[active];
let next_parent_bounds = {
let Some(layout) = slice_layout
.children()
.nth(active - menu_state.slice.start_index)
else {
prev_bounds_list.pop();
return RecEvent::Event;
};

layout.bounds()
};
layout.bounds()
};

rec(
next_tree,
next_item,
event,
layout_iter,
cursor,
renderer,
clipboard,
shell,
next_parent_bounds,
viewport,
prev_bounds_list,
&mut menu_state.active,
scroll_speed,
)
rec(
next_tree,
next_item,
event,
layout_iter,
cursor,
renderer,
clipboard,
shell,
next_parent_bounds,
viewport,
prev_bounds_list,
&mut menu_state.active,
scroll_speed,
)
} else {
RecEvent::Close
}
} else {
RecEvent::Close
};
Expand Down

0 comments on commit 7dde7a1

Please sign in to comment.