Skip to content

Commit 300503a

Browse files
committed
Add screenshots to documentation
Create include_screenshot macro
1 parent 8342d8f commit 300503a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

masonry/src/testing/screenshots.rs

+36
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66
use image::{GenericImageView as _, RgbImage};
77
use nv_flip::{FlipImageRgb8, DEFAULT_PIXELS_PER_DEGREE};
88

9+
#[cfg(docsrs)]
10+
#[doc(hidden)]
11+
#[macro_export]
12+
macro_rules! include_screenshot {
13+
($path:literal $(, $caption:literal)? $(,)?) => {
14+
concat!(
15+
"![", $($caption,)? "]",
16+
"(", "https://raw.githubusercontent.com/linebender/xilem/",
17+
"masonry-v", env!("CARGO_PKG_VERSION"), "/masonry/src/", $path,
18+
")",
19+
)
20+
};
21+
}
22+
23+
#[cfg(not(docsrs))]
24+
#[doc(hidden)]
25+
#[macro_export]
26+
/// Macro used to create markdown img tag, with a different URL when uploading to docs.rs.
27+
macro_rules! include_screenshot {
28+
($path:literal $(, $caption:literal)? $(,)?) => {
29+
concat!(
30+
"![", $($caption,)? "]",
31+
"(", env!("CARGO_MANIFEST_DIR"), "/src/", $path, ")",
32+
)
33+
};
34+
}
35+
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+
43+
#[cfg_attr(docsrs, doc = r" This is a doc comment.")]
44+
#[cfg_attr(not(docsrs), doc = r" This is a doc comment.")]
945
pub(crate) fn get_image_diff(ref_image: &RgbImage, new_image: &RgbImage) -> Option<RgbImage> {
1046
assert_eq!(
1147
(ref_image.width(), ref_image.height()),

masonry/src/widget/align.rs

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

1616
use crate::contexts::AccessCtx;
17+
use crate::include_screenshot;
1718
use crate::paint_scene_helpers::UnitPoint;
1819
use crate::widget::WidgetPod;
1920
use crate::{
@@ -24,6 +25,8 @@ use crate::{
2425
// TODO - Have child widget type as generic argument
2526

2627
/// A widget that aligns its child.
28+
///
29+
#[doc = include_screenshot!("widget/screenshots/masonry__widget__align__tests__right.png", "Right-aligned label")]
2730
pub struct Align {
2831
align: UnitPoint,
2932
child: WidgetPod<dyn Widget>,

0 commit comments

Comments
 (0)