Add close_button option to test_viewports (#4907)
This make the test excercise the window recreation logic, that resulted in several bugs - see #4862 Adds a check box that turns the close button on and off for child windows
This commit is contained in:
parent
9a1e358a14
commit
06f88e12b0
|
|
@ -61,7 +61,7 @@ impl ViewportState {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn show(vp_state: Arc<RwLock<Self>>, ctx: &egui::Context) {
|
pub fn show(vp_state: Arc<RwLock<Self>>, ctx: &egui::Context, close_button: bool) {
|
||||||
if !vp_state.read().visible {
|
if !vp_state.read().visible {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -71,6 +71,7 @@ impl ViewportState {
|
||||||
|
|
||||||
let viewport = ViewportBuilder::default()
|
let viewport = ViewportBuilder::default()
|
||||||
.with_title(&title)
|
.with_title(&title)
|
||||||
|
.with_close_button(close_button)
|
||||||
.with_inner_size([500.0, 500.0]);
|
.with_inner_size([500.0, 500.0]);
|
||||||
|
|
||||||
if immediate {
|
if immediate {
|
||||||
|
|
@ -80,7 +81,7 @@ impl ViewportState {
|
||||||
vp_state.visible = false;
|
vp_state.visible = false;
|
||||||
}
|
}
|
||||||
show_as_popup(ctx, class, &title, vp_id.into(), |ui: &mut egui::Ui| {
|
show_as_popup(ctx, class, &title, vp_id.into(), |ui: &mut egui::Ui| {
|
||||||
generic_child_ui(ui, &mut vp_state);
|
generic_child_ui(ui, &mut vp_state, close_button);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -101,7 +102,7 @@ impl ViewportState {
|
||||||
ui.label(format!("Callback has been reused {current_count} times"));
|
ui.label(format!("Callback has been reused {current_count} times"));
|
||||||
*count.write() += 1;
|
*count.write() += 1;
|
||||||
|
|
||||||
generic_child_ui(ui, &mut vp_state);
|
generic_child_ui(ui, &mut vp_state, close_button);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
@ -118,6 +119,7 @@ impl ViewportState {
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
top: Vec<Arc<RwLock<ViewportState>>>,
|
top: Vec<Arc<RwLock<ViewportState>>>,
|
||||||
|
close_button: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for App {
|
impl Default for App {
|
||||||
|
|
@ -151,6 +153,7 @@ impl Default for App {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
close_button: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -169,8 +172,8 @@ impl eframe::App for App {
|
||||||
}
|
}
|
||||||
ctx.set_embed_viewports(embed_viewports);
|
ctx.set_embed_viewports(embed_viewports);
|
||||||
}
|
}
|
||||||
|
ui.checkbox(&mut self.close_button, "with close button");
|
||||||
generic_ui(ui, &self.top);
|
generic_ui(ui, &self.top, self.close_button);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +194,7 @@ fn show_as_popup(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generic_child_ui(ui: &mut egui::Ui, vp_state: &mut ViewportState) {
|
fn generic_child_ui(ui: &mut egui::Ui, vp_state: &mut ViewportState, close_button: bool) {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
ui.label("Title:");
|
ui.label("Title:");
|
||||||
if ui.text_edit_singleline(&mut vp_state.title).changed() {
|
if ui.text_edit_singleline(&mut vp_state.title).changed() {
|
||||||
|
|
@ -203,10 +206,10 @@ fn generic_child_ui(ui: &mut egui::Ui, vp_state: &mut ViewportState) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
generic_ui(ui, &vp_state.children);
|
generic_ui(ui, &vp_state.children, close_button);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {
|
fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>], close_button: bool) {
|
||||||
let container_id = ui.id();
|
let container_id = ui.id();
|
||||||
|
|
||||||
let ctx = ui.ctx().clone();
|
let ctx = ui.ctx().clone();
|
||||||
|
|
@ -290,7 +293,7 @@ fn generic_ui(ui: &mut egui::Ui, children: &[Arc<RwLock<ViewportState>>]) {
|
||||||
*visible
|
*visible
|
||||||
};
|
};
|
||||||
if visible {
|
if visible {
|
||||||
ViewportState::show(child.clone(), &ctx);
|
ViewportState::show(child.clone(), &ctx, close_button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue