Skip to content

Commit

Permalink
MAIN -> ROOT
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 6, 2023
1 parent 6a371e5 commit a52d383
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 85 deletions.
6 changes: 3 additions & 3 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn window_builder<E>(
..
} = native_options;

let mut window_builder = egui::ViewportBuilder::new(ViewportId::MAIN)
let mut window_builder = egui::ViewportBuilder::new(ViewportId::ROOT)
.with_title(title)
.with_close_button(true) // The default for all other viewports is `false`!
.with_decorations(*decorated)
Expand Down Expand Up @@ -425,7 +425,7 @@ impl EpiIntegration {
let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone());
self.egui_ctx
.memory_mut(|mem| mem.set_everything_is_visible(true));
let full_output = self.update(app, window, egui_winit, &None, ViewportIdPair::MAIN);
let full_output = self.update(app, window, egui_winit, &None, ViewportIdPair::ROOT);
self.pending_full_output.append(full_output); // Handle it next frame
self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge.
self.egui_ctx.clear_animations();
Expand All @@ -450,7 +450,7 @@ impl EpiIntegration {
match event {
WindowEvent::CloseRequested => {
log::debug!("Received WindowEvent::CloseRequested");
self.close = app.on_close_event() && viewport_id == ViewportId::MAIN;
self.close = app.on_close_event() && viewport_id == ViewportId::ROOT;
log::debug!("App::on_close_event returned {}", self.close);
}
WindowEvent::Destroyed => {
Expand Down
66 changes: 33 additions & 33 deletions crates/eframe/src/native/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ fn run_and_exit(event_loop: EventLoop<UserEvent>, mut winit_app: impl WinitApp +
// WaitUntil seems to not work on iOS
#[cfg(target_os = "ios")]
winit_app
.get_window_winit_id(ViewportId::MAIN)
.get_window_winit_id(ViewportId::ROOT)
.map(|window_id| {
winit_app
.window(window_id)
Expand Down Expand Up @@ -662,24 +662,24 @@ mod glow_integration {
let mut viewport_maps = HashMap::default();
let mut window_maps = ViewportMap::default();
if let Some(window) = &window {
viewport_maps.insert(window.id(), ViewportId::MAIN);
window_maps.insert(ViewportId::MAIN, window.id());
viewport_maps.insert(window.id(), ViewportId::ROOT);
window_maps.insert(ViewportId::ROOT, window.id());
}

let mut windows = ViewportMap::default();
windows.insert(
ViewportId::MAIN,
ViewportId::ROOT,
Rc::new(RefCell::new(Viewport {
gl_surface: None,
window: window.map(|w| Rc::new(RefCell::new(w))),
egui_winit: None,
viewport_ui_cb: None,
id_pair: ViewportIdPair::MAIN,
id_pair: ViewportIdPair::ROOT,
})),
);

let mut builders = ViewportMap::default();
builders.insert(ViewportId::MAIN, window_builder);
builders.insert(ViewportId::ROOT, window_builder);

// the fun part with opengl gl is that we never know whether there is an error. the context creation might have failed, but
// it could keep working until we try to make surface current or swap buffers or something else. future glutin improvements might
Expand Down Expand Up @@ -892,7 +892,7 @@ mod glow_integration {
native_options,
running: Rc::new(RefCell::new(None)),
app_creator: Some(app_creator),
is_focused: Rc::new(RefCell::new(Some(ViewportId::MAIN))),
is_focused: Rc::new(RefCell::new(Some(ViewportId::ROOT))),
}
}

Expand All @@ -914,7 +914,7 @@ mod glow_integration {
};
glutin_window_context.on_resume(event_loop)?;

if let Some(window) = &glutin_window_context.viewports.get(&ViewportId::MAIN) {
if let Some(window) = &glutin_window_context.viewports.get(&ViewportId::ROOT) {
let window = window.borrow();
if let Some(window) = &window.window {
epi_integration::apply_native_options_to_window(
Expand Down Expand Up @@ -960,7 +960,7 @@ mod glow_integration {
.unwrap_or_else(|err| panic!("An OpenGL error occurred: {err}\n"));

glutin_ctx.max_texture_side = painter.max_texture_side();
glutin_ctx.viewports[&ViewportId::MAIN]
glutin_ctx.viewports[&ViewportId::ROOT]
.borrow_mut()
.egui_winit
.as_mut()
Expand All @@ -969,7 +969,7 @@ mod glow_integration {

let system_theme = system_theme(
&glutin_ctx
.window(ViewportId::MAIN)
.window(ViewportId::ROOT)
.borrow()
.window
.as_ref()
Expand All @@ -979,7 +979,7 @@ mod glow_integration {
);
let mut integration = epi_integration::EpiIntegration::new(
&glutin_ctx
.window(ViewportId::MAIN)
.window(ViewportId::ROOT)
.borrow()
.window
.as_ref()
Expand Down Expand Up @@ -1017,7 +1017,7 @@ mod glow_integration {
#[cfg(feature = "accesskit")]
{
let event_loop_proxy = self.repaint_proxy.lock().clone();
let window = &glutin_ctx.viewports[&ViewportId::MAIN];
let window = &glutin_ctx.viewports[&ViewportId::ROOT];
let window = &mut *window.borrow_mut();
integration.init_accesskit(
window.egui_winit.as_mut().unwrap(),
Expand All @@ -1030,7 +1030,7 @@ mod glow_integration {

if self.native_options.mouse_passthrough {
glutin_ctx
.window(ViewportId::MAIN)
.window(ViewportId::ROOT)
.borrow()
.window
.as_ref()
Expand All @@ -1044,7 +1044,7 @@ mod glow_integration {
.expect("Single-use AppCreator has unexpectedly already been taken");
let mut app;
{
let window = glutin_ctx.window(ViewportId::MAIN);
let window = glutin_ctx.window(ViewportId::ROOT);
let window = &mut *window.borrow_mut();
app = app_creator(&epi::CreationContext {
egui_ctx: integration.egui_ctx.clone(),
Expand Down Expand Up @@ -1259,7 +1259,7 @@ mod glow_integration {
glutin_ctx: &Rc<RefCell<GlutinWindowContext>>,
mut viewports: Vec<ViewportOutput>,
) {
let mut active_viewports_ids = vec![ViewportId::MAIN];
let mut active_viewports_ids = vec![ViewportId::ROOT];

viewports.retain_mut(
|ViewportOutput {
Expand Down Expand Up @@ -1405,7 +1405,7 @@ mod glow_integration {
running
.glutin_ctx
.borrow()
.window(ViewportId::MAIN)
.window(ViewportId::ROOT)
.borrow()
.window
.as_ref()
Expand Down Expand Up @@ -1443,7 +1443,7 @@ mod glow_integration {
{
let glutin = glutin.borrow();
let viewport = &glutin.viewports[&viewport_id].clone();
if viewport.borrow().viewport_ui_cb.is_none() && viewport_id != ViewportId::MAIN
if viewport.borrow().viewport_ui_cb.is_none() && viewport_id != ViewportId::ROOT
{
if let Some(parent_viewport) =
glutin.viewports.get(&viewport.borrow().id_pair.parent)
Expand Down Expand Up @@ -1699,7 +1699,7 @@ mod glow_integration {
.glutin_ctx
.borrow()
.window_maps
.get(&ViewportId::MAIN)
.get(&ViewportId::ROOT)
.copied()
.unwrap(),
)
Expand Down Expand Up @@ -1784,7 +1784,7 @@ mod glow_integration {
.borrow()
.viewport_maps
.get(window_id)
.map_or(false, |id| *id == ViewportId::MAIN)
.map_or(false, |id| *id == ViewportId::ROOT)
&& running.integration.borrow().should_close() =>
{
log::debug!("Received WindowEvent::CloseRequested");
Expand Down Expand Up @@ -1967,7 +1967,7 @@ mod wgpu_integration {
native_options,
running: None,
app_creator: Some(app_creator),
is_focused: Rc::new(RefCell::new(Some(ViewportId::MAIN))),
is_focused: Rc::new(RefCell::new(Some(ViewportId::ROOT))),
}
}

Expand Down Expand Up @@ -2065,12 +2065,12 @@ mod wgpu_integration {
#[cfg(target_os = "android")]
fn drop_window(&mut self) -> std::result::Result<(), egui_wgpu::WgpuError> {
if let Some(running) = &mut self.running {
running.viewports.borrow_mut().remove(&ViewportId::MAIN);
running.viewports.borrow_mut().remove(&ViewportId::ROOT);
pollster::block_on(
running
.painter
.borrow_mut()
.set_window(ViewportId::MAIN, None),
.set_window(ViewportId::ROOT, None),
)?;
}
Ok(())
Expand All @@ -2095,7 +2095,7 @@ mod wgpu_integration {
),
self.native_options.transparent,
);
pollster::block_on(painter.set_window(ViewportId::MAIN, Some(&window)))?;
pollster::block_on(painter.set_window(ViewportId::ROOT, Some(&window)))?;

let wgpu_render_state = painter.render_state();

Expand Down Expand Up @@ -2164,22 +2164,22 @@ mod wgpu_integration {
}

let mut viewport_maps = HashMap::default();
viewport_maps.insert(window.id(), ViewportId::MAIN);
viewport_maps.insert(window.id(), ViewportId::ROOT);
let viewport_maps = Rc::new(RefCell::new(viewport_maps));

let viewports = Rc::new(RefCell::new(Viewports::default()));
viewports.borrow_mut().insert(
ViewportId::MAIN,
ViewportId::ROOT,
Viewport {
window: Some(Rc::new(RefCell::new(window))),
state: Rc::new(RefCell::new(Some(state))),
viewport_ui_cb: None,
parent_id: ViewportId::MAIN,
parent_id: ViewportId::ROOT,
},
);

let builders = Rc::new(RefCell::new(ViewportMap::default()));
builders.borrow_mut().insert(ViewportId::MAIN, builder);
builders.borrow_mut().insert(ViewportId::ROOT, builder);

let painter = Rc::new(RefCell::new(painter));

Expand Down Expand Up @@ -2385,7 +2385,7 @@ mod wgpu_integration {
if let Some(mut running) = self.running.take() {
crate::profile_function!();
if let Some(Viewport { window, .. }) =
running.viewports.borrow().get(&ViewportId::MAIN)
running.viewports.borrow().get(&ViewportId::ROOT)
{
running.integration.borrow_mut().save(
running.app.as_mut(),
Expand Down Expand Up @@ -2443,7 +2443,7 @@ mod wgpu_integration {
return EventResult::Wait;
};
// This is used to not render a viewport if is sync
if viewport_id != ViewportId::MAIN && viewport_ui_cb.is_none() {
if viewport_id != ViewportId::ROOT && viewport_ui_cb.is_none() {
if let Some(viewport) = running.viewports.borrow().get(&parent_id) {
if let Some(window) = viewport.window.as_ref() {
return EventResult::RepaintNext(window.borrow().id());
Expand Down Expand Up @@ -2512,7 +2512,7 @@ mod wgpu_integration {
integration.post_present(&window.borrow());
}

let mut active_viewports_ids = vec![ViewportId::MAIN];
let mut active_viewports_ids = vec![ViewportId::ROOT];

out_viewports.retain_mut(
|ViewportOutput {
Expand Down Expand Up @@ -2624,14 +2624,14 @@ mod wgpu_integration {
Ok(match event {
winit::event::Event::Resumed => {
if let Some(running) = &self.running {
if running.viewports.borrow().get(&ViewportId::MAIN).is_none() {
if running.viewports.borrow().get(&ViewportId::ROOT).is_none() {
let _ = Self::create_window(
event_loop,
running.integration.borrow().frame.storage(),
&self.app_name,
&mut self.native_options,
)?;
self.set_window(ViewportId::MAIN)?;
self.set_window(ViewportId::ROOT)?;
}
} else {
let storage = epi_integration::create_storage(
Expand All @@ -2654,7 +2654,7 @@ mod wgpu_integration {
.unwrap()
.viewports
.borrow()
.get(&ViewportId::MAIN)
.get(&ViewportId::ROOT)
.unwrap()
.window
.as_ref()
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/web/app_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl AppRunner {

let full_output = self
.egui_ctx
.run(raw_input, ViewportIdPair::MAIN, |egui_ctx| {
.run(raw_input, ViewportIdPair::ROOT, |egui_ctx| {
self.app.update(egui_ctx, &mut self.frame);
});
let egui::FullOutput {
Expand All @@ -195,7 +195,7 @@ impl AppRunner {

self.handle_platform_output(platform_output);
self.textures_delta.append(textures_delta);
let clipped_primitives = self.egui_ctx.tessellate(shapes, ViewportId::MAIN);
let clipped_primitives = self.egui_ctx.tessellate(shapes, ViewportId::ROOT);

{
let app_output = self.frame.take_app_output();
Expand Down
Loading

0 comments on commit a52d383

Please sign in to comment.