Skip to main content

azul_core/
ui_solver.rs

1//! Small geometry types used by the layout solver and text shaping pipeline.
2//!
3//! Default font / text constants live in [`azul_css::defaults`].
4
5use crate::geom::{LogicalPosition, LogicalSize};
6
7/// Resolved top/right/bottom/left offsets in logical pixels (used for
8/// margins, padding, and borders after CSS resolution).
9#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
10#[repr(C)]
11pub struct ResolvedOffsets {
12    pub top: f32,
13    pub left: f32,
14    pub right: f32,
15    pub bottom: f32,
16}
17
18impl ResolvedOffsets {
19    #[must_use]
20    pub const fn zero() -> Self {
21        Self {
22            top: 0.0,
23            left: 0.0,
24            right: 0.0,
25            bottom: 0.0,
26        }
27    }
28    #[must_use]
29    pub fn total_vertical(&self) -> f32 {
30        self.top + self.bottom
31    }
32    #[must_use]
33    pub fn total_horizontal(&self) -> f32 {
34        self.left + self.right
35    }
36}
37
38/// Index into a font's glyph table.
39type GlyphIndex = u32;
40
41/// A single positioned glyph with its index, screen position, and size.
42#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd)]
43pub struct GlyphInstance {
44    pub index: GlyphIndex,
45    pub point: LogicalPosition,
46    pub size: LogicalSize,
47}
48
49impl GlyphInstance {
50    pub fn scale_for_dpi(&mut self, scale_factor: f32) {
51        self.point.scale_for_dpi(scale_factor);
52        self.size.scale_for_dpi(scale_factor);
53    }
54}
55
56#[cfg(test)]
57#[path = "ui_solver_test.rs"]
58mod ui_solver_test;