1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 21:30:03 -04:00

Remove viewport_id and parent_viewport_id from Window::show arguments because can be accessed from Context::get_viewport_id and Context::get_parent_viewport_id

This commit is contained in:
Konkitoman
2023-08-03 19:53:17 +03:00
parent 7f791f4bf9
commit 1448c5047f
30 changed files with 81 additions and 81 deletions

View File

@@ -55,7 +55,7 @@ impl eframe::App for MyApp {
egui::Window::new("Do you want to quit?")
.collapsible(false)
.resizable(false)
.show(ctx, move |ui, _, _| {
.show(ctx, move |ui| {
ui.horizontal(|ui| {
if ui.button("Cancel").clicked() {
data.write().unwrap().show_confirmation_dialog = false;

View File

@@ -53,7 +53,7 @@ impl ThreadState {
let title = self.data.read().unwrap().title.clone();
egui::Window::new(title)
.default_pos(pos)
.show(ctx, move |ui, _, _| {
.show(ctx, move |ui| {
let data = &mut *clone.data.write().unwrap();
ui.horizontal(|ui| {
ui.label("Your name: ");
@@ -147,10 +147,11 @@ impl eframe::App for MyApp {
return;
}
let data = self.data.clone();
egui::Window::new("Main thread").show(ctx, move |ui, _, parent_id| {
egui::Window::new("Main thread").show(ctx, move |ui| {
if ui.button("Spawn another thread").clicked() {
data.write().unwrap().spawn_thread();
ui.ctx().request_repaint_viewport(parent_id);
ui.ctx()
.request_repaint_viewport(ui.ctx().get_parent_viewport_id());
}
});

View File

@@ -61,15 +61,16 @@ fn main() {
}
egui::CollapsingHeader::new("Show Test1").show(ui, |ui| {
egui::Window::new("Test1").embedded(&mut embedded1).show(
ctx,
|ui, id, parent_id| {
egui::Window::new("Test1")
.embedded(&mut embedded1)
.show(ctx, |ui| {
ui.label(format!("Frame: {}", ui.ctx().frame_nr()));
let mut embedded = ui.data_mut(|data| {
*data.get_temp_mut_or(Id::new("Test1").with("_is_embedded"), true)
});
if ui.checkbox(&mut embedded, "Should embedd?").clicked() {
ui.ctx().request_repaint_viewport(parent_id);
ui.ctx()
.request_repaint_viewport(ui.ctx().get_parent_viewport_id());
}
ui.data_mut(|data| {
data.insert_persisted(Id::new("Test1").with("_embedded"), embedded)
@@ -84,8 +85,11 @@ fn main() {
ctx.get_viewport_id()
));
if ui.button("Drag").is_pointer_button_down_on() {
if id != parent_id {
ctx.viewport_command(id, egui::window::ViewportCommand::Drag)
if ctx.get_viewport_id() != ctx.get_parent_viewport_id() {
ctx.viewport_command(
ctx.get_viewport_id(),
egui::window::ViewportCommand::Drag,
)
} else {
ctx.memory_mut(|mem| {
mem.set_dragged_id(
@@ -94,17 +98,17 @@ fn main() {
});
}
}
},
);
});
});
egui::CollapsingHeader::new("Shout Test2").show(ui, |ui| {
egui::Window::new("Test2").show(ctx, move |ui, id, parent_id| {
egui::Window::new("Test2").show(ctx, move |ui| {
ui.label(format!("Frame: {}", ui.ctx().frame_nr()));
let mut embedded = ui.data_mut(|data| {
*data.get_temp_mut_or(Id::new("Test2").with("_embedded"), true)
});
if ui.checkbox(&mut embedded, "Should embedd?").clicked() {
ui.ctx().request_repaint_viewport(parent_id);
ui.ctx()
.request_repaint_viewport(ui.ctx().get_parent_viewport_id());
}
ui.data_mut(|data| {
data.insert_persisted(Id::new("Test2").with("_embedded"), embedded)
@@ -119,18 +123,22 @@ fn main() {
));
if ui.button("Drag").is_pointer_button_down_on() {
ctx.viewport_command(id, egui::window::ViewportCommand::Drag)
ctx.viewport_command(
ctx.get_viewport_id(),
egui::window::ViewportCommand::Drag,
)
}
});
});
egui::CollapsingHeader::new("Shout Test3").show(ui, |ui| {
egui::Window::new("Test3").show(ctx, move |ui, id, parent_id| {
egui::Window::new("Test3").show(ctx, move |ui| {
ui.label(format!("Frame: {}", ui.ctx().frame_nr()));
let mut embedded = ui.data_mut(|data| {
*data.get_temp_mut_or(Id::new("Test3").with("_embedded"), true)
});
if ui.checkbox(&mut embedded, "Should embedd?").clicked() {
ui.ctx().request_repaint_viewport(parent_id);
ui.ctx()
.request_repaint_viewport(ui.ctx().get_parent_viewport_id());
}
ui.data_mut(|data| {
data.insert_persisted(Id::new("Test3").with("_embedded"), embedded)
@@ -142,7 +150,10 @@ fn main() {
));
if ui.button("Drag").is_pointer_button_down_on() {
ctx.viewport_command(id, egui::window::ViewportCommand::Drag)
ctx.viewport_command(
ctx.get_viewport_id(),
egui::window::ViewportCommand::Drag,
)
}
});
});