ui::testing::TestRenderer¶
Header: winui/testing/TestRenderer.hpp.
Derives from ui::Renderer.
Renderer test double that records every draw call as a RenderCommand instead of painting.
This is the headless testing boundary: any Element can render() into it without a native window, a GPU or a desktop session, and the resulting command stream is deterministic. Each override appends exactly one command of the matching alternative; images and SVGs are recorded by their natural size only, never their pixels. render/Describe.hpp turns the stream into the text used by the semantic golden files.
Example:
ui::ButtonControl button{"Hello"};
ui::testing::TestRenderer renderer;
button.render(renderer); // Theme::default_light() by default
REQUIRE(renderer.count() == 3); // background, elevation border, label
REQUIRE(std::holds_alternative<ui::FillRoundedRect>(renderer.commands[0]));
REQUIRE(renderer.count_of<ui::DrawTextRun>() == 1);
REQUIRE(std::get<ui::DrawTextRun>(renderer.commands[2]).text == "Hello");
renderer.clear(); // reuse for the next frame
commands¶
Every recorded command, in draw order. Public so tests can index and std::get directly.
scale¶
What device_scale() reports, 1 by default: set it to test a mark drawn per device pixel at another DPI (1.5 for 144 DPI).
TestRenderer¶
TestRenderer¶
TestRenderer¶
operator=¶
operator=¶
~TestRenderer¶
fill_rounded_rect¶
Records a FillRoundedRect.
stroke_rounded_rect¶
void stroke_rounded_rect(const Rect& bounds, float radius, const Color& color, float stroke_width) override
Records a StrokeRoundedRect.
draw_text¶
void draw_text(std::string_view text, const Rect& bounds, const Color& color, const TextStyle& style) override
Records a DrawTextRun, copying text into an owned string.
fill_rounded_rect_gradient¶
void fill_rounded_rect_gradient(const Rect& bounds, float radius, const LinearGradientBrush& brush) override
Records a FillRoundedRectGradient.
stroke_rounded_rect_gradient¶
void stroke_rounded_rect_gradient(const Rect& bounds, float radius, const LinearGradientBrush& brush, float extent_px, float stroke_width) override
Records a StrokeRoundedRectGradient.
stroke_line¶
Records a StrokeLine.
stroke_wavy_line¶
void stroke_wavy_line(Point from, Point to, const Color& color, float stroke_width, float amplitude, float wavelength) override
Records a StrokeWavyLine (the spelling squiggle).
fill_polygon¶
Records the FillPolygon as-is.
stroke_polyline¶
Records the StrokePolyline as-is.
draw_geometry¶
Records the DrawGeometry as-is.
push_clip¶
Records a PushClip.
pop_clip¶
Records a PopClip.
push_clip_ellipse¶
Records a PushClipEllipse.
push_clip_rounded_rect¶
Records a PushClipRoundedRect.
push_opacity_layer¶
Records a PushOpacityLayer.
pop_opacity_layer¶
Records a PopOpacityLayer.
push_matrix¶
Records a PushTransform decomposed as (m11, offset {dx, dy}, m22, m12, m21).
pop_transform¶
Records a PopTransform.
set_rasterization¶
Records the SetRasterization policy as-is.
device_scale¶
Returns scale.
fill_ellipse¶
Records a FillEllipse.
stroke_ellipse¶
void stroke_ellipse(Point center, float radius_x, float radius_y, const Color& color, float stroke_width) override
Records a StrokeEllipse.
fill_rect_pattern¶
void fill_rect_pattern(const Rect& bounds, Pattern pattern, const Color& fg, const Color& bg) override
Records a FillRectPattern.
draw_image_nine_slice¶
void draw_image_nine_slice(const std::string& image_name, const Rect& bounds, const Thickness& slice_margins) override
Records a DrawImageNineSlice by image name.
draw_image¶
Records a DrawImage carrying the image's pixel size, not its pixels.
draw_image_rect¶
Records a DrawImageRect carrying the image's pixel size and source rect.
draw_svg¶
Records a DrawSvg carrying the document's natural size.
clear¶
Drops every recorded command, e.g. between two render() passes.
count¶
Number of recorded commands (commands.size()).
count_of¶
How many recorded commands hold alternative T (e.g. count_of<DrawTextRun>()).