1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-27 15:13:12 -04:00

Removed Context::set_current_rendering_viewport

Now we always need to say what viewport we rendering in Context::beagin or Context::run
This commit is contained in:
Konkitoman
2023-07-30 20:03:56 +03:00
parent 1f5d17cfcc
commit fd1c01cf1f
6 changed files with 22 additions and 21 deletions

View File

@@ -515,7 +515,7 @@ impl EpiIntegration {
self.frame.info.parent_viewport = parent_id;
// Run user code:
let full_output = self.egui_ctx.run(raw_input, |egui_ctx| {
let full_output = self.egui_ctx.run(raw_input, viewport_id, |egui_ctx| {
crate::profile_scope!("App::update");
app.update(egui_ctx, &mut self.frame, render.as_ref().map(|r| &***r));
});

View File

@@ -1062,7 +1062,6 @@ mod glow_integration {
app.clear_color(&integration.egui_ctx.style().visuals),
);
integration.egui_ctx.set_current_viewport_id(win.window_id);
egui::FullOutput {
platform_output,
repaint_after,
@@ -1786,7 +1785,6 @@ mod wgpu_integration {
};
{
let Some((viewport_id, (Some(window), Some(state), render, parent_viewport_id, _))) = windows_id.get(&window_id).and_then(|id|(windows.get_mut(id).map(|w|(*id, w)))) else{return vec![]};
integration.egui_ctx.set_current_viewport_id(viewport_id);
let _ = pollster::block_on(painter.set_window(viewport_id, Some(window)));

View File

@@ -219,7 +219,8 @@ struct ContextImpl {
}
impl ContextImpl {
fn begin_frame_mut(&mut self, mut new_raw_input: RawInput) {
fn begin_frame_mut(&mut self, mut new_raw_input: RawInput, viewport_id: u64) {
self.current_rendering_viewport = viewport_id;
self.repaint.start_frame(self.current_rendering_viewport);
if let Some(new_pixels_per_point) = self.memory.new_pixels_per_point.take() {
@@ -420,8 +421,13 @@ impl Context {
/// // handle full_output
/// ```
#[must_use]
pub fn run(&self, new_input: RawInput, run_ui: impl FnOnce(&Context)) -> FullOutput {
self.begin_frame(new_input);
pub fn run(
&self,
new_input: RawInput,
viewport_id: u64,
run_ui: impl FnOnce(&Context),
) -> FullOutput {
self.begin_frame(new_input, viewport_id);
run_ui(self);
self.end_frame()
}
@@ -443,8 +449,8 @@ impl Context {
/// let full_output = ctx.end_frame();
/// // handle full_output
/// ```
pub fn begin_frame(&self, new_input: RawInput) {
self.write(|ctx| ctx.begin_frame_mut(new_input));
pub fn begin_frame(&self, new_input: RawInput, viewport_id: u64) {
self.write(|ctx| ctx.begin_frame_mut(new_input, viewport_id));
}
}
@@ -1973,9 +1979,6 @@ impl Context {
use containers::window::ViewportBuilder;
/// # Windows
impl Context {
pub fn set_current_viewport_id(&self, viewport_id: u64) {
self.write(|ctx| ctx.current_rendering_viewport = viewport_id);
}
pub fn current_rendering_viewport(&self) -> u64 {
self.read(|ctx| ctx.current_rendering_viewport)
}

View File

@@ -555,7 +555,7 @@ pub type ViewportRender = dyn Fn(&Context, u64, u64) + Sync + Send;
pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), |ctx| {
let _ = ctx.run(Default::default(), 0, |ctx| {
run_ui(ctx);
});
}
@@ -564,7 +564,7 @@ pub fn __run_test_ctx(mut run_ui: impl FnMut(&Context)) {
pub fn __run_test_ui(mut add_contents: impl FnMut(&mut Ui)) {
let ctx = Context::default();
ctx.set_fonts(FontDefinitions::empty()); // prevent fonts from being loaded (save CPU time)
let _ = ctx.run(Default::default(), |ctx| {
let _ = ctx.run(Default::default(), 0, |ctx| {
crate::CentralPanel::default().show(ctx, |ui| {
add_contents(ui);
});

View File

@@ -13,7 +13,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
// The most end-to-end benchmark.
c.bench_function("demo_with_tessellate__realistic", |b| {
b.iter(|| {
let full_output = ctx.run(RawInput::default(), |ctx| {
let full_output = ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx);
});
ctx.tessellate(full_output.shapes)
@@ -22,13 +22,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("demo_no_tessellate", |b| {
b.iter(|| {
ctx.run(RawInput::default(), |ctx| {
ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx);
})
});
});
let full_output = ctx.run(RawInput::default(), |ctx| {
let full_output = ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx);
});
c.bench_function("demo_only_tessellate", |b| {
@@ -42,7 +42,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
let mut demo_windows = egui_demo_lib::DemoWindows::default();
c.bench_function("demo_full_no_tessellate", |b| {
b.iter(|| {
ctx.run(RawInput::default(), |ctx| {
ctx.run(RawInput::default(), 0, |ctx| {
demo_windows.ui(ctx);
})
});
@@ -51,7 +51,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
{
let ctx = egui::Context::default();
let _ = ctx.run(RawInput::default(), |ctx| {
let _ = ctx.run(RawInput::default(), 0, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| {
c.bench_function("label &str", |b| {
b.iter(|| {
@@ -69,7 +69,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
{
let ctx = egui::Context::default();
ctx.begin_frame(RawInput::default());
ctx.begin_frame(RawInput::default(), 0);
egui::CentralPanel::default().show(&ctx, |ui| {
c.bench_function("Painter::rect", |b| {

View File

@@ -68,7 +68,7 @@ fn test_egui_e2e() {
const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| {
let full_output = ctx.run(raw_input.clone(), 0, |ctx| {
demo_windows.ui(ctx);
});
let clipped_primitives = ctx.tessellate(full_output.shapes);
@@ -87,7 +87,7 @@ fn test_egui_zero_window_size() {
const NUM_FRAMES: usize = 5;
for _ in 0..NUM_FRAMES {
let full_output = ctx.run(raw_input.clone(), |ctx| {
let full_output = ctx.run(raw_input.clone(), 0, |ctx| {
demo_windows.ui(ctx);
});
let clipped_primitives = ctx.tessellate(full_output.shapes);