mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -04:00
Add Harness::new_ui, Harness::fit_contents (#5301)
This adds a `Harness::new_ui`, which accepts a Ui closure and shows the ui in a central panel. One big benefit is that this allows us to add a fit_contents method that can run the ui closure with a sizing pass and resize the "screen" based on the content size. I also used this to add a snapshot test for the rendering_test at different scales.
This commit is contained in:
@@ -290,7 +290,7 @@ fn doc_link_label_with_crate<'a>(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::View;
|
||||
use egui::{CentralPanel, Context, Vec2};
|
||||
use egui::Vec2;
|
||||
use egui_kittest::Harness;
|
||||
|
||||
#[test]
|
||||
@@ -300,15 +300,12 @@ mod tests {
|
||||
date: Some(chrono::NaiveDate::from_ymd_opt(2024, 1, 1).unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
let app = |ctx: &Context| {
|
||||
CentralPanel::default().show(ctx, |ui| {
|
||||
demo.ui(ui);
|
||||
});
|
||||
};
|
||||
let harness = Harness::builder()
|
||||
let mut harness = Harness::builder()
|
||||
.with_pixels_per_point(2.0)
|
||||
.with_size(Vec2::new(380.0, 550.0))
|
||||
.with_dpi(2.0)
|
||||
.build(app);
|
||||
.build_ui(|ui| demo.ui(ui));
|
||||
|
||||
harness.fit_contents();
|
||||
|
||||
harness.wgpu_snapshot("widget_gallery");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user