Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screenshots to documentation #832

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions masonry/src/testing/screenshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,42 @@
use image::{GenericImageView as _, RgbImage};
use nv_flip::{FlipImageRgb8, DEFAULT_PIXELS_PER_DEGREE};

#[cfg(docsrs)]
#[doc(hidden)]
#[macro_export]
macro_rules! include_screenshot {
($path:literal $(, $caption:literal)? $(,)?) => {
concat!(
"![", $($caption,)? "]",
"(", "https://raw.githubusercontent.com/linebender/xilem/",
"masonry-v", env!("CARGO_PKG_VERSION"), "/masonry/src/", $path,
")",
)
};
}

#[cfg(not(docsrs))]
#[doc(hidden)]
#[macro_export]
/// Macro used to create markdown img tag, with a different URL when uploading to docs.rs.
macro_rules! include_screenshot {
($path:literal $(, $caption:literal)? $(,)?) => {
concat!(
"![", $($caption,)? "]",
"(", env!("CARGO_MANIFEST_DIR"), "/src/", $path, ")",
)
};
}

// [!Image alt](link)

// https://raw.githubusercontent.com/linebender/xilem/7f40266bd831c3f8e715bf7af325e3a53e046612/masonry/src/widget/screenshots/masonry__widget__align__tests__centered.png

#[cfg(FALSE)]
include_screenshot!("hello");

#[cfg_attr(docsrs, doc = r" This is a doc comment.")]
#[cfg_attr(not(docsrs), doc = r" This is a doc comment.")]
pub(crate) fn get_image_diff(ref_image: &RgbImage, new_image: &RgbImage) -> Option<RgbImage> {
assert_eq!(
(ref_image.width(), ref_image.height()),
Expand Down
3 changes: 3 additions & 0 deletions masonry/src/widget/align.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tracing::{trace_span, Span};
use vello::Scene;

use crate::contexts::AccessCtx;
use crate::include_screenshot;
use crate::paint_scene_helpers::UnitPoint;
use crate::widget::WidgetPod;
use crate::{
Expand All @@ -24,6 +25,8 @@ use crate::{
// TODO - Have child widget type as generic argument

/// A widget that aligns its child.
///
#[doc = include_screenshot!("widget/screenshots/masonry__widget__align__tests__right.png", "Right-aligned label")]
pub struct Align {
align: UnitPoint,
child: WidgetPod<Box<dyn Widget>>,
Expand Down
Loading