Skip to content

Commit

Permalink
Rename force_embedding -> embed_viewports
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Nov 7, 2023
1 parent 1ddfe07 commit a85adf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
20 changes: 10 additions & 10 deletions crates/egui/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct ContextImpl {
viewport_commands: Vec<(ViewportId, ViewportCommand)>,

is_desktop: bool,
force_embedding: bool,
embed_viewports: bool,

/// Written to during the frame.
layer_rects_this_frame: ViewportMap<HashMap<LayerId, Vec<(Id, Rect)>>>,
Expand Down Expand Up @@ -428,7 +428,7 @@ impl Default for Context {
let s = Self(Arc::new(RwLock::new(ContextImpl::default())));

s.write(|ctx| {
ctx.force_embedding = true;
ctx.embed_viewports = true;
});

s
Expand Down Expand Up @@ -510,7 +510,7 @@ impl Context {
let context = Context::default();
context.write(|ctx| {
ctx.is_desktop = desktop;
ctx.force_embedding = !desktop;
ctx.embed_viewports = !desktop;
});
context
}
Expand Down Expand Up @@ -2531,14 +2531,14 @@ impl Context {
}

/// If this is true no other native window will be created, when a viewport is created!
pub fn force_embedding(&self) -> bool {
self.read(|ctx| ctx.force_embedding)
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
pub fn set_force_embedding(&self, value: bool) {
self.write(|ctx| ctx.force_embedding = value || !ctx.is_desktop);
pub fn set_embed_viewports(&self, value: bool) {
self.write(|ctx| ctx.embed_viewports = value || !ctx.is_desktop);
}

/// Send a command to the current viewport.
Expand Down Expand Up @@ -2568,7 +2568,7 @@ impl Context {
viewport_builder: ViewportBuilder,
viewport_ui_cb: impl Fn(&Context) + Send + Sync + 'static,
) {
if self.force_embedding() {
if self.embed_viewports() {
viewport_ui_cb(self);
} else {
self.write(|ctx| {
Expand Down Expand Up @@ -2601,7 +2601,7 @@ impl Context {
/// The given ui function will be called immediately.
/// This can only be called from the main thread.
///
/// If [`Context::force_embedding`] is true, or if the current egui
/// If [`Context::embed_viewports`] is true, or if the current egui
/// backend does not support sync viewports, the given callback
/// will be called immediately and the function will return.
///
Expand All @@ -2621,7 +2621,7 @@ impl Context {
viewport_builder: ViewportBuilder,
viewport_ui_cb: impl FnOnce(&Context) -> T,
) -> T {
if self.force_embedding() {
if self.embed_viewports() {
return viewport_ui_cb(self);
}

Expand Down
6 changes: 3 additions & 3 deletions examples/test_viewports/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ impl eframe::App for App {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Root viewport");
{
let mut force_embedding = ctx.force_embedding();
ui.checkbox(&mut force_embedding, "Force embedding of new viewprts");
ctx.set_force_embedding(force_embedding);
let mut embed_viewports = ctx.embed_viewports();
ui.checkbox(&mut embed_viewports, "Embed all viewports");
ctx.set_embed_viewports(embed_viewports);
}

generic_ui(ui, &self.top);
Expand Down

0 comments on commit a85adf5

Please sign in to comment.