mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Allow masking widgets in kittest snapshots (#7467)
* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE> * [ ] I have followed the instructions in the PR template
This commit is contained in:
@@ -28,8 +28,9 @@ pub use builder::*;
|
||||
pub use node::*;
|
||||
pub use renderer::*;
|
||||
|
||||
use egui::epaint::{ClippedShape, RectShape};
|
||||
use egui::style::ScrollAnimation;
|
||||
use egui::{Key, Modifiers, Pos2, Rect, RepaintCause, Vec2, ViewportId};
|
||||
use egui::{Color32, Key, Modifiers, Pos2, Rect, RepaintCause, Shape, Vec2, ViewportId};
|
||||
use kittest::Queryable;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -556,6 +557,18 @@ impl<'a, State> Harness<'a, State> {
|
||||
self.key_combination_modifiers(modifiers, &[key]);
|
||||
}
|
||||
|
||||
/// Mask something. Useful for snapshot tests.
|
||||
///
|
||||
/// Call this _after_ [`Self::run`] and before [`Self::snapshot`].
|
||||
/// This will add a [`RectShape`] to the output shapes, for the current frame.
|
||||
/// Will be overwritten on the next call to [`Self::run`].
|
||||
pub fn mask(&mut self, rect: Rect) {
|
||||
self.output.shapes.push(ClippedShape {
|
||||
clip_rect: Rect::EVERYTHING,
|
||||
shape: Shape::Rect(RectShape::filled(rect, 0.0, Color32::MAGENTA)),
|
||||
});
|
||||
}
|
||||
|
||||
/// Render the last output to an image.
|
||||
///
|
||||
/// # Errors
|
||||
|
||||
Reference in New Issue
Block a user