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