Repository: typst/typst
File: crates/typst/src/layout/frame.rs (Rust)

Code before:
    Transform,
};
use crate::model::{Destination, LinkElem};
use crate::syntax::Span;
use crate::text::TextItem;
use crate::utils::{LazyHash, Numeric};
use crate::visualize::{
    ellipse, styled_rect, Color, FixedStroke, Geometry, Image, Paint, Path, Shape,
};

/// A finished layout with items at fixed positions.
#[derive(Default, Clone, Hash)]
pub struct Frame {
    /// The size of the frame.
    size: Size,
    /// The baseline of the frame measured from the top. If this is `None`, the
    /// frame's implicit baseline is at the bottom.
    baseline: Option<Abs>,
    /// The items composing this layout.
    items: Arc<LazyHash<Vec<(Point, FrameItem)>>>,
    /// The hardness of this frame.
    ///
    /// Determines whether it is a boundary for gradient drawing.
    kind: FrameKind,
    /// An optional label attached to the frame.
    label: Option<Label>,
}

/// Constructor, accessors and setters.
impl Frame {
    /// Create a new, empty frame.
    ///
    /// Panics the size is not finite.
    #[track_caller]
    pub fn new(size: Size, kind: FrameKind) -> Self {
        assert!(size.is_finite());
        Self {
            size,
            baseline: None,
            items: Arc::new(LazyHash::new(vec![])),
            kind,
            label: None,
        }
    }

    /// Create a new, empty soft frame.
    ///
    /// Panics if the size is not finite.
    #[track_caller]
    pub fn soft(size: Size) -> Self {
        Self::new(size, FrameKind::Soft)

Review comment (suggestion):
I want to try and keep frames as lightweight and conceptually simple as possible (the existence of `FrameKind` is actually already unfortunate), so I would prefer for this to be in `GroupItem`. You can generate it via `frame.group(..)`. You can search for references to this function to see how it works.

Code after:
    Transform,
};
use crate::model::{Destination, LinkElem};
use crate::syntax::Span;
use crate::text::TextItem;
use crate::utils::{LazyHash, Numeric};
use crate::visualize::{
    ellipse, styled_rect, Color, FixedStroke, Geometry, Image, Paint, Path, Shape,
};

/// A finished layout with items at fixed positions.
#[derive(Default, Clone, Hash)]
pub struct Frame {
    /// The size of the frame.
    size: Size,
    /// The baseline of the frame measured from the top. If this is `None`, the
    /// frame's implicit baseline is at the bottom.
    baseline: Option<Abs>,
    /// The items composing this layout.
    items: Arc<LazyHash<Vec<(Point, FrameItem)>>>,
    /// The hardness of this frame.
    ///
    /// Determines whether it is a boundary for gradient drawing.
    kind: FrameKind,
}

/// Constructor, accessors and setters.
impl Frame {
    /// Create a new, empty frame.
    ///
    /// Panics the size is not finite.
    #[track_caller]
    pub fn new(size: Size, kind: FrameKind) -> Self {
        assert!(size.is_finite());
        Self {
            size,
            baseline: None,
            items: Arc::new(LazyHash::new(vec![])),
            kind,
        }
    }

    /// Create a new, empty soft frame.
    ///
    /// Panics if the size is not finite.
    #[track_caller]
    pub fn soft(size: Size) -> Self {
        Self::new(size, FrameKind::Soft)
    }

    /// Create a new, empty hard frame.