use std::panic::Location;
use crate::tokens;
use crate::tree::*;
const RULE_WIDTH: f32 = 2.0;
const CONTENT_INDENT: f32 = RULE_WIDTH + tokens::SPACE_4;
#[track_caller]
pub fn blockquote<I, E>(children: I) -> El
where
I: IntoIterator<Item = E>,
E: Into<El>,
{
let loc = Location::caller();
let rule = El::new(Kind::Divider)
.at_loc(loc)
.width(Size::Fixed(RULE_WIDTH))
.height(Size::Fill(1.0))
.fill(tokens::BORDER);
let body = column(children)
.at_loc(loc)
.width(Size::Fill(1.0))
.height(Size::Hug)
.default_padding(Sides {
left: CONTENT_INDENT,
right: 0.0,
top: 0.0,
bottom: 0.0,
})
.default_gap(tokens::SPACE_3);
stack([rule, body])
.at_loc(loc)
.width(Size::Fill(1.0))
.height(Size::Hug)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::widgets::text::paragraph;
#[test]
fn blockquote_overlays_rule_and_indented_body_column() {
let q = blockquote([paragraph("Quoted prose")]);
assert_eq!(q.kind, Kind::Group);
assert_eq!(q.axis, Axis::Overlay);
assert_eq!(q.width, Size::Fill(1.0));
assert_eq!(q.children.len(), 2);
let rule = &q.children[0];
assert_eq!(rule.kind, Kind::Divider);
assert_eq!(rule.width, Size::Fixed(RULE_WIDTH));
assert_eq!(rule.height, Size::Fill(1.0));
assert_eq!(rule.fill, Some(tokens::BORDER));
let body = &q.children[1];
assert_eq!(body.kind, Kind::Group);
assert_eq!(body.axis, Axis::Column);
assert_eq!(body.width, Size::Fill(1.0));
assert_eq!(body.padding.left, CONTENT_INDENT);
assert_eq!(body.padding.top, 0.0);
assert_eq!(body.padding.right, 0.0);
assert_eq!(body.padding.bottom, 0.0);
assert_eq!(body.children.len(), 1);
}
#[test]
fn blockquote_padding_overrideable_at_call_site() {
let q = blockquote([paragraph("x")]).pl(0.0);
assert_eq!(q.padding.left, 0.0);
assert!(q.explicit_padding);
}
}