feat(block): support `align-content` along the block axis (#959)
1//! Style types for Block layout
2use crate::style::AlignContent;
3use crate::{CoreStyle, Style};
4
5/// The set of styles required for a Block layout container
6pub trait BlockContainerStyle: CoreStyle {
7 /// Defines which row in the grid the item should start and end at
8 #[inline(always)]
9 fn text_align(&self) -> TextAlign {
10 Style::<Self::CustomIdent>::DEFAULT.text_align
11 }
12
13 /// How children of this block container are aligned in the block (cross) axis
14 #[inline(always)]
15 fn align_content(&self) -> Option<AlignContent> {
16 Style::<Self::CustomIdent>::DEFAULT.align_content
17 }
18}
19
20/// The set of styles required for a Block layout item (child of a Block container)
21pub trait BlockItemStyle: CoreStyle {
22 /// Whether the item is a table. Table children are handled specially in block layout.
23 #[inline(always)]
24 fn is_table(&self) -> bool {
25 false
26 }
27
28 /// Whether the item is a floated
29 #[cfg(feature = "float_layout")]
30 #[inline(always)]
31 fn float(&self) -> super::Float {
32 super::Float::None
33 }
34
35 /// Whether the item is a floated
36 #[cfg(feature = "float_layout")]
37 #[inline(always)]
38 fn clear(&self) -> super::Clear {
39 super::Clear::None
40 }
41}
42
43/// Used by block layout to implement the legacy behaviour of `<center>` and `<div align="left | right | center">`
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
45#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
46pub enum TextAlign {
47 /// No special legacy text align behaviour.
48 #[default]
49 Auto,
50 /// Corresponds to `-webkit-left` or `-moz-left` in browsers
51 LegacyLeft,
52 /// Corresponds to `-webkit-right` or `-moz-right` in browsers
53 LegacyRight,
54 /// Corresponds to `-webkit-center` or `-moz-center` in browsers
55 LegacyCenter,
56}
57
58#[cfg(feature = "parse")]
59crate::util::parse::impl_parse_for_keyword_enum!(TextAlign,
60 "auto" => Auto,
61 "-webkit-left" => LegacyLeft,
62 "-webkit-right" => LegacyRight,
63 "-webkit-center" => LegacyCenter,
64);