Skip to content

Commit

Permalink
This PR has a smaller scope, and this are some reverts
Browse files Browse the repository at this point in the history
Will no longer change egui::Window!
  • Loading branch information
konkitoman committed Aug 31, 2023
1 parent c10a4cd commit 78a0ae8
Show file tree
Hide file tree
Showing 14 changed files with 610 additions and 1,256 deletions.
924 changes: 563 additions & 361 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/egui/src/containers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub mod panel;
pub mod popup;
pub(crate) mod resize;
pub mod scroll_area;
pub mod window;
pub(crate) mod window;

pub use {
area::Area,
Expand Down
1 change: 0 additions & 1 deletion crates/egui/src/containers/popup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ pub fn was_tooltip_open_last_frame(ctx: &Context, tooltip_id: Id) -> bool {
for (count, (individual_id, _size)) in &state.individual_ids_and_sizes {
if *individual_id == tooltip_id {
let area_id = common_id.with(count);

let layer_id = LayerId::new(Order::Tooltip, area_id);
if ctx.memory(|mem| mem.areas.visible_last_frame(&layer_id)) {
return true;
Expand Down
825 changes: 18 additions & 807 deletions crates/egui/src/containers/window.rs

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions crates/egui_demo_lib/src/demo/demo_app_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl Demos {
#[cfg_attr(feature = "serde", serde(default))]
struct Tests {
#[cfg_attr(feature = "serde", serde(skip))]
demos: Vec<Box<dyn Demo + Sync + Send>>,
demos: Vec<Box<dyn Demo>>,

open: BTreeSet<String>,
}
Expand All @@ -101,7 +101,7 @@ impl Default for Tests {
}

impl Tests {
pub fn from_demos(demos: Vec<Box<dyn Demo + Sync + Send>>) -> Self {
pub fn from_demos(demos: Vec<Box<dyn Demo>>) -> Self {
let mut open = BTreeSet::new();
open.insert(
super::widget_gallery::WidgetGallery::default()
Expand Down Expand Up @@ -146,7 +146,6 @@ fn set_open(open: &mut BTreeSet<String>, key: &'static str, is_open: bool) {
// ----------------------------------------------------------------------------

/// A menu bar in which you can select different demo windows to show.

#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct DemoWindows {
Expand Down
1 change: 1 addition & 0 deletions crates/egui_demo_lib/src/demo/drag_and_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn drop_target<R>(
InnerResponse::new(ret, response)
}

#[derive(Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub struct DragAndDropDemo {
/// columns with items
Expand Down
4 changes: 2 additions & 2 deletions crates/egui_demo_lib/src/demo/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ enum WidgetType {
TextEdit,
}

#[derive(Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq)]
pub struct ManualLayoutTest {
widget_offset: egui::Vec2,
widget_size: egui::Vec2,
Expand Down Expand Up @@ -133,7 +133,7 @@ impl super::View for ManualLayoutTest {
fn ui(&mut self, ui: &mut egui::Ui) {
egui::reset_button(ui, self);

let ManualLayoutTest {
let Self {
widget_offset,
widget_size,
widget_type,
Expand Down
1 change: 1 addition & 0 deletions crates/egui_demo_lib/src/demo/text_edit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/// Showcase [`TextEdit`].
#[derive(PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[cfg_attr(feature = "serde", serde(default))]
pub struct TextEdit {
Expand Down
1 change: 1 addition & 0 deletions crates/egui_demo_lib/src/demo/widget_gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl super::View for WidgetGallery {
self.gallery_grid_contents(ui);
});
});

ui.separator();

ui.horizontal(|ui| {
Expand Down
4 changes: 1 addition & 3 deletions examples/confirm_exit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ impl eframe::App for MyApp {

if ui.button("Yes!").clicked() {
self.allowed_to_close = true;
frame.close();
}
});
});
if self.allowed_to_close {
frame.close();
}
}
}
}
6 changes: 1 addition & 5 deletions examples/hello_world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@ impl eframe::App for MyApp {
&mut self,
ctx: &egui::Context,
_frame: &mut eframe::Frame,
render: Option<&ViewportRender>,
_: Option<&ViewportRender>,
) {
if let Some(render) = render {
render(ctx);
return;
}
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("My egui Application");
ui.horizontal(|ui| {
Expand Down
1 change: 0 additions & 1 deletion examples/hello_world_par/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@ eframe = { path = "../../crates/eframe", default-features = false, features = [
# accesskit struggles with threading
"default_fonts",
"wgpu",
"x11"
] }
env_logger = "0.10"
42 changes: 19 additions & 23 deletions examples/hello_world_par/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release

use std::{sync::mpsc, thread::JoinHandle};
use std::sync::mpsc;
use std::thread::JoinHandle;

use eframe::egui::{self, ViewportRender};

Expand Down Expand Up @@ -39,20 +40,20 @@ impl ThreadState {
}

fn show(&mut self, ctx: &egui::Context) {
let thread_nr = self.thread_nr;
let pos = egui::pos2(16.0, 128.0 * (thread_nr as f32 + 1.0));
let title = self.title.clone();
egui::Window::new(title).default_pos(pos).show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name);
let pos = egui::pos2(16.0, 128.0 * (self.thread_nr as f32 + 1.0));
egui::Window::new(&self.title)
.default_pos(pos)
.show(ctx, |ui| {
ui.horizontal(|ui| {
ui.label("Your name: ");
ui.text_edit_singleline(&mut self.name);
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
});
ui.add(egui::Slider::new(&mut self.age, 0..=120).text("age"));
if ui.button("Click each year").clicked() {
self.age += 1;
}
ui.label(format!("Hello '{}', age {}", self.name, self.age));
});
}
}

Expand Down Expand Up @@ -96,9 +97,7 @@ impl MyApp {

slf
}
}

impl MyApp {
fn spawn_thread(&mut self) {
let thread_nr = self.threads.len();
self.threads
Expand All @@ -120,22 +119,19 @@ impl eframe::App for MyApp {
&mut self,
ctx: &egui::Context,
_frame: &mut eframe::Frame,
render: Option<&ViewportRender>,
_: Option<&ViewportRender>,
) {
if let Some(render) = render {
render(ctx);
return;
}
egui::Window::new("Main thread").show(ctx, |ui| {
if ui.button("Spawn another thread").clicked() {
self.spawn_thread();
ui.ctx()
.request_repaint_viewport(ui.ctx().get_parent_viewport_id());
}
});

for (_handle, show_tx) in &self.threads {
let _ = show_tx.send(ctx.clone());
}

for _ in 0..self.threads.len() {
let _ = self.on_done_rc.recv();
}
}
Expand Down
49 changes: 0 additions & 49 deletions examples/viewports/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ const RENDERER: eframe::Renderer = eframe::Renderer::Glow;
pub struct App {
show_async_viewport: bool,
show_sync_viewport: bool,
show_async_window: bool,
show_sync_window: bool,

async_viewport_state: Arc<RwLock<usize>>,
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>>,
Expand Down Expand Up @@ -61,8 +57,6 @@ impl eframe::App for App {
}
ui.checkbox(&mut self.show_async_viewport, "Show Async Viewport");
ui.checkbox(&mut self.show_sync_viewport, "Show Sync Viewport");
ui.checkbox(&mut self.show_async_window, "Show Async Window");
ui.checkbox(&mut self.show_sync_window, "Show Sync Window");

let ctx = ui.ctx();
// Showing Async Viewport
Expand Down Expand Up @@ -343,49 +337,6 @@ impl eframe::App for App {
},
);
}

// Showing Async Window
if self.show_async_window {
let state = self.async_window_state.clone();
egui::Window::new("Async Window")
.default_embedded(false)
.show_async(ctx, move |ui| {
let ctx = ui.ctx().clone();
let mut state = state.write().unwrap();
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.viewport_outer_pos()));
ui.label(format!("Size: {:?}", ctx.viewport_inner_size()));
ui.label(format!("Count: {state}"));
if ui.button("Add").clicked() {
*state += 1;
}
});
}

// Showing Sync Window
if self.show_sync_window {
egui::Window::new("Sync Window")
.default_embedded(false)
.show(ctx, |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.viewport_outer_pos()));
ui.label(format!("Size: {:?}", ctx.viewport_inner_size()));
ui.label(format!("Count: {}", self.sync_window_state));
if ui.button("Add").clicked() {
self.sync_window_state += 1;
}
});
}
});
}
}
Expand Down

0 comments on commit 78a0ae8

Please sign in to comment.