1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 14:20:04 -04:00

Remove Context::is_desktop

This commit is contained in:
Emil Ernerfeldt
2023-11-07 09:30:00 +01:00
parent a85adf59b2
commit 6643713cc0
2 changed files with 14 additions and 22 deletions

View File

@@ -338,11 +338,12 @@ impl EpiIntegration {
app_name: &str, app_name: &str,
native_options: &crate::NativeOptions, native_options: &crate::NativeOptions,
storage: Option<Box<dyn epi::Storage>>, storage: Option<Box<dyn epi::Storage>>,
desktop: bool, is_desktop: bool,
#[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>, #[cfg(feature = "glow")] gl: Option<std::sync::Arc<glow::Context>>,
#[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>, #[cfg(feature = "wgpu")] wgpu_render_state: Option<egui_wgpu::RenderState>,
) -> Self { ) -> 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(); let memory = load_egui_memory(storage.as_deref()).unwrap_or_default();
egui_ctx.memory_mut(|mem| *mem = memory); egui_ctx.memory_mut(|mem| *mem = memory);

View File

@@ -173,7 +173,6 @@ struct ContextImpl {
viewports: ViewportMap<Viewport>, viewports: ViewportMap<Viewport>,
viewport_commands: Vec<(ViewportId, ViewportCommand)>, viewport_commands: Vec<(ViewportId, ViewportCommand)>,
is_desktop: bool,
embed_viewports: bool, embed_viewports: bool,
/// Written to during the frame. /// Written to during the frame.
@@ -504,16 +503,6 @@ impl Context {
self.write(|ctx| ctx.begin_frame_mut(new_input, id_pair)); 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`] /// ## Borrows parts of [`Context`]
@@ -2525,20 +2514,22 @@ impl Context {
}); });
} }
/// This will tell you if is possible to open a native window /// If `true`, [`Self::create_viewport_async`] and [`Self::create_viewport_sync`] will
pub fn is_desktop(&self) -> bool { /// embed the new viewports as [`egui::Window`]s instead of spawning a new native window.
self.read(|ctx| ctx.is_desktop) ///
} /// `eframe` sets this to `false` on supported platforms,
/// but the default value is `true`.
/// If this is true no other native window will be created, when a viewport is created!
pub fn embed_viewports(&self) -> bool { pub fn embed_viewports(&self) -> bool {
self.read(|ctx| ctx.embed_viewports) self.read(|ctx| ctx.embed_viewports)
} }
/// 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
/// You will always be able to set to true /// 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) { 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. /// Send a command to the current viewport.