From abc70ccf9c1217e418ca449ca272635c26c615c7 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 1 Nov 2023 18:19:19 +0100 Subject: [PATCH] Misc code cleanup --- crates/eframe/src/native/epi_integration.rs | 2 +- crates/egui/src/viewport.rs | 16 +++++++++++++--- examples/viewports/src/main.rs | 18 +++++++++--------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/crates/eframe/src/native/epi_integration.rs b/crates/eframe/src/native/epi_integration.rs index fafbc791d54..ef6ba61eb06 100644 --- a/crates/eframe/src/native/epi_integration.rs +++ b/crates/eframe/src/native/epi_integration.rs @@ -89,7 +89,7 @@ pub fn window_builder( .. } = native_options; - let mut window_builder = ViewportBuilder::new("") + let mut window_builder = egui::ViewportBuilder::new("") .with_title(title) .with_decorations(*decorated) .with_fullscreen(*fullscreen) diff --git a/crates/egui/src/viewport.rs b/crates/egui/src/viewport.rs index 1ea592268fd..cb8bac832c6 100644 --- a/crates/egui/src/viewport.rs +++ b/crates/egui/src/viewport.rs @@ -6,7 +6,7 @@ use crate::{Context, Id}; /// This is used to send a command to a specific viewport /// -/// This is returned by `Context::get_viewport_id` and `Context::get_parent_viewport_id` +/// This is returned by [`Context::get_viewport_id`] and [`Context::get_parent_viewport_id`]. #[derive(Default, Debug, Hash, Clone, Copy, PartialEq, Eq)] pub struct ViewportId(pub(crate) u64); @@ -21,7 +21,7 @@ impl ViewportId { pub const MAIN: Self = Self(0); } -/// This will deref to `ViewportIdPair::this` +/// This will deref to [`Self::this`]. #[derive(Default, Debug, Hash, Clone, Copy, PartialEq, Eq)] pub struct ViewportIdPair { pub this: ViewportId, @@ -54,14 +54,24 @@ pub type ViewportRender = dyn Fn(&Context) + Sync + Send; pub type ViewportRenderSyncCallback = dyn for<'a> Fn(&Context, ViewportBuilder, ViewportIdPair, Box); -/// The filds in this struct should not be change directly, but is not problem tho! +/// Control the building of a new egui viewport (i.e. native window). +/// +/// The fields are or public, but you use the builder pattern to set them, +/// and thats' where you'll find the documentation too. +/// /// Every thing is wrapped in `Option` indicates that nothing changed from the last `ViewportBuilder`! #[derive(PartialEq, Eq, Clone)] #[allow(clippy::option_option)] pub struct ViewportBuilder { pub id: Id, + + /// The title of the vieweport. + /// `eframe` will use this as the title of the native window. pub title: String, + + /// This is wayland only. See [`Self::with_name`]. pub name: Option<(String, String)>, + pub position: Option>, pub inner_size: Option>, pub fullscreen: Option, diff --git a/examples/viewports/src/main.rs b/examples/viewports/src/main.rs index 3e1539792a5..1338da1b3fd 100644 --- a/examples/viewports/src/main.rs +++ b/examples/viewports/src/main.rs @@ -1,9 +1,7 @@ -use egui::mutex::RwLock; use std::sync::Arc; -use eframe::egui::{self, InnerResponse}; -use eframe::egui::{Id, ViewportBuilder}; -use eframe::NativeOptions; +use eframe::egui; +use egui::{mutex::RwLock, Id, InnerResponse, ViewportBuilder}; #[derive(Default)] pub struct App { @@ -24,10 +22,9 @@ impl eframe::App for App { fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { egui::CentralPanel::default().show(ctx, |ui| { generic_ui(ui, "Central Panel"); - ui.label("Look at the \"Frame: \" will tell you, what viewport is rendering!"); { let mut force_embedding = ctx.force_embedding(); - ui.checkbox(&mut force_embedding, "Force embedding!"); + ui.checkbox(&mut force_embedding, "Force embedding of new viewprts"); ctx.set_force_embedding(force_embedding); } ui.checkbox(&mut self.show_async_viewport, "Show Async Viewport"); @@ -320,7 +317,10 @@ fn show_as_popup(ctx: &egui::Context, name: &str, content: impl FnOnce(&mut egui fn generic_ui(ui: &mut egui::Ui, container_id: impl Into) { let ctx = ui.ctx().clone(); - ui.label(format!("Frame: {}", ctx.frame_nr())); + ui.label(format!( + "Frame nr: {} (this increases when this viewport is beeing rendered)", + ctx.frame_nr() + )); ui.label(format!("Current Viewport Id: {}", ctx.viewport_id())); ui.label(format!("Current Parent Viewport Id: {}", ctx.viewport_id())); let inner_rect = ctx.inner_rect(); @@ -491,12 +491,12 @@ fn main() { let _ = eframe::run_native( "Viewports", - NativeOptions { + eframe::NativeOptions { #[cfg(feature = "wgpu")] renderer: eframe::Renderer::Wgpu, initial_window_size: Some(egui::Vec2::new(450.0, 320.0)), - ..NativeOptions::default() + ..Default::default() }, Box::new(|_| Box::::default()), );