mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 14:50:03 -04:00
Hide close-button for child viewports by default
This commit is contained in:
@@ -87,8 +87,9 @@ pub fn window_builder<E>(
|
|||||||
..
|
..
|
||||||
} = native_options;
|
} = native_options;
|
||||||
|
|
||||||
let mut window_builder = egui::ViewportBuilder::new("")
|
let mut window_builder = egui::ViewportBuilder::new(ViewportId::MAIN)
|
||||||
.with_title(title)
|
.with_title(title)
|
||||||
|
.with_close_button(true) // The default for all other viewports is `false`!
|
||||||
.with_decorations(*decorated)
|
.with_decorations(*decorated)
|
||||||
.with_fullscreen(*fullscreen)
|
.with_fullscreen(*fullscreen)
|
||||||
.with_maximized(*maximized)
|
.with_maximized(*maximized)
|
||||||
|
|||||||
@@ -34,6 +34,10 @@ impl std::fmt::Debug for ViewportId {
|
|||||||
impl ViewportId {
|
impl ViewportId {
|
||||||
/// This will return the `ViewportId` of the main viewport
|
/// This will return the `ViewportId` of the main viewport
|
||||||
pub const MAIN: Self = Self(Id::null());
|
pub const MAIN: Self = Self(Id::null());
|
||||||
|
|
||||||
|
pub fn from_hash_of(source: impl std::hash::Hash) -> Self {
|
||||||
|
Self(Id::new(source))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This will deref to [`Self::this`].
|
/// This will deref to [`Self::this`].
|
||||||
@@ -69,10 +73,12 @@ pub type ViewportRenderSyncCallback =
|
|||||||
|
|
||||||
/// Control the building of a new egui viewport (i.e. native window).
|
/// 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,
|
/// The fields are public, but you should use the builder pattern to set them,
|
||||||
/// and thats' where you'll find the documentation too.
|
/// and that's where you'll find the documentation too.
|
||||||
///
|
///
|
||||||
/// Every thing is wrapped in `Option<T>` indicates that nothing changed from the last `ViewportBuilder`!
|
/// Since egui is immediate mode, `ViewportBuilder` is accumulative in nature.
|
||||||
|
/// Setting any option to `None` means "keep the current value",
|
||||||
|
/// or "Use the default" if it is the first call.
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
#[allow(clippy::option_option)]
|
#[allow(clippy::option_option)]
|
||||||
pub struct ViewportBuilder {
|
pub struct ViewportBuilder {
|
||||||
@@ -110,9 +116,12 @@ pub struct ViewportBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ViewportBuilder {
|
impl ViewportBuilder {
|
||||||
pub fn new(id: impl Into<Id>) -> Self {
|
/// Default settings for a new child viewport.
|
||||||
|
///
|
||||||
|
/// The given id must be unique for each viewport.
|
||||||
|
pub fn new(id: ViewportId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: ViewportId(id.into()),
|
id,
|
||||||
title: "egui".into(),
|
title: "egui".into(),
|
||||||
name: None,
|
name: None,
|
||||||
position: None,
|
position: None,
|
||||||
@@ -131,16 +140,22 @@ impl ViewportBuilder {
|
|||||||
min_inner_size: None,
|
min_inner_size: None,
|
||||||
max_inner_size: None,
|
max_inner_size: None,
|
||||||
drag_and_drop: Some(true),
|
drag_and_drop: Some(true),
|
||||||
close_button: Some(true),
|
close_button: Some(false), // We disable the close button by default because we haven't implemented closing of child viewports yet
|
||||||
minimize_button: Some(true),
|
minimize_button: Some(true),
|
||||||
maximize_button: Some(true),
|
maximize_button: Some(true),
|
||||||
hittest: Some(true),
|
hittest: Some(true),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn empty(id: impl Into<Id>) -> Self {
|
/// Empty settings for everything.
|
||||||
|
///
|
||||||
|
/// If used the first frame, backend-specific defaults will be used.
|
||||||
|
/// When used on subsequent frames, the current settings will be kept.
|
||||||
|
///
|
||||||
|
/// The given id must be unique for each viewport.
|
||||||
|
pub fn empty(id: ViewportId) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id: ViewportId(id.into()),
|
id,
|
||||||
title: "egui".into(),
|
title: "egui".into(),
|
||||||
name: None,
|
name: None,
|
||||||
position: None,
|
position: None,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{mutex::RwLock, Id, InnerResponse, ViewportBuilder};
|
use egui::{mutex::RwLock, Id, InnerResponse, ViewportBuilder, ViewportId};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
@@ -139,7 +139,7 @@ fn show_async_viewport(
|
|||||||
let name: String = name.into();
|
let name: String = name.into();
|
||||||
|
|
||||||
ctx.create_viewport_async(
|
ctx.create_viewport_async(
|
||||||
ViewportBuilder::new(name.clone())
|
ViewportBuilder::new(ViewportId::from_hash_of(&name))
|
||||||
.with_title(name.as_str())
|
.with_title(name.as_str())
|
||||||
.with_inner_size(Some(egui::vec2(450.0, 350.0))),
|
.with_inner_size(Some(egui::vec2(450.0, 350.0))),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
@@ -192,7 +192,7 @@ fn show_sync_viewport(
|
|||||||
let name: String = name.into();
|
let name: String = name.into();
|
||||||
|
|
||||||
ctx.create_viewport_sync(
|
ctx.create_viewport_sync(
|
||||||
ViewportBuilder::new(name.clone())
|
ViewportBuilder::new(ViewportId::from_hash_of(&name))
|
||||||
.with_title(name.as_str())
|
.with_title(name.as_str())
|
||||||
.with_inner_size(Some(egui::vec2(450.0, 350.0))),
|
.with_inner_size(Some(egui::vec2(450.0, 350.0))),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
|
|||||||
Reference in New Issue
Block a user