Skip to main content

ratex_layout/
layout_options.rs

1use ratex_font::{get_global_metrics, MathConstants};
2use ratex_types::color::Color;
3use ratex_types::math_style::MathStyle;
4
5/// Layout options passed through the layout tree.
6#[derive(Debug, Clone)]
7pub struct LayoutOptions {
8    pub style: MathStyle,
9    pub color: Color,
10    /// When set (e.g. in align/aligned), cap relation spacing to this many mu for consistency.
11    pub align_relation_spacing: Option<f64>,
12    /// When inside \\left...\\right, the stretch height for \\middle delimiters (second pass only).
13    pub leftright_delim_height: Option<f64>,
14}
15
16impl Default for LayoutOptions {
17    fn default() -> Self {
18        Self {
19            style: MathStyle::Display,
20            color: Color::BLACK,
21            align_relation_spacing: None,
22            leftright_delim_height: None,
23        }
24    }
25}
26
27impl LayoutOptions {
28    pub fn metrics(&self) -> &'static MathConstants {
29        get_global_metrics(self.style.size_index())
30    }
31
32    pub fn size_multiplier(&self) -> f64 {
33        self.style.size_multiplier()
34    }
35
36    pub fn with_style(&self, style: MathStyle) -> Self {
37        Self {
38            style,
39            color: self.color,
40            align_relation_spacing: self.align_relation_spacing,
41            leftright_delim_height: self.leftright_delim_height,
42        }
43    }
44
45    pub fn with_color(&self, color: Color) -> Self {
46        Self {
47            style: self.style,
48            color,
49            align_relation_spacing: self.align_relation_spacing,
50            leftright_delim_height: self.leftright_delim_height,
51        }
52    }
53}