Skip to content

Commit

Permalink
attempt to fix slice being used as Max usize and Limit max size to Len()
Browse files Browse the repository at this point in the history
  • Loading branch information
genusistimelord committed Jul 20, 2024
1 parent 38df62a commit 168c252
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/widgets/menu/menu_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Default for MenuState {
active: None,
slice: MenuSlice {
start_index: 0,
end_index: usize::MAX,
end_index: usize::MAX - 1,
lower_bound_rel: 0.0,
upper_bound_rel: f32::MAX,
},
Expand Down Expand Up @@ -390,10 +390,12 @@ where

let menu_state = tree.state.downcast_ref::<MenuState>();
let slice = &menu_state.slice;
let max_item_slice = self.items.len().min(slice.end_index);
let max_tree_slice = tree.children.len().min(slice.end_index);

self.items[slice.start_index..=slice.end_index]
self.items[slice.start_index..=max_item_slice]
.iter()
.zip(tree.children[slice.start_index..=slice.end_index].iter()) // [item_tree...]
.zip(tree.children[slice.start_index..=max_tree_slice].iter()) // [item_tree...]
.zip(slice_layout.children()) // [item_layout...]
.map(|((item, tree), layout)| {
item.mouse_interaction(tree, layout, cursor, viewport, renderer)
Expand Down

0 comments on commit 168c252

Please sign in to comment.