Browse Source

Rename `show_viewport` to `show_viewport_deferred`

Let's be explicit
pull/3575/head
Emil Ernerfeldt 12 months ago
parent
commit
74862bd129
  1. 2
      crates/eframe/src/epi.rs
  2. 2
      crates/egui/src/containers/window.rs
  3. 12
      crates/egui/src/context.rs
  4. 6
      crates/egui/src/viewport.rs
  5. 2
      examples/test_viewports/src/main.rs

2
crates/eframe/src/epi.rs

@ -116,7 +116,7 @@ pub trait App {
/// To force a repaint, call [`egui::Context::request_repaint`] at any time (e.g. from another thread).
///
/// This is called for the root viewport ([`egui::ViewportId::ROOT`]).
/// Use [`egui::Context::show_viewport`] to spawn additional viewports (windows).
/// Use [`egui::Context::show_viewport_deferred`] to spawn additional viewports (windows).
/// (A "viewport" in egui means an native OS window).
fn update(&mut self, ctx: &egui::Context, frame: &mut Frame);

2
crates/egui/src/containers/window.rs

@ -26,7 +26,7 @@ use super::*;
/// The previous rectangle used by this window can be obtained through [`crate::Memory::area_rect()`].
///
/// Note that this is NOT a native OS window.
/// To create a new native OS window, use [`crate::Context::show_viewport`].
/// To create a new native OS window, use [`crate::Context::show_viewport_deferred`].
#[must_use = "You should call .show()"]
pub struct Window<'open> {
title: WidgetText,

12
crates/egui/src/context.rs

@ -2536,7 +2536,7 @@ impl Context {
});
}
/// If `true`, [`Self::show_viewport`] and [`Self::show_viewport_immediate`] will
/// If `true`, [`Self::show_viewport_deferred`] and [`Self::show_viewport_immediate`] will
/// embed the new viewports inside the existing one, instead of spawning a new native window.
///
/// `eframe` sets this to `false` on supported platforms, but the default value is `true`.
@ -2544,7 +2544,7 @@ impl Context {
self.read(|ctx| ctx.embed_viewports)
}
/// If `true`, [`Self::show_viewport`] and [`Self::show_viewport_immediate`] will
/// If `true`, [`Self::show_viewport_deferred`] and [`Self::show_viewport_immediate`] will
/// embed the new viewports inside the existing one, instead of spawning a new native window.
///
/// `eframe` sets this to `false` on supported platforms, but the default value is `true`.
@ -2567,7 +2567,7 @@ impl Context {
self.request_repaint_of(id);
}
/// This creates a new native window, if possible.
/// Show a deferred viewport, creating a new native window, if possible.
///
/// The given id must be unique for each viewport.
///
@ -2596,7 +2596,7 @@ impl Context {
/// If you find [`ViewportClass::Embedded`], you need to create a new [`crate::Window`] for you content.
///
/// See [`crate::viewport`] for more information about viewports.
pub fn show_viewport(
pub fn show_viewport_deferred(
&self,
new_viewport_id: ViewportId,
viewport_builder: ViewportBuilder,
@ -2622,12 +2622,12 @@ impl Context {
}
}
/// This creates a new native window, if possible.
/// Show an immediate viewport, creating a new native window, if possible.
///
/// This is the easier type of viewport to use, but it is less performant
/// at it requires both parent and child to repaint if any one of them needs repainting,
/// which efficvely produce double work for two viewports, and triple work for three viewports, etc.
/// To avoid this, use [`Self::show_viewport`] instead.
/// To avoid this, use [`Self::show_viewport_deferred`] instead.
///
/// The given id must be unique for each viewport.
///

6
crates/egui/src/viewport.rs

@ -3,7 +3,7 @@
//! Not all egui backends support multiple viewports, but `eframe` native does
//! (but not on web).
//!
//! You can spawn a new viewport using [`Context::show_viewport`] and [`Context::show_viewport_immediate`].
//! You can spawn a new viewport using [`Context::show_viewport_deferred`] and [`Context::show_viewport_immediate`].
//! These needs to be called every frame the viewport should be visible.
//!
//! This is implemented by the native `eframe` backend, but not the web one.
@ -17,7 +17,7 @@
//! The root viewport is the original viewport, and cannot be closed without closing the application.
//!
//! ### Deferred viewports
//! These are created with [`Context::show_viewport`].
//! These are created with [`Context::show_viewport_deferred`].
//! Deferred viewports take a closure that is called by the integration at a later time, perhaps multiple times.
//! Deferred viewports are repainted independenantly of the parent viewport.
//! This means communication with them need to done via channels, or `Arc/Mutex`.
@ -87,7 +87,7 @@ pub enum ViewportClass {
///
/// This is the preferred type of viewport from a performance perspective.
///
/// Create these with [`crate::Context::show_viewport`].
/// Create these with [`crate::Context::show_viewport_deferred`].
Deferred,
/// A viewport run inside the parent viewport.

2
examples/test_viewports/src/main.rs

@ -79,7 +79,7 @@ impl ViewportState {
});
} else {
let count = Arc::new(RwLock::new(0));
ctx.show_viewport(vp_id, viewport, move |ctx, class| {
ctx.show_viewport_deferred(vp_id, viewport, move |ctx, class| {
let mut vp_state = vp_state.write();
let count = count.clone();
show_as_popup(

Loading…
Cancel
Save