mirror of
https://github.com/emilk/egui.git
synced 2026-06-28 07:23:13 -04:00
Some more work now stuff is rendered corectly
This commit is contained in:
@@ -980,7 +980,6 @@ mod glow_integration {
|
||||
let window = &mut *window.write();
|
||||
if let Some(winit_state) = &mut window.egui_winit {
|
||||
if let Some(win) = window.window.clone() {
|
||||
println!("Render beagin!");
|
||||
let win = win.read();
|
||||
let input = winit_state.take_egui_input(&win);
|
||||
let output =
|
||||
@@ -1026,7 +1025,6 @@ mod glow_integration {
|
||||
"failed to get current context to swap buffers",
|
||||
));
|
||||
}
|
||||
println!("Should render sync");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ struct ContextImpl {
|
||||
frame_stack: Vec<(u64, u64)>,
|
||||
|
||||
// The output of a frame:
|
||||
graphics: GraphicLayers,
|
||||
graphics: HashMap<u64, GraphicLayers>,
|
||||
output: PlatformOutput,
|
||||
|
||||
paint_stats: PaintStats,
|
||||
@@ -241,6 +241,17 @@ impl ContextImpl {
|
||||
viewport_id: u64,
|
||||
parent_viewport_id: u64,
|
||||
) {
|
||||
// This is used to pause the last frame
|
||||
if !self.frame_stack.is_empty() {
|
||||
let viewport_id = self.get_viewport_id();
|
||||
println!("Pause: {viewport_id}");
|
||||
self.layer_rects_prev_viewports.insert(
|
||||
viewport_id,
|
||||
std::mem::take(&mut self.layer_rects_this_frame),
|
||||
);
|
||||
self.memory.pause_frame(viewport_id);
|
||||
}
|
||||
|
||||
self.frame_stack.push((viewport_id, parent_viewport_id));
|
||||
self.repaint.start_frame(self.get_viewport_id());
|
||||
|
||||
@@ -581,7 +592,7 @@ impl Context {
|
||||
/// Read-write access to [`GraphicLayers`], where painted [`crate::Shape`]s are written to.
|
||||
#[inline]
|
||||
pub(crate) fn graphics_mut<R>(&self, writer: impl FnOnce(&mut GraphicLayers) -> R) -> R {
|
||||
self.write(move |ctx| writer(&mut ctx.graphics))
|
||||
self.write(move |ctx| writer(ctx.graphics.entry(ctx.get_viewport_id()).or_default()))
|
||||
}
|
||||
|
||||
/// Read-only access to [`PlatformOutput`].
|
||||
@@ -1459,7 +1470,22 @@ impl Context {
|
||||
})
|
||||
});
|
||||
|
||||
self.write(|ctx| ctx.frame_stack.pop());
|
||||
// This is used to resume the last frame!
|
||||
let is_last = self.write(|ctx| {
|
||||
ctx.frame_stack.pop();
|
||||
ctx.frame_stack.is_empty()
|
||||
});
|
||||
if !is_last {
|
||||
let viewport_id = self.get_viewport_id();
|
||||
println!("Resume: {viewport_id}");
|
||||
self.write(|ctx| {
|
||||
ctx.layer_rects_prev_frame = ctx
|
||||
.layer_rects_prev_viewports
|
||||
.remove(&viewport_id)
|
||||
.unwrap_or_default();
|
||||
ctx.memory.resume_frame(viewport_id)
|
||||
});
|
||||
}
|
||||
FullOutput {
|
||||
platform_output,
|
||||
repaint_after,
|
||||
@@ -1471,7 +1497,13 @@ impl Context {
|
||||
}
|
||||
|
||||
fn drain_paint_lists(&self) -> Vec<ClippedShape> {
|
||||
self.write(|ctx| ctx.graphics.drain(ctx.memory.areas.order()).collect())
|
||||
self.write(|ctx| {
|
||||
ctx.graphics
|
||||
.entry(ctx.get_viewport_id())
|
||||
.or_default()
|
||||
.drain(ctx.memory.areas.order())
|
||||
.collect()
|
||||
})
|
||||
}
|
||||
|
||||
/// Tessellate the given shapes into triangle meshes.
|
||||
|
||||
@@ -385,6 +385,13 @@ impl Memory {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn pause_frame(&mut self, viewport_id: u64) {
|
||||
self.interactions
|
||||
.insert(viewport_id, std::mem::take(&mut self.interaction));
|
||||
self.viewports_areas
|
||||
.insert(viewport_id, std::mem::take(&mut self.areas));
|
||||
}
|
||||
|
||||
pub(crate) fn end_frame(
|
||||
&mut self,
|
||||
input: &InputState,
|
||||
@@ -403,6 +410,11 @@ impl Memory {
|
||||
self.viewports_areas.retain(|id, _| viewports.contains(id));
|
||||
}
|
||||
|
||||
pub(crate) fn resume_frame(&mut self, viewport_id: u64) {
|
||||
self.interaction = self.interactions.remove(&viewport_id).unwrap();
|
||||
self.areas = self.viewports_areas.remove(&viewport_id).unwrap();
|
||||
}
|
||||
|
||||
/// Top-most layer at the given position.
|
||||
pub fn layer_id_at(&self, pos: Pos2, resize_interact_radius_side: f32) -> Option<LayerId> {
|
||||
self.areas.layer_id_at(pos, resize_interact_radius_side)
|
||||
|
||||
@@ -8,6 +8,9 @@ fn main() {
|
||||
|
||||
let mut to_repair = false;
|
||||
|
||||
let mut show = false;
|
||||
let mut value = 0.0;
|
||||
|
||||
let _ = eframe::run_simple_native(
|
||||
"Viewports Examples",
|
||||
NativeOptions {
|
||||
@@ -35,10 +38,21 @@ fn main() {
|
||||
ui.label("Parent Viewport ID: ");
|
||||
ui.label(format!("{parent_viewport_id}"))
|
||||
});
|
||||
ui.checkbox(&mut show, "Show");
|
||||
ui.add(
|
||||
egui::widgets::DragValue::new(&mut value)
|
||||
.clamp_range(-10..=10)
|
||||
.speed(0.1),
|
||||
);
|
||||
})
|
||||
},
|
||||
);
|
||||
|
||||
if show {
|
||||
ui.label("Is shown!");
|
||||
ui.label(format!("Value: {value}"));
|
||||
}
|
||||
|
||||
egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
|
||||
egui::Window::new("Test1").show(ctx, move |ui, id, parent_id| {
|
||||
ui.label(format!("Frame: {}", ui.ctx().frame_nr()));
|
||||
|
||||
Reference in New Issue
Block a user