Skip to content
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
13 changes: 13 additions & 0 deletions crates/egui/src/widget_rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ impl WidgetRects {

let InteractOptions { move_to_top } = options;

let mut shift_layer_index_after = None;

let layer_widgets = by_layer.entry(layer_id).or_default();

match by_id.entry(widget_rect.id) {
Expand All @@ -187,6 +189,7 @@ impl WidgetRects {
if existing.layer_id == widget_rect.layer_id {
if move_to_top {
layer_widgets.remove(*idx_in_layer);
shift_layer_index_after = Some(*idx_in_layer);
*idx_in_layer = layer_widgets.len();
layer_widgets.push(*existing);
} else {
Expand All @@ -200,6 +203,16 @@ impl WidgetRects {
}
}
}

if let Some(shift_start) = shift_layer_index_after {
#[expect(clippy::needless_range_loop)]
for i in shift_start..layer_widgets.len() {
let w = &layer_widgets[i];
if let Some((idx_in_by_id, _)) = by_id.get_mut(&w.id) {
*idx_in_by_id = i;
}
}
}
}

pub fn set_info(&mut self, id: Id, info: WidgetInfo) {
Expand Down