mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
* Fix warnings
* Refactor eframe wgpu
This commit is contained in:
@@ -945,7 +945,7 @@ mod glow_integration {
|
|||||||
);
|
);
|
||||||
#[cfg(feature = "accesskit")]
|
#[cfg(feature = "accesskit")]
|
||||||
{
|
{
|
||||||
let window = gl_window.windows.get(&ViewportId::MAIN).unwrap();
|
let window = &gl_window.windows[&ViewportId::MAIN];
|
||||||
let window = &mut *window.write();
|
let window = &mut *window.write();
|
||||||
integration.init_accesskit(
|
integration.init_accesskit(
|
||||||
window.egui_winit.as_mut().unwrap(),
|
window.egui_winit.as_mut().unwrap(),
|
||||||
@@ -1303,7 +1303,7 @@ mod glow_integration {
|
|||||||
// This will only happen if the viewport is sync
|
// This will only happen if the viewport is sync
|
||||||
// That means that the viewport cannot be rendered by itself and needs his parent to be rendered
|
// That means that the viewport cannot be rendered by itself and needs his parent to be rendered
|
||||||
{
|
{
|
||||||
let win = glutin_ctx.read().windows.get(&viewport_id).unwrap().clone();
|
let win = &glutin_ctx.read().windows[&viewport_id].clone();
|
||||||
if win.read().render.is_none() && viewport_id != ViewportId::MAIN {
|
if win.read().render.is_none() && viewport_id != ViewportId::MAIN {
|
||||||
if let Some(win) = glutin_ctx.read().windows.get(&win.read().parent_id) {
|
if let Some(win) = glutin_ctx.read().windows.get(&win.read().parent_id) {
|
||||||
if let Some(w) = win.read().window.as_ref() {
|
if let Some(w) = win.read().window.as_ref() {
|
||||||
@@ -1776,22 +1776,16 @@ mod wgpu_integration {
|
|||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Windows(
|
pub struct Window {
|
||||||
Arc<
|
window: Option<Arc<RwLock<winit::window::Window>>>,
|
||||||
RwLock<
|
state: Arc<RwLock<Option<egui_winit::State>>>,
|
||||||
HashMap<
|
render: Option<Arc<Box<ViewportRender>>>,
|
||||||
ViewportId,
|
parent_id: ViewportId,
|
||||||
(
|
builder: ViewportBuilder,
|
||||||
Option<Arc<RwLock<winit::window::Window>>>,
|
}
|
||||||
Arc<RwLock<Option<egui_winit::State>>>,
|
|
||||||
Option<Arc<Box<ViewportRender>>>,
|
#[derive(Clone)]
|
||||||
ViewportId,
|
pub struct Windows(Arc<RwLock<HashMap<ViewportId, Window>>>);
|
||||||
ViewportBuilder,
|
|
||||||
),
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
);
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe impl Send for Windows {}
|
unsafe impl Send for Windows {}
|
||||||
@@ -1799,20 +1793,7 @@ mod wgpu_integration {
|
|||||||
unsafe impl Sync for Windows {}
|
unsafe impl Sync for Windows {}
|
||||||
|
|
||||||
impl std::ops::Deref for Windows {
|
impl std::ops::Deref for Windows {
|
||||||
type Target = Arc<
|
type Target = Arc<RwLock<HashMap<ViewportId, Window>>>;
|
||||||
RwLock<
|
|
||||||
HashMap<
|
|
||||||
ViewportId,
|
|
||||||
(
|
|
||||||
Option<Arc<RwLock<winit::window::Window>>>,
|
|
||||||
Arc<RwLock<Option<egui_winit::State>>>,
|
|
||||||
Option<Arc<Box<ViewportRender>>>,
|
|
||||||
ViewportId,
|
|
||||||
ViewportBuilder,
|
|
||||||
),
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>;
|
|
||||||
|
|
||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
&self.0
|
&self.0
|
||||||
@@ -1887,7 +1868,16 @@ mod wgpu_integration {
|
|||||||
fn build_windows(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) {
|
fn build_windows(&mut self, event_loop: &EventLoopWindowTarget<UserEvent>) {
|
||||||
let Some(running) = &mut self.running else {return};
|
let Some(running) = &mut self.running else {return};
|
||||||
|
|
||||||
for (id, (window, state, _, _, builder)) in running.windows.write().iter_mut() {
|
for (
|
||||||
|
id,
|
||||||
|
Window {
|
||||||
|
window,
|
||||||
|
state,
|
||||||
|
builder,
|
||||||
|
..
|
||||||
|
},
|
||||||
|
) in running.windows.write().iter_mut()
|
||||||
|
{
|
||||||
if window.is_some() {
|
if window.is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -1928,10 +1918,15 @@ mod wgpu_integration {
|
|||||||
|
|
||||||
fn set_window(&mut self, id: ViewportId) -> std::result::Result<(), egui_wgpu::WgpuError> {
|
fn set_window(&mut self, id: ViewportId) -> std::result::Result<(), egui_wgpu::WgpuError> {
|
||||||
if let Some(running) = &mut self.running {
|
if let Some(running) = &mut self.running {
|
||||||
if let Some((Some(window), _, _, _, _)) = running.windows.read().get(&id) {
|
if let Some(Window { window, .. }) = running.windows.read().get(&id) {
|
||||||
return pollster::block_on(
|
let window = window.clone();
|
||||||
running.painter.write().set_window(id, Some(&window.read())),
|
if let Some(win) = &window {
|
||||||
);
|
return pollster::block_on(
|
||||||
|
running.painter.write().set_window(id, Some(&*win.read())),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return pollster::block_on(running.painter.write().set_window(id, None));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -2036,13 +2031,13 @@ mod wgpu_integration {
|
|||||||
let windows = Windows(Arc::new(RwLock::new(HashMap::default())));
|
let windows = Windows(Arc::new(RwLock::new(HashMap::default())));
|
||||||
windows.write().insert(
|
windows.write().insert(
|
||||||
ViewportId::MAIN,
|
ViewportId::MAIN,
|
||||||
(
|
Window {
|
||||||
Some(Arc::new(RwLock::new(window))),
|
window: Some(Arc::new(RwLock::new(window))),
|
||||||
Arc::new(RwLock::new(Some(state))),
|
state: Arc::new(RwLock::new(Some(state))),
|
||||||
None,
|
render: None,
|
||||||
ViewportId::MAIN,
|
parent_id: ViewportId::MAIN,
|
||||||
builder,
|
builder,
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
let _windows = windows.clone();
|
let _windows = windows.clone();
|
||||||
@@ -2057,7 +2052,7 @@ mod wgpu_integration {
|
|||||||
move |viewport_builder, viewport_id, parent_viewport_id, render| {
|
move |viewport_builder, viewport_id, parent_viewport_id, render| {
|
||||||
if _windows.read().get(&viewport_id).is_none(){
|
if _windows.read().get(&viewport_id).is_none(){
|
||||||
let mut _windows = _windows.write();
|
let mut _windows = _windows.write();
|
||||||
let (window, state, _, _, _) = _windows.entry(viewport_id).or_insert((None, Arc::new(RwLock::new(None)), None, viewport_id, viewport_builder.clone()));
|
let Window{window, state, ..} = _windows.entry(viewport_id).or_insert(Window{window: None, state: Arc::new(RwLock::new(None)), render: None, parent_id: viewport_id, builder: viewport_builder.clone()});
|
||||||
|
|
||||||
let event_loop;
|
let event_loop;
|
||||||
|
|
||||||
@@ -2072,8 +2067,8 @@ mod wgpu_integration {
|
|||||||
if let Some(window) = window {
|
if let Some(window) = window {
|
||||||
let output;
|
let output;
|
||||||
{
|
{
|
||||||
if let Some(winit_state) = &mut *window.1.write() {
|
if let Some(winit_state) = &mut *window.state.write() {
|
||||||
if let Some(win) = window.0.clone() {
|
if let Some(win) = window.window {
|
||||||
let win = win.read();
|
let win = win.read();
|
||||||
let mut input = winit_state.take_egui_input(&win);
|
let mut input = winit_state.take_egui_input(&win);
|
||||||
input.time = Some(time.elapsed().as_secs_f64());
|
input.time = Some(time.elapsed().as_secs_f64());
|
||||||
@@ -2120,8 +2115,8 @@ mod wgpu_integration {
|
|||||||
|
|
||||||
viewports.retain_mut(|(id, parent, _builder, render)| {
|
viewports.retain_mut(|(id, parent, _builder, render)| {
|
||||||
if let Some(w) = _windows.write().get_mut(id) {
|
if let Some(w) = _windows.write().get_mut(id) {
|
||||||
w.2 = render.clone();
|
w.render = render.clone();
|
||||||
w.3 = *parent;
|
w.parent_id = *parent;
|
||||||
active_viewports_ids.push(*id);
|
active_viewports_ids.push(*id);
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
@@ -2132,7 +2127,7 @@ mod wgpu_integration {
|
|||||||
for (id, parent, builder, render) in viewports {
|
for (id, parent, builder, render) in viewports {
|
||||||
_windows.write().insert(
|
_windows.write().insert(
|
||||||
id,
|
id,
|
||||||
(None, Arc::new(RwLock::new(None)), render, parent, builder),
|
Window{window: None, state: Arc::new(RwLock::new(None)), render, parent_id: parent, builder},
|
||||||
);
|
);
|
||||||
active_viewports_ids.push(id);
|
active_viewports_ids.push(id);
|
||||||
}
|
}
|
||||||
@@ -2140,7 +2135,8 @@ mod wgpu_integration {
|
|||||||
egui_winit::process_viewports_commands(
|
egui_winit::process_viewports_commands(
|
||||||
output.viewport_commands,
|
output.viewport_commands,
|
||||||
*focused.read(),
|
*focused.read(),
|
||||||
|id| _windows.read().get(&id).and_then(|w| w.0.clone()),
|
|id| _windows.read().get(&id).and_then(|w| w.window.clone())
|
||||||
|
,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2188,7 +2184,7 @@ mod wgpu_integration {
|
|||||||
r.windows_id
|
r.windows_id
|
||||||
.read()
|
.read()
|
||||||
.get(&window_id)
|
.get(&window_id)
|
||||||
.and_then(|id| r.windows.read().get(id).map(|w| w.0.clone()))
|
.and_then(|id| r.windows.read().get(id).map(|w| w.window.clone()))
|
||||||
})
|
})
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
@@ -2198,13 +2194,13 @@ mod wgpu_integration {
|
|||||||
r.windows
|
r.windows
|
||||||
.read()
|
.read()
|
||||||
.get(&id)
|
.get(&id)
|
||||||
.and_then(|w| w.0.as_ref().map(|w| w.read().id()))
|
.and_then(|w| w.window.as_ref().map(|w| w.read().id()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_and_destroy(&mut self) {
|
fn save_and_destroy(&mut self) {
|
||||||
if let Some(mut running) = self.running.take() {
|
if let Some(mut running) = self.running.take() {
|
||||||
if let Some((window, _, _, _, _)) = running.windows.read().get(&ViewportId::MAIN) {
|
if let Some(Window { window, .. }) = running.windows.read().get(&ViewportId::MAIN) {
|
||||||
running
|
running
|
||||||
.integration
|
.integration
|
||||||
.write()
|
.write()
|
||||||
@@ -2244,11 +2240,11 @@ mod wgpu_integration {
|
|||||||
viewport_commands,
|
viewport_commands,
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let Some((viewport_id, (Some(window), state, render, parent_viewport_id, _))) = windows_id.read().get(&window_id).and_then(|id|(windows.read().get(id).map(|w|(*id, w.clone())))) else{return vec![]};
|
let Some((viewport_id, Window{window: Some(window), state, render, parent_id, ..})) = windows_id.read().get(&window_id).and_then(|id|(windows.read().get(id).map(|w|(*id, w.clone())))) else{return vec![]};
|
||||||
// This is used to not render a viewport if is sync
|
// This is used to not render a viewport if is sync
|
||||||
if viewport_id != ViewportId::MAIN && render.is_none() {
|
if viewport_id != ViewportId::MAIN && render.is_none() {
|
||||||
if let Some(window) = running.windows.read().get(&parent_viewport_id) {
|
if let Some(window) = running.windows.read().get(&parent_id) {
|
||||||
if let Some(w) = window.0.as_ref() {
|
if let Some(w) = window.window.as_ref() {
|
||||||
return vec![EventResult::RepaintNow(w.read().id())];
|
return vec![EventResult::RepaintNow(w.read().id())];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2274,7 +2270,7 @@ mod wgpu_integration {
|
|||||||
state.write().as_mut().unwrap(),
|
state.write().as_mut().unwrap(),
|
||||||
&render.clone(),
|
&render.clone(),
|
||||||
viewport_id,
|
viewport_id,
|
||||||
parent_viewport_id,
|
parent_id,
|
||||||
);
|
);
|
||||||
|
|
||||||
integration.write().handle_platform_output(
|
integration.write().handle_platform_output(
|
||||||
@@ -2310,8 +2306,8 @@ mod wgpu_integration {
|
|||||||
|
|
||||||
viewports.retain_mut(|(id, parent, _builder, render)| {
|
viewports.retain_mut(|(id, parent, _builder, render)| {
|
||||||
if let Some(w) = windows.write().get_mut(id) {
|
if let Some(w) = windows.write().get_mut(id) {
|
||||||
w.2 = render.clone();
|
w.render = render.clone();
|
||||||
w.3 = *parent;
|
w.parent_id = *parent;
|
||||||
active_viewports_ids.push(*id);
|
active_viewports_ids.push(*id);
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
@@ -2322,7 +2318,13 @@ mod wgpu_integration {
|
|||||||
for (id, parent, builder, render) in viewports {
|
for (id, parent, builder, render) in viewports {
|
||||||
windows.write().insert(
|
windows.write().insert(
|
||||||
id,
|
id,
|
||||||
(None, Arc::new(RwLock::new(None)), render, parent, builder),
|
Window {
|
||||||
|
window: None,
|
||||||
|
state: Arc::new(RwLock::new(None)),
|
||||||
|
render,
|
||||||
|
parent_id: parent,
|
||||||
|
builder,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
active_viewports_ids.push(id);
|
active_viewports_ids.push(id);
|
||||||
}
|
}
|
||||||
@@ -2330,7 +2332,12 @@ mod wgpu_integration {
|
|||||||
egui_winit::process_viewports_commands(
|
egui_winit::process_viewports_commands(
|
||||||
viewport_commands,
|
viewport_commands,
|
||||||
*self.is_focused.read(),
|
*self.is_focused.read(),
|
||||||
|viewport_id| windows.read().get(&viewport_id).and_then(|w| w.0.clone()),
|
|viewport_id| {
|
||||||
|
windows
|
||||||
|
.read()
|
||||||
|
.get(&viewport_id)
|
||||||
|
.and_then(|w| w.window.clone())
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
windows
|
windows
|
||||||
@@ -2346,8 +2353,10 @@ mod wgpu_integration {
|
|||||||
control_flow.push(if integration.read().should_close() {
|
control_flow.push(if integration.read().should_close() {
|
||||||
EventResult::Exit
|
EventResult::Exit
|
||||||
} else if repaint_after.1.is_zero() {
|
} else if repaint_after.1.is_zero() {
|
||||||
if let Some((Some(window), _, _, _, _)) =
|
if let Some(Window {
|
||||||
windows.read().get(&repaint_after.0)
|
window: Some(window),
|
||||||
|
..
|
||||||
|
}) = windows.read().get(&repaint_after.0)
|
||||||
{
|
{
|
||||||
EventResult::RepaintNext(window.read().id())
|
EventResult::RepaintNext(window.read().id())
|
||||||
} else {
|
} else {
|
||||||
@@ -2361,8 +2370,10 @@ mod wgpu_integration {
|
|||||||
// technically, this might lead to some weird corner cases where the user *WANTS*
|
// 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
|
// winit to use `WaitUntil(MAX_INSTANT)` explicitly. they can roll their own
|
||||||
// egui backend impl i guess.
|
// egui backend impl i guess.
|
||||||
if let Some((Some(window), _, _, _, _)) =
|
if let Some(Window {
|
||||||
windows.read().get(&repaint_after.0)
|
window: Some(window),
|
||||||
|
..
|
||||||
|
}) = windows.read().get(&repaint_after.0)
|
||||||
{
|
{
|
||||||
EventResult::RepaintAt(window.read().id(), repaint_after_instant)
|
EventResult::RepaintAt(window.read().id(), repaint_after_instant)
|
||||||
} else {
|
} else {
|
||||||
@@ -2373,7 +2384,7 @@ mod wgpu_integration {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some((_, (Some(window), _, _, _, _))) = windows_id.read().get(&window_id).and_then(|id|(windows.read().get(id).map(|w|(*id, w.clone())))) else{return vec![]};
|
let Some((_, Window{window: Some(window), ..})) = windows_id.read().get(&window_id).and_then(|id|(windows.read().get(id).map(|w|(*id, w.clone())))) else{return vec![]};
|
||||||
integration
|
integration
|
||||||
.write()
|
.write()
|
||||||
.maybe_autosave(app.as_mut(), window.clone());
|
.maybe_autosave(app.as_mut(), window.clone());
|
||||||
@@ -2432,7 +2443,7 @@ mod wgpu_integration {
|
|||||||
.read()
|
.read()
|
||||||
.get(&ViewportId::MAIN)
|
.get(&ViewportId::MAIN)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.0
|
.window
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.read()
|
.read()
|
||||||
@@ -2510,7 +2521,7 @@ mod wgpu_integration {
|
|||||||
_ => {}
|
_ => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
let event_response = if let Some((id, (_, state, _, _, _))) =
|
let event_response = if let Some((id, Window { state, .. })) =
|
||||||
running.windows_id.read().get(window_id).and_then(|id| {
|
running.windows_id.read().get(window_id).and_then(|id| {
|
||||||
running.windows.read().get(id).map(|w| (*id, w.clone()))
|
running.windows.read().get(id).map(|w| (*id, w.clone()))
|
||||||
}) {
|
}) {
|
||||||
@@ -2552,7 +2563,7 @@ mod wgpu_integration {
|
|||||||
accesskit_winit::ActionRequestEvent { request, window_id },
|
accesskit_winit::ActionRequestEvent { request, window_id },
|
||||||
)) => {
|
)) => {
|
||||||
if let Some(running) = &mut self.running {
|
if let Some(running) = &mut self.running {
|
||||||
if let Some((_, state, _, _, _)) = running
|
if let Some(Window { state, .. }) = running
|
||||||
.windows_id
|
.windows_id
|
||||||
.read()
|
.read()
|
||||||
.get(window_id)
|
.get(window_id)
|
||||||
|
|||||||
@@ -209,19 +209,7 @@ struct ContextImpl {
|
|||||||
>,
|
>,
|
||||||
viewport_commands: Vec<(ViewportId, ViewportCommand)>,
|
viewport_commands: Vec<(ViewportId, ViewportCommand)>,
|
||||||
|
|
||||||
render_sync: Option<
|
render_sync: Option<Arc<Box<ViewportRenderSyncCallback>>>,
|
||||||
Arc<
|
|
||||||
Box<
|
|
||||||
dyn for<'a> Fn(
|
|
||||||
ViewportBuilder,
|
|
||||||
ViewportId,
|
|
||||||
ViewportId,
|
|
||||||
Box<dyn FnOnce(&Context) + 'a>,
|
|
||||||
) + Send
|
|
||||||
+ Sync,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
>,
|
|
||||||
|
|
||||||
viewport_counter: u64,
|
viewport_counter: u64,
|
||||||
is_desktop: bool,
|
is_desktop: bool,
|
||||||
@@ -312,12 +300,12 @@ impl ContextImpl {
|
|||||||
self.frame_state
|
self.frame_state
|
||||||
.entry(viewport_id)
|
.entry(viewport_id)
|
||||||
.or_default()
|
.or_default()
|
||||||
.begin_frame(self.input.get(&viewport_id).unwrap());
|
.begin_frame(&self.input[&viewport_id]);
|
||||||
|
|
||||||
self.update_fonts_mut();
|
self.update_fonts_mut();
|
||||||
|
|
||||||
// Ensure we register the background area so panels and background ui can catch clicks:
|
// Ensure we register the background area so panels and background ui can catch clicks:
|
||||||
let input = self.input.get(&viewport_id).unwrap();
|
let input = &self.input[&viewport_id];
|
||||||
let screen_rect = input.screen_rect();
|
let screen_rect = input.screen_rect();
|
||||||
self.memory.areas.set_state(
|
self.memory.areas.set_state(
|
||||||
LayerId::background(),
|
LayerId::background(),
|
||||||
@@ -694,7 +682,7 @@ impl Context {
|
|||||||
/// Read-only access to [`FrameState`].
|
/// Read-only access to [`FrameState`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(crate) fn frame_state<R>(&self, reader: impl FnOnce(&FrameState) -> R) -> R {
|
pub(crate) fn frame_state<R>(&self, reader: impl FnOnce(&FrameState) -> R) -> R {
|
||||||
self.read(move |ctx| reader(ctx.frame_state.get(&ctx.get_viewport_id()).unwrap()))
|
self.read(move |ctx| reader(&ctx.frame_state[&ctx.get_viewport_id()]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read-write access to [`FrameState`].
|
/// Read-write access to [`FrameState`].
|
||||||
@@ -882,19 +870,14 @@ impl Context {
|
|||||||
.push((id, interact_rect));
|
.push((id, interact_rect));
|
||||||
|
|
||||||
if hovered {
|
if hovered {
|
||||||
let pointer_pos = ctx
|
let pointer_pos = &ctx.input[&ctx.get_viewport_id()].pointer.interact_pos();
|
||||||
.input
|
|
||||||
.get(&ctx.get_viewport_id())
|
|
||||||
.unwrap()
|
|
||||||
.pointer
|
|
||||||
.interact_pos();
|
|
||||||
if let Some(pointer_pos) = pointer_pos {
|
if let Some(pointer_pos) = pointer_pos {
|
||||||
if let Some(rects) = ctx.layer_rects_prev_frame.get(&layer_id) {
|
if let Some(rects) = ctx.layer_rects_prev_frame.get(&layer_id) {
|
||||||
for &(prev_id, prev_rect) in rects.iter().rev() {
|
for &(prev_id, prev_rect) in rects.iter().rev() {
|
||||||
if prev_id == id {
|
if prev_id == id {
|
||||||
break; // there is no other interactive widget covering us at the pointer position.
|
break; // there is no other interactive widget covering us at the pointer position.
|
||||||
}
|
}
|
||||||
if prev_rect.contains(pointer_pos) {
|
if prev_rect.contains(*pointer_pos) {
|
||||||
// Another interactive widget is covering us at the pointer position,
|
// Another interactive widget is covering us at the pointer position,
|
||||||
// so we aren't hovered.
|
// so we aren't hovered.
|
||||||
|
|
||||||
@@ -1506,7 +1489,7 @@ impl Context {
|
|||||||
|
|
||||||
let textures_delta = self.write(|ctx| {
|
let textures_delta = self.write(|ctx| {
|
||||||
ctx.memory.end_frame(
|
ctx.memory.end_frame(
|
||||||
ctx.input.get(&ctx.get_viewport_id()).unwrap(),
|
&ctx.input[&ctx.get_viewport_id()],
|
||||||
&viewports,
|
&viewports,
|
||||||
&ctx.frame_state
|
&ctx.frame_state
|
||||||
.entry(ctx.get_viewport_id())
|
.entry(ctx.get_viewport_id())
|
||||||
@@ -1723,11 +1706,7 @@ impl Context {
|
|||||||
/// How much space is used by panels and windows.
|
/// How much space is used by panels and windows.
|
||||||
pub fn used_rect(&self) -> Rect {
|
pub fn used_rect(&self) -> Rect {
|
||||||
self.read(|ctx| {
|
self.read(|ctx| {
|
||||||
let mut used = ctx
|
let mut used = ctx.frame_state[&ctx.get_viewport_id()].used_by_panels;
|
||||||
.frame_state
|
|
||||||
.get(&ctx.get_viewport_id())
|
|
||||||
.unwrap()
|
|
||||||
.used_by_panels;
|
|
||||||
for window in ctx.memory.areas.visible_windows() {
|
for window in ctx.memory.areas.visible_windows() {
|
||||||
used = used.union(window.rect());
|
used = used.union(window.rect());
|
||||||
}
|
}
|
||||||
@@ -1905,7 +1884,7 @@ impl Context {
|
|||||||
pub fn animate_bool_with_time(&self, id: Id, target_value: bool, animation_time: f32) -> f32 {
|
pub fn animate_bool_with_time(&self, id: Id, target_value: bool, animation_time: f32) -> f32 {
|
||||||
let animated_value = self.write(|ctx| {
|
let animated_value = self.write(|ctx| {
|
||||||
ctx.animation_manager.animate_bool(
|
ctx.animation_manager.animate_bool(
|
||||||
ctx.input.get(&ctx.get_viewport_id()).unwrap(),
|
&ctx.input[&ctx.get_viewport_id()],
|
||||||
animation_time,
|
animation_time,
|
||||||
id,
|
id,
|
||||||
target_value,
|
target_value,
|
||||||
@@ -1925,7 +1904,7 @@ impl Context {
|
|||||||
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32 {
|
pub fn animate_value_with_time(&self, id: Id, target_value: f32, animation_time: f32) -> f32 {
|
||||||
let animated_value = self.write(|ctx| {
|
let animated_value = self.write(|ctx| {
|
||||||
ctx.animation_manager.animate_value(
|
ctx.animation_manager.animate_value(
|
||||||
ctx.input.get(&ctx.get_viewport_id()).unwrap(),
|
&ctx.input[&ctx.get_viewport_id()],
|
||||||
animation_time,
|
animation_time,
|
||||||
id,
|
id,
|
||||||
target_value,
|
target_value,
|
||||||
|
|||||||
@@ -24,9 +24,14 @@ impl ViewportId {
|
|||||||
/// This is used to render an async viewport
|
/// This is used to render an async viewport
|
||||||
pub type ViewportRender = dyn Fn(&Context) + Sync + Send;
|
pub type ViewportRender = dyn Fn(&Context) + Sync + Send;
|
||||||
|
|
||||||
|
pub type ViewportRenderSyncCallback = dyn for<'a> Fn(ViewportBuilder, ViewportId, ViewportId, Box<dyn FnOnce(&Context) + 'a>)
|
||||||
|
+ Send
|
||||||
|
+ Sync;
|
||||||
|
|
||||||
/// The filds in this struct should not be change directly, but is not problem tho!
|
/// The filds in this struct should not be change directly, but is not problem tho!
|
||||||
/// Every thing is wrapped in Option<> indicates that thing should not be changed!
|
/// Every thing is wrapped in Option<> indicates that thing should not be changed!
|
||||||
#[derive(PartialEq, Eq, Clone)]
|
#[derive(PartialEq, Eq, Clone)]
|
||||||
|
#[allow(clippy::option_option)]
|
||||||
pub struct ViewportBuilder {
|
pub struct ViewportBuilder {
|
||||||
pub id: Id,
|
pub id: Id,
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
|
use egui::mutex::RwLock;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::RwLock;
|
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use eframe::egui::ViewportBuilder;
|
use eframe::egui::ViewportBuilder;
|
||||||
use eframe::NativeOptions;
|
use eframe::NativeOptions;
|
||||||
|
|
||||||
#[cfg(feature = "wgpu")]
|
|
||||||
const RENDERER: eframe::Renderer = eframe::Renderer::Wgpu;
|
|
||||||
#[cfg(not(feature = "wgpu"))]
|
|
||||||
const RENDERER: eframe::Renderer = eframe::Renderer::Glow;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct App {
|
pub struct App {
|
||||||
show_async_viewport: bool,
|
show_async_viewport: bool,
|
||||||
@@ -58,10 +53,10 @@ impl eframe::App for App {
|
|||||||
ctx.create_viewport(
|
ctx.create_viewport(
|
||||||
ViewportBuilder::new("Async Viewport").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();
|
||||||
|
|
||||||
let mut show_async_viewport2 = show_async_viewport2.write().unwrap();
|
let mut show_async_viewport2 = show_async_viewport2.write();
|
||||||
let mut show_sync_viewport2 = show_sync_viewport2.write().unwrap();
|
let mut show_sync_viewport2 = show_sync_viewport2.write();
|
||||||
|
|
||||||
let async_viewport_state2 = async_viewport_state2.clone();
|
let async_viewport_state2 = async_viewport_state2.clone();
|
||||||
let sync_viewport_state2 = sync_viewport_state2.clone();
|
let sync_viewport_state2 = sync_viewport_state2.clone();
|
||||||
@@ -72,7 +67,7 @@ impl eframe::App for App {
|
|||||||
ui.checkbox(&mut show_async_viewport2, "Show Async Viewport 2");
|
ui.checkbox(&mut show_async_viewport2, "Show Async Viewport 2");
|
||||||
ui.checkbox(&mut show_sync_viewport2, "Show Sync Viewport 2");
|
ui.checkbox(&mut show_sync_viewport2, "Show Sync Viewport 2");
|
||||||
|
|
||||||
ui.label(format!("Count: {state}"));
|
ui.label(format!("Count: {}", *state));
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
*state += 1;
|
*state += 1;
|
||||||
}
|
}
|
||||||
@@ -82,12 +77,12 @@ impl eframe::App for App {
|
|||||||
ViewportBuilder::new("Async Viewport in Async Viewport")
|
ViewportBuilder::new("Async Viewport in Async Viewport")
|
||||||
.with_title("Async Viewport in Async Viewport"),
|
.with_title("Async Viewport in Async Viewport"),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
let mut state = async_viewport_state2.write().unwrap();
|
let mut state = async_viewport_state2.write();
|
||||||
|
|
||||||
let content = move |ui: &mut egui::Ui| {
|
let content = move |ui: &mut egui::Ui| {
|
||||||
ui_info(ui);
|
ui_info(ui);
|
||||||
|
|
||||||
ui.label(format!("Count: {state}"));
|
ui.label(format!("Count: {}", *state));
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
*state += 1;
|
*state += 1;
|
||||||
}
|
}
|
||||||
@@ -107,12 +102,12 @@ impl eframe::App for App {
|
|||||||
ViewportBuilder::new("Sync Viewport in Async Viewport")
|
ViewportBuilder::new("Sync Viewport in Async Viewport")
|
||||||
.with_title("Sync Viewport in Async Viewport"),
|
.with_title("Sync Viewport in Async Viewport"),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
let mut state = sync_viewport_state2.write().unwrap();
|
let mut state = sync_viewport_state2.write();
|
||||||
|
|
||||||
let content = move |ui: &mut egui::Ui| {
|
let content = move |ui: &mut egui::Ui| {
|
||||||
ui_info(ui);
|
ui_info(ui);
|
||||||
|
|
||||||
ui.label(format!("Count: {state}"));
|
ui.label(format!("Count: {}", *state));
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
*state += 1;
|
*state += 1;
|
||||||
}
|
}
|
||||||
@@ -156,12 +151,12 @@ impl eframe::App for App {
|
|||||||
ViewportBuilder::new("Async Viewport in Sync Viewport")
|
ViewportBuilder::new("Async Viewport in Sync Viewport")
|
||||||
.with_title("Async Viewport in Sync Viewport"),
|
.with_title("Async Viewport in Sync Viewport"),
|
||||||
move |ctx| {
|
move |ctx| {
|
||||||
let mut state = async_viewport_state3.write().unwrap();
|
let mut state = async_viewport_state3.write();
|
||||||
|
|
||||||
let content = move |ui: &mut egui::Ui| {
|
let content = move |ui: &mut egui::Ui| {
|
||||||
ui_info(ui);
|
ui_info(ui);
|
||||||
|
|
||||||
ui.label(format!("Count: {state}"));
|
ui.label(format!("Count: {}", *state));
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
*state += 1;
|
*state += 1;
|
||||||
}
|
}
|
||||||
@@ -186,7 +181,7 @@ impl eframe::App for App {
|
|||||||
let content = move |ui: &mut egui::Ui| {
|
let content = move |ui: &mut egui::Ui| {
|
||||||
ui_info(ui);
|
ui_info(ui);
|
||||||
|
|
||||||
ui.label(format!("Count: {state}"));
|
ui.label(format!("Count: {}", *state));
|
||||||
if ui.button("Add").clicked() {
|
if ui.button("Add").clicked() {
|
||||||
*state += 1;
|
*state += 1;
|
||||||
}
|
}
|
||||||
@@ -237,7 +232,9 @@ fn main() {
|
|||||||
let _ = eframe::run_native(
|
let _ = eframe::run_native(
|
||||||
"Viewports",
|
"Viewports",
|
||||||
NativeOptions {
|
NativeOptions {
|
||||||
renderer: RENDERER,
|
#[cfg(feature = "wgpu")]
|
||||||
|
renderer: eframe::Renderer::Wgpu,
|
||||||
|
|
||||||
initial_window_size: Some(egui::Vec2::new(400.0, 220.0)),
|
initial_window_size: Some(egui::Vec2::new(400.0, 220.0)),
|
||||||
..NativeOptions::default()
|
..NativeOptions::default()
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user