mirror of
https://github.com/emilk/egui.git
synced 2026-06-27 15:13:12 -04:00
Now viewports will be identified by there id a normal egui::Id
Before viewports was identified by there title
This commit is contained in:
@@ -90,7 +90,7 @@ pub fn window_builder<E>(
|
||||
..
|
||||
} = native_options;
|
||||
|
||||
let mut window_builder = ViewportBuilder::default()
|
||||
let mut window_builder = ViewportBuilder::new("")
|
||||
.with_title(title)
|
||||
.with_decorations(*decorated)
|
||||
.with_fullscreen(*fullscreen)
|
||||
|
||||
@@ -48,7 +48,7 @@ impl<'open> Window<'open> {
|
||||
let title = title.into().fallback_text_style(TextStyle::Heading);
|
||||
let area = Area::new(Id::new(title.text()));
|
||||
Self {
|
||||
window_builder: ViewportBuilder::default().with_title(title.text()),
|
||||
window_builder: ViewportBuilder::new(title.text().to_owned()).with_title(title.text()),
|
||||
title,
|
||||
open: None,
|
||||
area,
|
||||
@@ -70,6 +70,7 @@ impl<'open> Window<'open> {
|
||||
/// Assign a unique id to the Window. Required if the title changes, or is shared with another window.
|
||||
pub fn id(mut self, id: Id) -> Self {
|
||||
self.area = self.area.id(id);
|
||||
self.window_builder.id = id;
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -197,7 +197,7 @@ struct ContextImpl {
|
||||
repaint: Repaint,
|
||||
|
||||
viewports: HashMap<
|
||||
String,
|
||||
Id,
|
||||
(
|
||||
ViewportBuilder,
|
||||
ViewportId,
|
||||
@@ -2189,12 +2189,12 @@ impl Context {
|
||||
self.read(|ctx| ctx.get_parent_viewport_id())
|
||||
}
|
||||
|
||||
pub fn get_viewport_id_by_name(&self, name: &str) -> Option<ViewportId> {
|
||||
self.read(|ctx| ctx.viewports.get(name).map(|v| v.1))
|
||||
pub fn get_viewport_id_by_id(&self, id: impl Into<Id>) -> Option<ViewportId> {
|
||||
self.read(|ctx| ctx.viewports.get(&id.into()).map(|v| v.1))
|
||||
}
|
||||
|
||||
pub fn get_viewport_parent_id_by_name(&self, name: &str) -> Option<ViewportId> {
|
||||
self.read(|ctx| ctx.viewports.get(name).map(|v| v.1))
|
||||
pub fn get_viewport_parent_id_by_id(&self, id: impl Into<Id>) -> Option<ViewportId> {
|
||||
self.read(|ctx| ctx.viewports.get(&id.into()).map(|v| v.1))
|
||||
}
|
||||
|
||||
/// This should only be used by the backend!
|
||||
@@ -2246,7 +2246,7 @@ impl Context {
|
||||
if !self.force_embedding() {
|
||||
self.write(|ctx| {
|
||||
let viewport_id = ctx.get_viewport_id();
|
||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.title) {
|
||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
||||
window.0 = viewport_builder;
|
||||
window.2 = viewport_id;
|
||||
window.3 = true;
|
||||
@@ -2255,7 +2255,7 @@ impl Context {
|
||||
let id = ViewportId(ctx.viewport_counter + 1);
|
||||
ctx.viewport_counter += 1;
|
||||
ctx.viewports.insert(
|
||||
viewport_builder.title.clone(),
|
||||
viewport_builder.id,
|
||||
(
|
||||
viewport_builder,
|
||||
id,
|
||||
@@ -2287,7 +2287,7 @@ impl Context {
|
||||
let mut parent_viewport_id = ViewportId::MAIN;
|
||||
let render_sync = self.write(|ctx| {
|
||||
viewport_id = ctx.get_viewport_id();
|
||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.title) {
|
||||
if let Some(window) = ctx.viewports.get_mut(&viewport_builder.id) {
|
||||
window.0 = viewport_builder.clone();
|
||||
window.2 = viewport_id;
|
||||
window.3 = true;
|
||||
@@ -2298,7 +2298,7 @@ impl Context {
|
||||
let id = ViewportId(ctx.viewport_counter + 1);
|
||||
ctx.viewport_counter += 1;
|
||||
ctx.viewports.insert(
|
||||
viewport_builder.title.clone(),
|
||||
viewport_builder.id,
|
||||
(viewport_builder.clone(), id, viewport_id, true, None),
|
||||
);
|
||||
viewport_id = id;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::{fmt::Display, sync::Arc};
|
||||
|
||||
use crate::Context;
|
||||
use crate::{Context, Id};
|
||||
|
||||
/// This is used to send a command to a specific viewport
|
||||
///
|
||||
@@ -26,6 +26,7 @@ pub type ViewportRender = dyn Fn(&Context) + Sync + Send;
|
||||
/// Every thing is wraped in Option<> indicates that thing should not be changed!
|
||||
#[derive(Hash, PartialEq, Eq, Clone)]
|
||||
pub struct ViewportBuilder {
|
||||
pub id: Id,
|
||||
pub title: String,
|
||||
pub name: Option<(String, String)>,
|
||||
pub position: Option<Option<(i32, i32)>>,
|
||||
@@ -53,10 +54,11 @@ pub struct ViewportBuilder {
|
||||
pub hittest: Option<bool>,
|
||||
}
|
||||
|
||||
impl Default for ViewportBuilder {
|
||||
fn default() -> Self {
|
||||
impl ViewportBuilder {
|
||||
pub fn new(id: impl Into<Id>) -> Self {
|
||||
Self {
|
||||
title: "Dummy EGUI Window".into(),
|
||||
id: id.into(),
|
||||
title: "Dummy egui viewport".into(),
|
||||
name: None,
|
||||
position: None,
|
||||
inner_size: Some(Some((300, 200))),
|
||||
@@ -84,9 +86,10 @@ impl Default for ViewportBuilder {
|
||||
}
|
||||
|
||||
impl ViewportBuilder {
|
||||
pub fn empty() -> Self {
|
||||
pub fn empty(id: impl Into<Id>) -> Self {
|
||||
Self {
|
||||
title: "Dummy EGUI Window".into(),
|
||||
id: id.into(),
|
||||
title: "Dummy egui viewport".into(),
|
||||
name: None,
|
||||
position: None,
|
||||
inner_size: None,
|
||||
|
||||
@@ -63,7 +63,7 @@ impl eframe::App for App {
|
||||
if self.show_async_viewport {
|
||||
let state = self.async_viewport_state.clone();
|
||||
ctx.create_viewport(
|
||||
ViewportBuilder::default().with_title("Async Viewport"),
|
||||
ViewportBuilder::new("Async Viewport").with_title("Async Viewport"),
|
||||
move |ctx| {
|
||||
let mut state = state.write().unwrap();
|
||||
let content = |ui: &mut egui::Ui| {
|
||||
@@ -96,7 +96,7 @@ impl eframe::App for App {
|
||||
// Showing Sync Viewport
|
||||
if self.show_sync_viewport {
|
||||
ctx.create_viewport_sync(
|
||||
ViewportBuilder::default().with_title("Sync Viewport"),
|
||||
ViewportBuilder::new("Sync Viewport").with_title("Sync Viewport"),
|
||||
|ctx| {
|
||||
let content = |ui: &mut egui::Ui| {
|
||||
ui.label(format!("Frame: {}", ctx.frame_nr()));
|
||||
|
||||
Reference in New Issue
Block a user