Skip to content

Commit

Permalink
Remove Context::is_desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 7, 2023
1 parent a85adf5 commit 6643713
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
5 changes: 3 additions & 2 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,12 @@ impl EpiIntegration {
app_name: &str,
native_options: &crate::NativeOptions,
storage: Option<Box<dyn epi::Storage>>,
desktop: bool,
is_desktop: bool,
#[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>,
#[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>,
) -> Self {
let egui_ctx = egui::Context::new(desktop);
let egui_ctx = egui::Context::default();
egui_ctx.set_embed_viewports(!is_desktop);

let memory = load_egui_memory(storage.as_deref()).unwrap_or_default();
egui_ctx.memory_mut(|mem| *mem = memory);
Expand Down
31 changes: 11 additions & 20 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ struct ContextImpl {
viewports: ViewportMap<Viewport>,
viewport_commands: Vec<(ViewportId, ViewportCommand)>,

is_desktop: bool,
embed_viewports: bool,

/// Written to during the frame.
Expand Down Expand Up @@ -504,16 +503,6 @@ impl Context {

self.write(|ctx| ctx.begin_frame_mut(new_input, id_pair));
}

/// Create a new Context and specify if is desktop
pub fn new(desktop: bool) -> Context {
let context = Context::default();
context.write(|ctx| {
ctx.is_desktop = desktop;
ctx.embed_viewports = !desktop;
});
context
}
}

/// ## Borrows parts of [`Context`]
Expand Down Expand Up @@ -2525,20 +2514,22 @@ impl Context {
});
}

/// This will tell you if is possible to open a native window
pub fn is_desktop(&self) -> bool {
self.read(|ctx| ctx.is_desktop)
}

/// If this is true no other native window will be created, when a viewport is created!
/// If `true`, [`Self::create_viewport_async`] and [`Self::create_viewport_sync`] will
/// embed the new viewports as [`egui::Window`]s instead of spawning a new native window.
///
/// `eframe` sets this to `false` on supported platforms,
/// but the default value is `true`.
pub fn embed_viewports(&self) -> bool {
self.read(|ctx| ctx.embed_viewports)
}

/// If this is true no other native window will be created, when a viewport is created!
/// You will always be able to set to true
/// If `true`, [`Self::create_viewport_async`] and [`Self::create_viewport_sync`] will
/// embed the new viewports as [`egui::Window`]s instead of spawning a new native window.
///
/// `eframe` sets this to `false` on supported platforms,
/// but the default value is `true`.
pub fn set_embed_viewports(&self, value: bool) {
self.write(|ctx| ctx.embed_viewports = value || !ctx.is_desktop);
self.write(|ctx| ctx.embed_viewports = value);
}

/// Send a command to the current viewport.
Expand Down

0 comments on commit 6643713

Please sign in to comment.