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

Fix mouse input

Now on Context.create_viewport in the render function will we have viewport_id and parent_viewport_id
New problem if a windows is fucused and we interact with other window the first event will be send to the last window that was focused
This commit is contained in:
Konkitoman
2023-07-24 14:24:30 +03:00
parent 3a1d9f2e21
commit 4d883b8217
36 changed files with 261 additions and 173 deletions

View File

@@ -432,7 +432,7 @@ impl EpiIntegration {
let saved_memory: egui::Memory = self.egui_ctx.memory(|mem| mem.clone());
self.egui_ctx
.memory_mut(|mem| mem.set_everything_is_visible(true));
let full_output = self.update(app, window, egui_winit, None);
let full_output = self.update(app, window, egui_winit, None, 0, 0);
self.pending_full_output.append(full_output); // Handle it next frame
self.egui_ctx.memory_mut(|mem| *mem = saved_memory); // We don't want to remember that windows were huge.
self.egui_ctx.clear_animations();
@@ -496,7 +496,9 @@ impl EpiIntegration {
app: &mut dyn epi::App,
window: &winit::window::Window,
egui_winit: &mut egui_winit::State,
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
render: Option<Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>>,
viewport_id: u64,
parent_id: u64,
) -> egui::FullOutput {
let frame_start = std::time::Instant::now();
@@ -511,7 +513,7 @@ impl EpiIntegration {
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
crate::profile_scope!("App::update");
if let Some(render) = render {
(render.as_ref())(egui_ctx)
(render.as_ref())(egui_ctx, viewport_id, parent_id)
} else {
app.update(egui_ctx, &mut self.frame);
}

View File

@@ -454,7 +454,8 @@ mod glow_integration {
gl_surface: Option<glutin::surface::Surface<glutin::surface::WindowSurface>>,
window: Option<winit::window::Window>,
window_id: u64,
render: Option<Arc<Box<dyn Fn(&Context) + Sync + Send>>>,
parent_id: u64,
render: Option<Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>>,
pub egui_winit: Option<egui_winit::State>,
}
/// This struct will contain both persistent and temporary glutin state.
@@ -603,6 +604,7 @@ mod glow_integration {
window_id: 0,
egui_winit: None,
render: None,
parent_id: 0,
}],
window_maps,
})
@@ -1007,6 +1009,13 @@ mod glow_integration {
painter,
} = running;
let mut window_map = HashMap::default();
for window in gl_window.windows.iter() {
if let Some(win) = &window.window {
window_map.insert(window.window_id, win.id());
}
}
let egui::FullOutput {
platform_output,
repaint_after,
@@ -1052,6 +1061,8 @@ mod glow_integration {
win.window.as_ref().unwrap(),
win.egui_winit.as_mut().unwrap(),
win.render.clone(),
win.window_id,
win.parent_id,
);
integration.handle_platform_output(
@@ -1123,24 +1134,37 @@ mod glow_integration {
}
control_flow = if integration.should_close() {
EventResult::Exit
} else if repaint_after.is_zero() {
EventResult::RepaintNext(win.window.as_ref().unwrap().id())
} else if let Some(repaint_after_instant) =
std::time::Instant::now().checked_add(repaint_after)
{
// if repaint_after is something huge and can't be added to Instant,
// we will use `ControlFlow::Wait` instead.
// technically, this might lead to some weird corner cases where the user *WANTS*
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
// egui backend impl i guess.
EventResult::RepaintAt(
win.window.as_ref().unwrap().id(),
repaint_after_instant,
)
vec![EventResult::Exit]
} else {
EventResult::Wait
repaint_after
.into_iter()
.map(|(id, time)| {
if time.is_zero() {
if let Some(id) = window_map.get(&id) {
Some(EventResult::RepaintNext(*id))
} else {
None
}
} else if let Some(repaint_after_instant) =
std::time::Instant::now().checked_add(time)
{
// if repaint_after is something huge and can't be added to Instant,
// we will use `ControlFlow::Wait` instead.
// technically, this might lead to some weird corner cases where the user *WANTS*
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
// egui backend impl i guess.
if let Some(id) = window_map.get(&id) {
Some(EventResult::RepaintAt(*id, repaint_after_instant))
} else {
None
}
} else {
None
}
})
.flatten()
.collect::<Vec<EventResult>>()
};
integration.maybe_autosave(app.as_mut(), win.window.as_ref().unwrap());
@@ -1156,7 +1180,7 @@ mod glow_integration {
// 0 is the main viewport/window that will not be known by the egui_ctx
let mut active_viewports_ids = vec![0];
viewports.retain_mut(|(id, builder, render)| {
viewports.retain_mut(|(id, parent, builder, render)| {
for w in gl_window.windows.iter_mut() {
if w.window_id == *id {
if w.builder != *builder {
@@ -1169,6 +1193,7 @@ mod glow_integration {
w.gl_surface = None;
w.render = Some(render.clone());
w.builder = builder.clone();
w.parent_id = *id;
}
active_viewports_ids.push(*id);
return false;
@@ -1177,7 +1202,7 @@ mod glow_integration {
true
});
for (id, builder, render) in viewports {
for (id, parent, builder, render) in viewports {
gl_window.windows.push(Window {
builder,
gl_surface: None,
@@ -1185,6 +1210,7 @@ mod glow_integration {
window_id: id,
egui_winit: None,
render: Some(render.clone()),
parent_id: parent,
});
active_viewports_ids.push(id);
}
@@ -1199,10 +1225,15 @@ mod glow_integration {
control_flow
};
windows_indexes
let mut events = vec![EventResult::Wait];
for event in windows_indexes
.into_iter()
.map(|window_index| inner(window_index))
.collect()
{
events.extend(event)
}
events
} else {
vec![EventResult::Wait]
}

View File

@@ -417,11 +417,19 @@ impl<'open> Window<'open> {
/// Returns `None` if the window is not open (if [`Window::open`] was called with `&mut false`).
/// Returns `Some(InnerResponse { inner: None })` if the window is collapsed.
#[inline]
pub fn show(self, ctx: &Context, add_contents: impl Fn(&mut Ui) + Send + Sync + 'static) {
pub fn show(
self,
ctx: &Context,
add_contents: impl Fn(&mut Ui, u64, u64) + Send + Sync + 'static,
) {
self.show_dyn(ctx, Box::new(add_contents))
}
fn show_dyn(self, ctx: &Context, add_contents: Box<dyn Fn(&mut Ui) + Send + Sync + 'static>) {
fn show_dyn(
self,
ctx: &Context,
add_contents: Box<dyn Fn(&mut Ui, u64, u64) + Send + Sync + 'static>,
) {
let Window {
title,
open,
@@ -448,16 +456,16 @@ impl<'open> Window<'open> {
window_builder.with_inner_size((size.x as u32 + 1, size.y as u32 + 1));
}
ctx.create_viewport(window_builder, move |ctx| {
let mut frame = frame.unwrap_or(Frame::window(&ctx.style())).rounding(0.0);
CentralPanel::default()
.frame(frame)
.show(ctx, |ui| Some(add_contents(ui)));
})
ctx.create_viewport(
window_builder,
move |ctx, viewport_id, parent_viewport_id| {
let mut frame = frame.unwrap_or(Frame::window(&ctx.style())).rounding(0.0);
CentralPanel::default().frame(frame).show(ctx, |ui| {
Some(add_contents(ui, viewport_id, parent_viewport_id))
});
},
)
} else {
if ctx.current_viewport() != ctx.current_rendering_viewport() {
return;
}
let frame = frame.unwrap_or_else(|| Frame::window(&ctx.style()));
area.show_open_close_animation(ctx, &frame, is_open);
@@ -555,9 +563,9 @@ impl<'open> Window<'open> {
}
if scroll.has_any_bar() {
scroll.show(ui, add_contents).inner
scroll.show(ui, |ui| add_contents(ui, 0, 0)).inner
} else {
add_contents(ui)
add_contents(ui, 0, 0)
}
})
})

View File

@@ -60,7 +60,7 @@ struct Repaint {
/// even if there's no new events.
///
/// Also used to suppress multiple calls to the repaint callback during the same frame.
repaint_after: std::time::Duration,
pub repaint_after: HashMap<u64, std::time::Duration>,
/// While positive, keep requesting repaints. Decrement at the end of each frame.
repaint_requests: u32,
@@ -71,9 +71,11 @@ struct Repaint {
impl Default for Repaint {
fn default() -> Self {
let mut repaint_after = HashMap::default();
repaint_after.insert(0, std::time::Duration::from_millis(100));
Self {
frame_nr: 0,
repaint_after: std::time::Duration::from_millis(100),
repaint_after,
// Start with painting an extra frame to compensate for some widgets
// that take two frames before they "settle":
repaint_requests: 1,
@@ -88,7 +90,7 @@ impl Repaint {
self.request_repaint_after(std::time::Duration::ZERO, window_id);
}
fn request_repaint_after(&mut self, after: std::time::Duration, window_id: u64) {
fn request_repaint_after(&mut self, after: std::time::Duration, viewport_id: u64) {
if after == std::time::Duration::ZERO {
// Do a few extra frames to let things settle.
// This is a bit of a hack, and we don't support it for `repaint_after` callbacks yet.
@@ -97,27 +99,33 @@ impl Repaint {
// We only re-call the callback if we get a lower duration,
// otherwise it's already been covered by the previous callback.
if after < self.repaint_after {
self.repaint_after = after;
if after
< self
.repaint_after
.get(&viewport_id)
.cloned()
.unwrap_or(std::time::Duration::MAX)
{
self.repaint_after.insert(viewport_id, after);
if let Some(callback) = &self.request_repaint_callback {
let info = RequestRepaintInfo {
after,
current_frame_nr: self.frame_nr,
window_id: window_id,
window_id: viewport_id,
};
(callback)(info);
}
}
}
fn start_frame(&mut self) {
fn start_frame(&mut self, viewport_id: u64) {
// We are repainting; no need to reschedule a repaint unless the user asks for it again.
self.repaint_after = std::time::Duration::MAX;
self.repaint_after.remove(&viewport_id);
}
// returns how long to wait until repaint
fn end_frame(&mut self) -> std::time::Duration {
fn end_frame(&mut self, viewport_id: u64) -> Vec<(u64, std::time::Duration)> {
// if repaint_requests is greater than zero. just set the duration to zero for immediate
// repaint. if there's no repaint requests, then we can use the actual repaint_after instead.
let repaint_after = if self.repaint_requests > 0 {
@@ -125,13 +133,19 @@ impl Repaint {
std::time::Duration::ZERO
} else {
self.repaint_after
.get(&viewport_id)
.cloned()
.unwrap_or(std::time::Duration::MAX)
};
self.repaint_after = std::time::Duration::MAX;
self.repaint_after.insert(viewport_id, repaint_after);
self.requested_repaint_last_frame = repaint_after.is_zero();
self.frame_nr += 1;
repaint_after
self.repaint_after
.iter()
.map(|(id, time)| (*id, *time))
.collect()
}
}
@@ -167,12 +181,11 @@ struct ContextImpl {
u64,
u64,
bool,
Arc<Box<dyn Fn(&Context) + Sync + Send>>,
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
),
>,
viewport_counter: u64,
current_rendering_viewport: u64,
viewport_stack: Vec<u64>,
is_desktop: bool,
/// Written to during the frame.
@@ -189,7 +202,7 @@ struct ContextImpl {
impl ContextImpl {
fn begin_frame_mut(&mut self, mut new_raw_input: RawInput) {
self.repaint.start_frame();
self.repaint.start_frame(self.current_rendering_viewport);
if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point.take() {
new_raw_input.pixels_per_point = Some(new_pixels_per_point);
@@ -976,10 +989,11 @@ impl Context {
/// (this will work on `eframe`).
pub fn request_repaint(&self) {
// request two frames of repaint, just to cover some corner cases (frame delays):
self.write(|ctx| {
ctx.repaint
.request_repaint(ctx.viewport_stack.last().cloned().unwrap_or(0))
});
self.write(|ctx| ctx.repaint.request_repaint(ctx.current_rendering_viewport));
}
pub fn request_repaint_viewport(&self, id: u64) {
self.write(|ctx| ctx.repaint.request_repaint(id))
}
/// Request repaint after at most the specified duration elapses.
@@ -1011,9 +1025,16 @@ impl Context {
/// timeout takes 500 milliseconds AFTER the vsync swap buffer.
/// So, its not that we are requesting repaint within X duration. We are rather timing out
/// during app idle time where we are not receiving any new input events.
pub fn request_repaint_after(&self, duration: std::time::Duration, window_id: u64) {
pub fn request_repaint_after(&self, duration: std::time::Duration) {
// Maybe we can check if duration is ZERO, and call self.request_repaint()?
self.write(|ctx| ctx.repaint.request_repaint_after(duration, window_id));
self.write(|ctx| {
ctx.repaint
.request_repaint_after(duration, ctx.current_rendering_viewport)
});
}
pub fn request_repaint_viewport_after(&self, duration: std::time::Duration, id: u64) {
self.write(|ctx| ctx.repaint.request_repaint_after(duration, id))
}
/// For integrations: this callback will be called when an egui user calls [`Self::request_repaint`].
@@ -1280,7 +1301,7 @@ impl Context {
}
}
let repaint_after = self.write(|ctx| ctx.repaint.end_frame());
let repaint_after = self.write(|ctx| ctx.repaint.end_frame(ctx.current_rendering_viewport));
let shapes = self.drain_paint_lists();
// This is used for,
@@ -1303,7 +1324,7 @@ impl Context {
*used = false;
}
viewports.push((*id, builder.clone(), render.clone()));
viewports.push((*id, *parent, builder.clone(), render.clone()));
(out || ctx.current_rendering_viewport != *parent)
&& avalibile_viewports.contains(parent)
})
@@ -1498,7 +1519,7 @@ impl Context {
}
pub(crate) fn rect_contains_pointer(&self, layer_id: LayerId, rect: Rect) -> bool {
rect.is_positive() && self.current_viewport() == self.current_rendering_viewport() && {
rect.is_positive() && {
let pointer_pos = self.input(|i| i.pointer.interact_pos());
if let Some(pointer_pos) = pointer_pos {
rect.contains(pointer_pos) && self.layer_id_at(pointer_pos) == Some(layer_id)
@@ -1929,10 +1950,6 @@ impl Context {
self.read(|ctx| ctx.current_rendering_viewport)
}
pub fn current_viewport(&self) -> u64 {
self.read(|ctx| ctx.viewport_stack.last().cloned().unwrap_or(0))
}
pub fn is_desktop(&self) -> bool {
self.read(|ctx| ctx.is_desktop)
}
@@ -1944,12 +1961,12 @@ impl Context {
pub fn create_viewport(
&self,
window_builder: ViewportBuilder,
func: impl Fn(&Context) + Send + Sync + 'static,
func: impl Fn(&Context, u64, u64) + Send + Sync + 'static,
) {
let id = self.write(|ctx| {
if ctx.is_desktop {
if let Some(window) = ctx.viewports.get_mut(&window_builder.title) {
window.2 = *ctx.viewport_stack.last().unwrap_or(&0);
window.2 = ctx.current_rendering_viewport;
window.3 = true;
window.4 = Arc::new(Box::new(func));
window.1
@@ -1961,7 +1978,7 @@ impl Context {
(
window_builder,
id,
*ctx.viewport_stack.last().unwrap_or(&0),
ctx.current_rendering_viewport,
true,
Arc::new(Box::new(func)),
),
@@ -1972,13 +1989,6 @@ impl Context {
0
}
});
let should_render = self.write(|ctx| {
ctx.viewport_stack.push(id);
ctx.viewport_stack.last().cloned().unwrap_or(0) == ctx.current_rendering_viewport
});
self.write(|ctx| {
ctx.viewport_stack.pop();
});
}
}

View File

@@ -21,7 +21,7 @@ pub struct FullOutput {
/// duration elapses. when in reactive mode, egui spends forever waiting for input and only then,
/// will it repaint itself. this can be used to make sure that backend will only wait for a
/// specified amount of time, and repaint egui without any new input.
pub repaint_after: std::time::Duration,
pub repaint_after: Vec<(u64, std::time::Duration)>,
/// Texture changes since last frame (including the font texture).
///
@@ -35,9 +35,10 @@ pub struct FullOutput {
pub shapes: Vec<epaint::ClippedShape>,
pub viewports: Vec<(
u64,
u64,
ViewportBuilder,
Arc<Box<dyn Fn(&Context) + Sync + Send>>,
Arc<Box<dyn Fn(&Context, u64, u64) + Sync + Send>>,
)>,
}

View File

@@ -283,10 +283,7 @@ impl BackendPanel {
let ctx = ui.ctx().clone();
call_after_delay(std::time::Duration::from_secs(2), move || {
log::info!("Request a repaint in 3s...");
ctx.request_repaint_after(
std::time::Duration::from_secs(3),
ctx.current_rendering_viewport(),
);
ctx.request_repaint_after(std::time::Duration::from_secs(3));
});
}
});
@@ -415,7 +412,7 @@ impl EguiWindows {
egui::Window::new("🔧 Settings")
.open(settings)
.vscroll(true)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
tmp_ctx.settings_ui(ui);
});
@@ -423,7 +420,7 @@ impl EguiWindows {
egui::Window::new("🔍 Inspection")
.open(inspection)
.vscroll(true)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
tmp_ctx.inspection_ui(ui);
});
@@ -431,7 +428,7 @@ impl EguiWindows {
egui::Window::new("📝 Memory")
.open(memory)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
tmp_ctx.memory_ui(ui);
});
@@ -440,7 +437,7 @@ impl EguiWindows {
.open(output_events)
.resizable(true)
.default_width(520.0)
.show(ctx, move |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. \

View File

@@ -424,7 +424,7 @@ impl WrapApp {
let dropped_files = self.dropped_files.clone();
egui::Window::new("Dropped files")
.open(&mut open)
.show(ctx, move |ui| {
.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 {

View File

@@ -12,7 +12,7 @@ impl super::Demo for About {
egui::Window::new(self.name())
.default_width(320.0)
.open(open)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
use super::View as _;
Self::default().ui(ui);
});

View File

@@ -40,7 +40,7 @@ impl super::Demo for CodeEditor {
egui::Window::new(self.name())
.open(open)
.default_height(500.0)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -84,7 +84,7 @@ impl super::Demo for CodeExample {
.default_size([800.0, 400.0])
.vscroll(false)
.hscroll(true)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -70,7 +70,7 @@ impl super::Demo for ContextMenus {
.vscroll(false)
.resizable(false)
.open(open)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -16,7 +16,7 @@ impl super::Demo for DancingStrings {
.open(open)
.default_size(vec2(512.0, 256.0))
.vscroll(false)
.show(ctx, |ui| Self::default().ui(ui));
.show(ctx, |ui, _, _| Self::default().ui(ui));
}
}

View File

@@ -202,7 +202,7 @@ impl DemoWindows {
.open(&mut about_is_open)
.resizable(false)
.collapsible(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
let close = close.clone();
clone.data.write().unwrap().about.ui(ui);
ui.add_space(12.0);

View File

@@ -120,7 +120,7 @@ impl super::Demo for DragAndDropDemo {
.default_size(vec2(256.0, 256.0))
.vscroll(false)
.resizable(false)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -32,7 +32,7 @@ impl super::Demo for FontBook {
let clone = self.clone();
egui::Window::new(self.name())
.open(open)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -12,7 +12,7 @@ impl super::Demo for Highlighting {
egui::Window::new(self.name())
.default_width(320.0)
.open(open)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
use super::View as _;
Self::default().ui(ui);
});

View File

@@ -92,7 +92,7 @@ impl super::Demo for LayoutTest {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -62,7 +62,7 @@ impl Demo for MiscDemoWindow {
.open(open)
.vscroll(true)
.hscroll(true)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -39,7 +39,7 @@ impl super::Demo for MultiTouch {
.open(open)
.default_size(vec2(512.0, 512.0))
.resizable(true)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -166,7 +166,7 @@ impl super::Demo for PaintBezier {
.vscroll(false)
.resizable(false)
.default_size([300.0, 350.0])
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -94,7 +94,7 @@ impl super::Demo for Painting {
.open(open)
.default_size(vec2(512.0, 512.0))
.vscroll(false)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -68,7 +68,7 @@ impl super::Demo for PlotDemo {
.open(open)
.default_size(vec2(400.0, 400.0))
.vscroll(false)
.show(ctx, move |ui| clone.clone().ui(ui));
.show(ctx, move |ui, _, _| clone.clone().ui(ui));
}
}

View File

@@ -50,7 +50,7 @@ impl super::Demo for Scrolling {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -63,7 +63,7 @@ impl super::Demo for Sliders {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -16,7 +16,7 @@ impl super::Demo for StripDemo {
.open(open)
.resizable(true)
.default_width(400.0)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
use super::View as _;
Self::default().ui(ui);
});

View File

@@ -49,7 +49,7 @@ impl super::Demo for TableDemo {
.open(open)
.resizable(true)
.default_width(400.0)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -9,10 +9,12 @@ impl super::Demo for CursorTest {
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
use super::View as _;
Self::default().ui(ui);
});
egui::Window::new(self.name())
.open(open)
.show(ctx, |ui, _, _| {
use super::View as _;
Self::default().ui(ui);
});
}
}
@@ -41,10 +43,12 @@ impl super::Demo for IdTest {
}
fn show(&mut self, ctx: &egui::Context, open: &mut bool) {
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
use super::View as _;
Self::default().ui(ui);
});
egui::Window::new(self.name())
.open(open)
.show(ctx, |ui, _, _| {
use super::View as _;
Self::default().ui(ui);
});
}
}
@@ -135,7 +139,7 @@ impl super::Demo for ManualLayoutTest {
egui::Window::new(self.name())
.resizable(false)
.open(open)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});
@@ -232,7 +236,7 @@ impl super::Demo for TableTest {
let clone = self.clone();
egui::Window::new(self.name())
.open(open)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});
@@ -353,7 +357,7 @@ impl super::Demo for InputTest {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});
@@ -434,7 +438,7 @@ impl super::Demo for WindowResizeTest {
Window::new("↔ auto-sized")
.open(open)
.auto_sized()
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
ui.label("This window will auto-size based on its contents.");
ui.heading("Resize this area:");
Resize::default().show(ui, |ui| {
@@ -448,7 +452,7 @@ impl super::Demo for WindowResizeTest {
.vscroll(true)
.resizable(true)
.default_height(300.0)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
ui.label(
"This window is resizable and has a scroll area. You can shrink it to any size.",
);
@@ -461,7 +465,7 @@ impl super::Demo for WindowResizeTest {
.vscroll(false)
.resizable(true)
.default_height(300.0)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
ui.label("This window is resizable but has no built-in scroll area.");
ui.label("However, we have a sub-region with a scroll bar:");
ui.separator();
@@ -477,7 +481,7 @@ impl super::Demo for WindowResizeTest {
.open(open)
.vscroll(false)
.resizable(true)
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
ui.label("This window is resizable but has no scroll area. This means it can only be resized to a size where all the contents is visible.");
ui.label("egui will not clip the contents of a window, nor add whitespace to it.");
ui.separator();
@@ -491,7 +495,7 @@ impl super::Demo for WindowResizeTest {
.vscroll(false)
.resizable(true)
.default_height(300.0)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
ui.label("Shows how you can fill an area with a widget.");
let mut text = clone.text.write().unwrap();
ui.add_sized(ui.available_size(), TextEdit::multiline(&mut *text));
@@ -502,7 +506,7 @@ impl super::Demo for WindowResizeTest {
.vscroll(false)
.resizable(true)
.default_size([250.0, 150.0])
.show(ctx, |ui| {
.show(ctx, |ui, _, _| {
ui.label("This window has empty space that fills up the available space, preventing auto-shrink.");
ui.allocate_space(ui.available_size());
});

View File

@@ -32,7 +32,7 @@ impl super::Demo for TextEdit {
egui::Window::new(self.name())
.open(open)
.resizable(false)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -63,7 +63,7 @@ impl super::Demo for WidgetGallery {
.open(open)
.resizable(true)
.default_width(280.0)
.show(ctx, move |ui| {
.show(ctx, move |ui, _, _| {
use super::View as _;
clone.clone().ui(ui);
});

View File

@@ -83,7 +83,7 @@ impl super::Demo for WindowOptions {
window = window.anchor(anchor, anchor_offset);
}
let clone = self.clone();
window.show(ctx, move |ui| {
window.show(ctx, move |ui, _, _| {
let mut clone = clone.clone();
clone.ui(ui)
});

View File

@@ -14,7 +14,7 @@ impl super::Demo for WindowWithPanels {
.default_height(400.0)
.vscroll(false)
.open(open);
window.show(ctx, |ui| Self {}.ui(ui));
window.show(ctx, |ui, _, _| Self {}.ui(ui));
}
}