mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Misc code cleanup
This commit is contained in:
@@ -89,7 +89,7 @@ pub fn window_builder<E>(
|
||||
..
|
||||
} = native_options;
|
||||
|
||||
let mut window_builder = ViewportBuilder::new("")
|
||||
let mut window_builder = egui::ViewportBuilder::new("")
|
||||
.with_title(title)
|
||||
.with_decorations(*decorated)
|
||||
.with_fullscreen(*fullscreen)
|
||||
|
||||
@@ -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<dyn FnOnce(&Context) + 'a>);
|
||||
|
||||
/// 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<T>` 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<Option<Pos2>>,
|
||||
pub inner_size: Option<Option<Vec2>>,
|
||||
pub fullscreen: Option<bool>,
|
||||
|
||||
@@ -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<Id>) {
|
||||
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::<App>::default()),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user