1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00

A lot of changes:

Now the Viewport render function is passed to the backend
I was needed to update the demo because now Window::show() needs a Fn before was a FnOnce
I changed from FnOnce to Fn because we want the window to be rendered separately from the main window
That means now the variabiles that we are moving to window need to be Rc or Arc!
This is making harder to use `Window`!
I'am waiting for more ideas!
In eframe now any Window has a property render that stores the current window render function, if has not function App::update will be called insted!
New problems in any other window excluding the main window we have no mouse input, i don't know why!
Now every window has embedded to false by default, for testing purposes!
This commit is contained in:
Konkitoman
2023-07-23 19:38:02 +03:00
parent fdca2b9220
commit 3a1d9f2e21
32 changed files with 971 additions and 645 deletions

View File

@@ -1,3 +1,5 @@
use std::sync::{Arc, RwLock};
/// How often we repaint the demo app by default
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
enum RunMode {
@@ -353,7 +355,7 @@ struct EguiWindows {
output_events: bool,
#[cfg_attr(feature = "serde", serde(skip))]
output_event_history: std::collections::VecDeque<egui::output::OutputEvent>,
output_event_history: Arc<RwLock<std::collections::VecDeque<egui::output::OutputEvent>>>,
}
impl Default for EguiWindows {
@@ -397,41 +399,48 @@ impl EguiWindows {
output_event_history,
} = self;
ctx.output(|o| {
for event in &o.events {
output_event_history.push_back(event.clone());
{
let mut output_event_history = output_event_history.write().unwrap();
ctx.output(|o| {
for event in &o.events {
output_event_history.push_back(event.clone());
}
});
while output_event_history.len() > 1000 {
output_event_history.pop_front();
}
});
while output_event_history.len() > 1000 {
output_event_history.pop_front();
}
let tmp_ctx = ctx.clone();
egui::Window::new("🔧 Settings")
.open(settings)
.vscroll(true)
.show(ctx, |ui| {
ctx.settings_ui(ui);
.show(ctx, move |ui| {
tmp_ctx.settings_ui(ui);
});
let tmp_ctx = ctx.clone();
egui::Window::new("🔍 Inspection")
.open(inspection)
.vscroll(true)
.show(ctx, |ui| {
ctx.inspection_ui(ui);
.show(ctx, move |ui| {
tmp_ctx.inspection_ui(ui);
});
let tmp_ctx = ctx.clone();
egui::Window::new("📝 Memory")
.open(memory)
.resizable(false)
.show(ctx, |ui| {
ctx.memory_ui(ui);
.show(ctx, move |ui| {
tmp_ctx.memory_ui(ui);
});
let tmp_output_event_history = output_event_history.clone();
egui::Window::new("📤 Output Events")
.open(output_events)
.resizable(true)
.default_width(520.0)
.show(ctx, |ui| {
.show(ctx, move |ui| {
ui.label(
"Recent output events from egui. \
These are emitted when you interact with widgets, or move focus between them with TAB. \
@@ -443,7 +452,7 @@ impl EguiWindows {
egui::ScrollArea::vertical()
.stick_to_bottom(true)
.show(ui, |ui| {
for event in output_event_history {
for event in &*tmp_output_event_history.read().unwrap() {
ui.label(format!("{:?}", event));
}
});

View File

@@ -5,6 +5,7 @@ use eframe::glow;
#[cfg(target_arch = "wasm32")]
use core::any::Any;
use std::sync::{Arc, RwLock};
#[derive(Default)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
@@ -147,7 +148,7 @@ pub struct WrapApp {
#[cfg(any(feature = "glow", feature = "wgpu"))]
custom3d: Option<crate::apps::Custom3d>,
dropped_files: Vec<egui::DroppedFile>,
dropped_files: Arc<RwLock<Vec<egui::DroppedFile>>>,
}
impl WrapApp {
@@ -412,17 +413,20 @@ impl WrapApp {
// Collect dropped files:
ctx.input(|i| {
if !i.raw.dropped_files.is_empty() {
self.dropped_files = i.raw.dropped_files.clone();
*self.dropped_files.write().unwrap() = i.raw.dropped_files.clone();
}
});
// Show dropped files (if any):
if !self.dropped_files.is_empty() {
let is_empty = self.dropped_files.read().unwrap().is_empty();
if !is_empty {
let mut open = true;
let dropped_files = self.dropped_files.clone();
egui::Window::new("Dropped files")
.open(&mut open)
.show(ctx, |ui| {
for file in &self.dropped_files {
.show(ctx, move |ui| {
let dropped_files = &*dropped_files.read().unwrap();
for file in dropped_files {
let mut info = if let Some(path) = &file.path {
path.display().to_string()
} else if !file.name.is_empty() {
@@ -437,7 +441,7 @@ impl WrapApp {
}
});
if !open {
self.dropped_files.clear();
self.dropped_files.write().unwrap().clear();
}
}
}