Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid index out of range panic #313

Merged
merged 2 commits into from
Jan 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading