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    pub const fn zero() -> Self {
20        Self {
21            top: 0.0,
22            left: 0.0,
23            right: 0.0,
24            bottom: 0.0,
25        }
26    }
27    #[must_use]
28    pub fn total_vertical(&self) -> f32 {
29        self.top + self.bottom
30    }
31    #[must_use]
32    pub fn total_horizontal(&self) -> f32 {
33        self.left + self.right
34    }
35}
36
37/// Index into a font's glyph table.
38type GlyphIndex = u32;
39
40/// A single positioned glyph with its index, screen position, and size.
41#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
42pub struct GlyphInstance {
43    pub index: GlyphIndex,
44    pub point: LogicalPosition,
45    pub size: LogicalSize,
46}
47
48impl GlyphInstance {
49    pub fn scale_for_dpi(&mut self, scale_factor: f32) {
50        self.point.scale_for_dpi(scale_factor);
51        self.size.scale_for_dpi(scale_factor);
52    }
53}