Skip to content

Commit 80d664f

Browse files
committed
Make "move_to_top" deterministic depending on the order in which it's called
1 parent 4ebee31 commit 80d664f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

crates/egui/src/memory/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,8 @@ pub struct Areas {
12251225
/// If several layers want to be on top, they will keep their relative order.
12261226
/// This means closing three windows and then reopening them all in one frame
12271227
/// results in them being sent to the top and keeping their previous internal order.
1228-
wants_to_be_on_top: ahash::HashSet<LayerId>,
1228+
// MEMBRANE: Make `move_to_top` deterministic depending on the order in which it's called.
1229+
wants_to_be_on_top: Vec<LayerId>,
12291230

12301231
/// The sublayers that each layer has.
12311232
///
@@ -1328,7 +1329,7 @@ impl Areas {
13281329

13291330
pub fn move_to_top(&mut self, layer_id: LayerId) {
13301331
self.visible_areas_current_frame.insert(layer_id);
1331-
self.wants_to_be_on_top.insert(layer_id);
1332+
self.wants_to_be_on_top.push(layer_id);
13321333

13331334
if !self.order.iter().any(|x| *x == layer_id) {
13341335
self.order.push(layer_id);
@@ -1400,7 +1401,16 @@ impl Areas {
14001401
std::mem::swap(visible_areas_last_frame, visible_areas_current_frame);
14011402
visible_areas_current_frame.clear();
14021403

1403-
order.sort_by_key(|layer| (layer.order, wants_to_be_on_top.contains(layer)));
1404+
order.sort_by_key(|layer| {
1405+
(
1406+
layer.order,
1407+
wants_to_be_on_top
1408+
.iter()
1409+
.position(|l| l == layer)
1410+
.map(|i| i + 1)
1411+
.unwrap_or(0),
1412+
)
1413+
});
14041414
wants_to_be_on_top.clear();
14051415

14061416
// For all layers with sublayers, put the sublayers directly after the parent layer:

0 commit comments

Comments
 (0)