Skip to content

Commit f94c162

Browse files
committed
Add screenshots to all widgets
Remove cruft
1 parent f661947 commit f94c162

14 files changed

+32
-10
lines changed

masonry/src/testing/screenshots.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ macro_rules! include_screenshot {
2020
};
2121
}
2222

23+
// TODO:
24+
// - Check whether the docs.rs trick actually works.
25+
// - Check whether this method will work with cargo rdme.
26+
// - Make better screenshots than the ones we currently use.
27+
2328
#[cfg(not(docsrs))]
2429
#[doc(hidden)]
2530
#[macro_export]
@@ -33,13 +38,6 @@ macro_rules! include_screenshot {
3338
};
3439
}
3540

36-
// [!Image alt](link)
37-
38-
// https://raw.githubusercontent.com/linebender/xilem/7f40266bd831c3f8e715bf7af325e3a53e046612/masonry/src/widget/screenshots/masonry__widget__align__tests__centered.png
39-
40-
#[cfg(FALSE)]
41-
include_screenshot!("hello");
42-
4341
#[cfg_attr(docsrs, doc = r" This is a doc comment.")]
4442
#[cfg_attr(not(docsrs), doc = r" This is a doc comment.")]
4543
pub(crate) fn get_image_diff(ref_image: &RgbImage, new_image: &RgbImage) -> Option<RgbImage> {

masonry/src/widget/align.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use tracing::{trace_span, Span};
1414
use vello::Scene;
1515

1616
use crate::contexts::AccessCtx;
17-
use crate::include_screenshot;
1817
use crate::paint_scene_helpers::UnitPoint;
1918
use crate::widget::WidgetPod;
2019
use crate::{
@@ -26,7 +25,7 @@ use crate::{
2625

2726
/// A widget that aligns its child.
2827
///
29-
#[doc = include_screenshot!("widget/screenshots/masonry__widget__align__tests__right.png", "Right-aligned label")]
28+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__align__tests__right.png", "Right-aligned label")]
3029
pub struct Align {
3130
align: UnitPoint,
3231
child: WidgetPod<Box<dyn Widget>>,

masonry/src/widget/button.rs

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const LABEL_INSETS: Insets = Insets::uniform_xy(8., 2.);
2626
/// A button with a text label.
2727
///
2828
/// Emits [`Action::ButtonPressed`] when pressed.
29+
///
30+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__button__tests__hello.png", "Button with text label")]
2931
pub struct Button {
3032
label: WidgetPod<Label>,
3133
}

masonry/src/widget/checkbox.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::{
1919
};
2020

2121
/// A checkbox that can be toggled.
22+
///
23+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__checkbox__tests__hello_checked.png", "Checkbox with checked state")]
2224
pub struct Checkbox {
2325
checked: bool,
2426
label: WidgetPod<Label>,

masonry/src/widget/flex.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::{
1919
/// A container with either horizontal or vertical layout.
2020
///
2121
/// This widget is the foundation of most layouts, and is highly configurable.
22+
///
23+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__flex__tests__col_main_axis_spaceAround.png", "Flex column with multiple labels")]
2224
pub struct Flex {
2325
direction: Axis,
2426
cross_alignment: CrossAxisAlignment,

masonry/src/widget/grid.rs

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ use crate::{
1313
QueryCtx, Size, TextEvent, Widget, WidgetId, WidgetPod,
1414
};
1515

16+
/// A widget that arranges its children in a grid.
17+
///
18+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__grid__tests__with_changed_spacing.png", "Grid with buttons of various sizes")]
1619
pub struct Grid {
1720
children: Vec<Child>,
1821
grid_width: i32,

masonry/src/widget/label.rs

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ pub enum LineBreaking {
4242
///
4343
/// This is useful for creating interactive widgets which internally
4444
/// need support for displaying text, such as a button.
45+
///
46+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__label__tests__styled_label.png", "Styled label")]
4547
pub struct Label {
4648
text_layout: Layout<BrushIndex>,
4749
accessibility: LayoutAccessibility,

masonry/src/widget/progress_bar.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use crate::{
2020
use super::{Label, LineBreaking, WidgetPod};
2121

2222
/// A progress bar.
23+
///
24+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__progress_bar__tests__25_percent_progressbar.png", "25% progress bar")]
2325
pub struct ProgressBar {
2426
/// A value in the range `[0, 1]` inclusive, where 0 is 0% and 1 is 100% complete.
2527
///

masonry/src/widget/prose.rs

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ const PROSE_PADDING: Padding = Padding::horizontal(2.0);
3838
/// as it enables users to copy/paste from the text.
3939
///
4040
/// This widget has no actions.
41+
///
42+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__prose__tests__prose_alignment_flex.png", "Multiple lines with different alignments")]
4143
pub struct Prose {
4244
text: WidgetPod<TextArea<false>>,
4345

masonry/src/widget/scroll_bar.rs

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ use crate::{
2424
// - Document names
2525
// - Document invariants
2626

27+
/// A scrollbar.
28+
///
29+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__scroll_bar__tests__scrollbar_default.png", "Vertical scrollbar")]
2730
pub struct ScrollBar {
2831
axis: Axis,
2932
pub(crate) cursor_progress: f64,

masonry/src/widget/sized_box.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub struct Padding {
5656
/// If not given a child, `SizedBox` will try to size itself as close to the specified height
5757
/// and width as possible given the parent's constraints. If height or width is not set,
5858
/// it will be treated as zero.
59+
///
60+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__sized_box__tests__label_box_with_outer_padding.png", "Box with blue border, pink background and a child label")]
5961
pub struct SizedBox {
6062
child: Option<WidgetPod<Box<dyn Widget>>>,
6163
width: Option<f64>,

masonry/src/widget/spinner.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ use crate::{
2424
/// that has a fixed width and height.
2525
///
2626
/// [`SizedBox`]: crate::widget::SizedBox
27+
///
28+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__spinner__tests__spinner_init.png", "Spinner frame")]
2729
pub struct Spinner {
2830
t: f64,
2931
color: Color,

masonry/src/widget/split.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use crate::{
1919
};
2020

2121
// TODO - Have child widget type as generic argument
22-
2322
/// A container containing two other widgets, splitting the area either horizontally or vertically.
23+
///
24+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__split__tests__columns.png", "Split panel with two labels")]
2425
pub struct Split {
2526
split_axis: Axis,
2627
split_point_chosen: f64,

masonry/src/widget/zstack.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub enum ChildAlignment {
2929
///
3030
/// The alignment of how the children are placed can be specified globally using [`with_alignment`][Self::with_alignment].
3131
/// Each child can additionally override the global alignment using [`ChildAlignment::SelfAligned`].
32+
///
33+
#[doc = crate::include_screenshot!("widget/screenshots/masonry__widget__zstack__tests__zstack_alignment_default.png", "Red foreground widget on top of blue background widget")]
3234
#[derive(Default)]
3335
pub struct ZStack {
3436
children: Vec<Child>,

0 commit comments

Comments
 (0)