Skip to content

Commit 5865777

Browse files
committed
Make test image size independent of tests
1 parent 5847b77 commit 5865777

13 files changed

+51
-55
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

tests/egui_tests/tests/test_widgets.rs

+27-31
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use egui::load::SizedTexture;
22
use egui::{
33
include_image, Align, Button, Color32, ColorImage, Direction, DragValue, Event, Grid, Layout,
4-
PointerButton, Pos2, Rect, Response, Sense, Slider, Stroke, StrokeKind, TextWrapMode,
5-
TextureHandle, TextureOptions, Ui, UiBuilder, Vec2, Widget,
4+
PointerButton, Pos2, Response, Slider, Stroke, StrokeKind, TextWrapMode, TextureHandle,
5+
TextureOptions, Ui, UiBuilder, Vec2, Widget,
66
};
77
use egui_kittest::kittest::{by, Node, Queryable};
88
use egui_kittest::{Harness, SnapshotResult, SnapshotResults};
@@ -155,32 +155,29 @@ fn test_widget_layout(name: &str, mut w: impl FnMut(&mut Ui) -> Response) -> Sna
155155
TextWrapMode::Truncate,
156156
TextWrapMode::Wrap,
157157
];
158-
Grid::new("wrapping").show(ui, |ui| {
159-
for mode in &modes {
160-
ui.label(format!("{mode:?}"));
161-
}
162-
ui.end_row();
163-
164-
for mode in &modes {
165-
let rect = Rect::from_min_size(ui.cursor().min, wrap_test_size);
158+
Grid::new("wrapping")
159+
.spacing(Vec2::new(test_size.x / 2.0, 4.0))
160+
.show(ui, |ui| {
161+
for mode in &modes {
162+
ui.label(format!("{mode:?}"));
163+
}
164+
ui.end_row();
166165

167-
ui.scope_builder(UiBuilder::new().max_rect(rect), |ui| {
168-
ui.style_mut().wrap_mode = Some(*mode);
166+
for mode in &modes {
167+
let (_, rect) = ui.allocate_space(wrap_test_size);
169168

170-
w(ui);
169+
let mut child_ui = ui.new_child(UiBuilder::new().max_rect(rect));
170+
child_ui.style_mut().wrap_mode = Some(*mode);
171+
w(&mut child_ui);
171172

172-
// Ensure we always take the full height
173-
ui.allocate_rect(rect, Sense::hover());
174-
});
175-
176-
ui.painter().rect_stroke(
177-
rect,
178-
0.0,
179-
Stroke::new(1.0, Color32::WHITE),
180-
StrokeKind::Outside,
181-
);
182-
}
183-
});
173+
ui.painter().rect_stroke(
174+
rect,
175+
0.0,
176+
Stroke::new(1.0, Color32::WHITE),
177+
StrokeKind::Outside,
178+
);
179+
}
180+
});
184181
}
185182

186183
ui.heading("Layout");
@@ -209,12 +206,11 @@ fn test_widget_layout(name: &str, mut w: impl FnMut(&mut Ui) -> Response) -> Sna
209206
main_wrap: false,
210207
};
211208

212-
let rect = Rect::from_min_size(ui.cursor().min, test_size);
213-
ui.scope_builder(UiBuilder::new().layout(layout).max_rect(rect), |ui| {
214-
w(ui);
215-
// Ensure we always take the full height
216-
ui.allocate_rect(rect, Sense::hover());
217-
});
209+
let (_, rect) = ui.allocate_space(test_size);
210+
211+
let mut child_ui = ui.new_child(UiBuilder::new().layout(layout).max_rect(rect));
212+
w(&mut child_ui);
213+
218214
ui.painter().rect_stroke(
219215
rect,
220216
0.0,

0 commit comments

Comments
 (0)