tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 979HTML 924Markdown 12TOML 82994 Definiciones

⎇ 18b6cf40090e6a3dafb34b3f3bbdfdbd979ffb1b src/tree/layout.rs Rust · 77 líneas · 2.9 KB Historia Quién tocó qué crudo

Remove duplicate types definitions (`Layout`, `RunMode`, `SizingMode`, `SizeAndBaselines`) (#469) 18b6cf400 · Nico Burns ·

1//! Final data structures that represent the high-level UI layout
2
3use crate::geometry::{Point, Size};
4
5/// Whether we are performing a full layout, or we merely need to size the node
6#[derive(Copy, Clone, Debug, PartialEq, Eq)]
7pub enum RunMode {
8    /// A full layout for this node and all children should be computed
9    PeformLayout,
10    /// The layout algorithm should be executed such that an accurate container size for the node can be determined.
11    /// Layout steps that aren't necessary for determining the container size of the current node can be skipped.
12    ComputeSize,
13}
14
15/// Whether styles should be taken into account when computing size
16#[derive(Copy, Clone, Debug, PartialEq, Eq)]
17pub enum SizingMode {
18    /// Only content contributions should be taken into account
19    ContentSize,
20    /// Inherent size styles should be taken into account in addition to content contributions
21    InherentSize,
22}
23
24/// A struct containing both the size of a node and it's first baseline in each dimension (if it has any)
25///
26/// A baseline is the line on which text sits. Your node likely has a baseline if it is a text node, or contains
27/// children that may be text nodes. See <https://www.w3.org/TR/css-writing-modes-3/#intro-baselines> for details.
28/// If your node does not have a baseline (or you are unsure how to compute it), then simply return `Point::NONE`
29/// for the first_baselines field
30#[derive(Debug, Copy, Clone)]
31pub struct SizeAndBaselines {
32    /// The size of the node
33    pub size: Size<f32>,
34    /// The first baseline of the node in each dimension, if any
35    pub first_baselines: Point<Option<f32>>,
36}
37
38impl From<Size<f32>> for SizeAndBaselines {
39    fn from(size: Size<f32>) -> Self {
40        Self { size, first_baselines: Point::NONE }
41    }
42}
43
44/// The final result of a layout algorithm for a single node.
45#[derive(Debug, Copy, Clone)]
46pub struct Layout {
47    /// The relative ordering of the node
48    ///
49    /// Nodes with a higher order should be rendered on top of those with a lower order.
50    /// This is effectively a topological sort of each tree.
51    pub order: u32,
52    /// The width and height of the node
53    pub size: Size<f32>,
54    /// The bottom-left corner of the node
55    pub location: Point<f32>,
56}
57
58impl Layout {
59    /// Creates a new zero-[`Layout`].
60    ///
61    /// The Zero-layout has size and location set to ZERO.
62    /// The `order` value of this layout is set to the minimum value of 0.
63    /// This means it should be rendered below all other [`Layout`]s.
64    #[must_use]
65    pub const fn new() -> Self {
66        Self { order: 0, size: Size::zero(), location: Point::ZERO }
67    }
68
69    /// Creates a new zero-[`Layout`] with the supplied `order` value.
70    ///
71    /// Nodes with a higher order should be rendered on top of those with a lower order.
72    /// The Zero-layout has size and location set to ZERO.
73    #[must_use]
74    pub const fn with_order(order: u32) -> Self {
75        Self { order, size: Size::zero(), location: Point::ZERO }
76    }
77}