pub fn run_egui_context_pass_loop_system(world: &mut World) {
    let mut contexts_query = world.query::<MultiPassEguiQuery>();
    let mut used_schedules = HashSet::<InternedScheduleLabel>::default();

    let mut multipass_contexts: Vec<_> = contexts_query
        .iter_mut(world)
        .filter_map(|mut egui_context| {
            if egui_context.settings.run_manually {
                return None;
            }

            Some((
                egui_context.entity,
                egui_context.context.get_mut().clone(),
                egui_context.input.take(),
                egui_context.multipass_schedule.clone(),
            ))
        })
        .collect();

    for (entity, ctx, ref mut input, EguiMultipassSchedule(multipass_schedule)) in
        &mut multipass_contexts
    {
        if !used_schedules.insert(*multipass_schedule) {
            panic!("Each Egui context running in the multi-pass mode must have a unique schedule (attempted to reuse schedule {multipass_schedule:?})");
        }

        let output = ctx.run(input.take(), |_| {
            let _ = world.try_run_schedule(*multipass_schedule);
        });

        **contexts_query
            .get_mut(world, *entity)
            .expect("previously queried context")
            .output = Some(output);
    }

    // If Egui's running in the single-pass mode and a user placed all the UI systems in `EguiContextPass`,
    // we want to run the schedule just once.
    // (And since the code above runs only for multi-pass contexts, it's not run yet in the case of single-pass.)
    if world
        .query_filtered::<Entity, (With<EguiContext>, With<PrimaryWindow>)>()
        .iter(world)
        .next()
        .is_none()
    {
        // Silly control flow to test that we still have a context. Attempting to run the schedule
        // when a user has closed a window will result in a panic.
        return;
    }
    if !used_schedules.contains(&ScheduleLabel::intern(&EguiContextPass)) {
        let _ = world.try_run_schedule(EguiContextPass);
    }
}
Runs Egui contexts with the [`EguiMultipassSchedule`] component. If there are no contexts with
this component, runs the [`EguiContextPass`] schedule once independently.
src/lib.rs