mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 22:30:03 -04:00
Fix new move_to_top flag breaking widget order (#7825)
* closes https://github.com/emilk/egui/issues/7812 * related https://github.com/emilk/egui/pull/7805 That pr introduced a bug that caused a mismatch in the `by_layer` / `by_id` widget rects. This should fix it by updating the index of all following widgets. Not super pretty and efficient, but I'm not sure if there's a better way. Maybe we could also just leave a "tombstone" / duplicate there in the by_layer map so we don't need to update the indexes?
This commit is contained in:
@@ -164,6 +164,8 @@ impl WidgetRects {
|
|||||||
|
|
||||||
let InteractOptions { move_to_top } = options;
|
let InteractOptions { move_to_top } = options;
|
||||||
|
|
||||||
|
let mut shift_layer_index_after = None;
|
||||||
|
|
||||||
let layer_widgets = by_layer.entry(layer_id).or_default();
|
let layer_widgets = by_layer.entry(layer_id).or_default();
|
||||||
|
|
||||||
match by_id.entry(widget_rect.id) {
|
match by_id.entry(widget_rect.id) {
|
||||||
@@ -187,6 +189,7 @@ impl WidgetRects {
|
|||||||
if existing.layer_id == widget_rect.layer_id {
|
if existing.layer_id == widget_rect.layer_id {
|
||||||
if move_to_top {
|
if move_to_top {
|
||||||
layer_widgets.remove(*idx_in_layer);
|
layer_widgets.remove(*idx_in_layer);
|
||||||
|
shift_layer_index_after = Some(*idx_in_layer);
|
||||||
*idx_in_layer = layer_widgets.len();
|
*idx_in_layer = layer_widgets.len();
|
||||||
layer_widgets.push(*existing);
|
layer_widgets.push(*existing);
|
||||||
} else {
|
} else {
|
||||||
@@ -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) {
|
pub fn set_info(&mut self, id: Id, info: WidgetInfo) {
|
||||||
|
|||||||
Reference in New Issue
Block a user