1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 07:03:14 -04:00

Make example more complex

This commit is contained in:
Konkitoman
2023-08-23 08:11:31 +03:00
parent dadcd508c9
commit 3cf9c1c4b1

View File

@@ -22,6 +22,12 @@ pub struct App {
sync_viewport_state: usize,
async_window_state: Arc<RwLock<usize>>,
sync_window_state: usize,
show_async_viewport2: Arc<RwLock<bool>>,
show_sync_viewport2: Arc<RwLock<bool>>,
async_viewport_state2: Arc<RwLock<usize>>,
sync_viewport_state2: Arc<RwLock<usize>>,
}
impl eframe::App for App {
@@ -62,11 +68,25 @@ impl eframe::App for App {
// Showing Async Viewport
if self.show_async_viewport {
let state = self.async_viewport_state.clone();
let show_async_viewport2 = self.show_async_viewport2.clone();
let show_sync_viewport2 = self.show_sync_viewport2.clone();
let async_viewport_state2 = self.async_viewport_state2.clone();
let sync_viewport_state2 = self.sync_viewport_state2.clone();
ctx.create_viewport(
ViewportBuilder::new("Async Viewport").with_title("Async Viewport"),
move |ctx| {
let mut state = state.write().unwrap();
let content = |ui: &mut egui::Ui| {
let mut show_async_viewport2 = show_async_viewport2.write().unwrap();
let mut show_sync_viewport2 = show_sync_viewport2.write().unwrap();
let async_viewport_state2 = async_viewport_state2.clone();
let sync_viewport_state2 = sync_viewport_state2.clone();
let content = move |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!("Current Viewport Id: {}", ctx.get_viewport_id()));
ui.label(format!(
@@ -75,10 +95,94 @@ impl eframe::App for App {
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.checkbox(&mut show_async_viewport2, "Show Async Viewport 2");
ui.checkbox(&mut show_sync_viewport2, "Show Sync Viewport 2");
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
if *show_async_viewport2 {
ctx.create_viewport(
ViewportBuilder::new("Async Viewport in Async Viewport")
.with_title("Async Viewport in Async Viewport"),
move |ctx| {
let mut state = async_viewport_state2.write().unwrap();
let content = move |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!(
"Current Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!(
"Current Parent Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
};
// This will make the viewport content, a popup if is in the main window
if ctx.get_viewport_id() == ViewportId::MAIN {
egui::Area::new("Async Viewport in Async Viewport")
.show(ctx, |ui| {
egui::Frame::popup(ui.style())
.show(ui, content);
});
} else {
egui::CentralPanel::default().show(ctx, content);
};
},
);
}
if *show_sync_viewport2 {
ctx.create_viewport_sync(
ViewportBuilder::new("Sync Viewport in Async Viewport")
.with_title("Sync Viewport in Async Viewport"),
move |ctx| {
let mut state = sync_viewport_state2.write().unwrap();
let content = move |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!(
"Current Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!(
"Current Parent Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
};
// This will make the viewport content, a popup if is in the main window
if ctx.get_viewport_id() == ViewportId::MAIN {
egui::Area::new("Sync Viewport in Async Viewport")
.show(ctx, |ui| {
egui::Frame::popup(ui.style())
.show(ui, content);
});
} else {
egui::CentralPanel::default().show(ctx, content);
};
},
);
}
};
// This will make the viewport content, a popup if is in the main window
@@ -98,6 +202,12 @@ impl eframe::App for App {
ctx.create_viewport_sync(
ViewportBuilder::new("Sync Viewport").with_title("Sync Viewport"),
|ctx| {
let mut show_async_viewport2 = self.show_async_viewport2.write().unwrap();
let mut show_sync_viewport2 = self.show_sync_viewport2.write().unwrap();
let async_viewport_state2 = self.async_viewport_state2.clone();
let sync_viewport_state2 = self.sync_viewport_state2.clone();
let content = |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!("Current Viewport Id: {}", ctx.get_viewport_id()));
@@ -107,10 +217,96 @@ impl eframe::App for App {
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.checkbox(&mut show_async_viewport2, "Show Async Viewport");
ui.checkbox(&mut show_sync_viewport2, "Show Sync Viewport");
ui.label(format!("Count: {}", self.sync_viewport_state));
if ui.button("Add").clicked() {
self.sync_viewport_state += 1;
}
if *show_async_viewport2 {
ctx.create_viewport(
ViewportBuilder::new("Async Viewport in Sync Viewport")
.with_title("Async Viewport in Sync Viewport"),
move |ctx| {
let mut state = async_viewport_state2.write().unwrap();
let content = move |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!(
"Current Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!(
"Current Parent Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
};
// This will make the viewport content, a popup if is in the main window
if ctx.get_viewport_id() == ViewportId::MAIN {
egui::Area::new("Async Viewport in Sync Viewport")
.show(ctx, |ui| {
egui::Frame::popup(ui.style())
.show(ui, content);
});
} else {
egui::CentralPanel::default().show(ctx, content);
};
},
);
}
if *show_sync_viewport2 {
ctx.create_viewport_sync(
ViewportBuilder::new("Sync Viewport in Sync Viewport")
.with_title("Sync Viewport in Sync Viewport"),
move |ctx| {
let mut state = sync_viewport_state2.write().unwrap();
let content = move |ui: &mut egui::Ui| {
ui.label(format!("Frame: {}", ctx.frame_nr()));
ui.label(format!(
"Current Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!(
"Current Parent Viewport Id: {}",
ctx.get_viewport_id()
));
ui.label(format!("Pos: {:?}", ctx.screen_rect().min));
ui.label(format!("Size: {:?}", ctx.screen_rect().max));
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
};
// This will make the viewport content, a popup if is in the main window
if ctx.get_viewport_id() == ViewportId::MAIN {
egui::Area::new("Sync Viewport in Sync Viewport").show(
ctx,
|ui| {
egui::Frame::popup(ui.style())
.show(ui, content);
},
);
} else {
egui::CentralPanel::default().show(ctx, content);
};
},
);
}
};
// This will make the viewport content, a popup if is in the main window