Skip to main content

azul_core/
ui_solver.rs

1#[cfg(not(feature = "std"))]
2use alloc::string::{String, ToString};
3use alloc::{boxed::Box, collections::btree_map::BTreeMap, vec::Vec};
4#[cfg(target_arch = "x86_64")]
5use core::arch::x86_64::__m256;
6use core::{
7    fmt,
8    sync::atomic::{AtomicBool, Ordering as AtomicOrdering},
9};
10
11use azul_css::{
12    css::CssPropertyValue,
13    props::{
14        basic::{
15            ColorU as StyleColorU, LayoutPoint, LayoutRect, LayoutRectVec, LayoutSize, PixelValue,
16            StyleFontSize,
17        },
18        layout::{
19            LayoutBoxSizing, LayoutDisplay, LayoutFlexDirection, LayoutFloat, LayoutHeight,
20            LayoutInsetBottom, LayoutJustifyContent, LayoutLeft, LayoutMarginBottom,
21            LayoutMarginLeft, LayoutMarginRight, LayoutMarginTop, LayoutMaxHeight, LayoutMaxWidth,
22            LayoutMinHeight, LayoutMinWidth, LayoutOverflow, LayoutPaddingBottom,
23            LayoutPaddingLeft, LayoutPaddingRight, LayoutPaddingTop, LayoutPosition, LayoutRight,
24            LayoutTop, LayoutWidth,
25        },
26        style::{
27            LayoutBorderBottomWidth, LayoutBorderLeftWidth, LayoutBorderRightWidth,
28            LayoutBorderTopWidth, OptionStyleTextAlign, StyleBoxShadow, StyleTextAlign,
29            StyleTextColor, StyleTransform, StyleTransformOrigin, StyleVerticalAlign,
30        },
31    },
32    AzString, OptionF32,
33};
34use rust_fontconfig::FcFontCache;
35
36use crate::{
37    callbacks::{HidpiAdjustedBounds, IFrameCallbackInfo, IFrameCallbackReturn},
38    dom::{DomId, DomNodeHash},
39    geom::{LogicalPosition, LogicalRect, LogicalRectVec, LogicalSize},
40    gl::OptionGlContextPtr,
41    gpu::GpuEventChanges,
42    hit_test::{ExternalScrollId, HitTestItem, ScrollHitTestItem, ScrollStates, ScrolledNodes},
43    id::{NodeDataContainer, NodeDataContainerRef, NodeId},
44    resources::{
45        Epoch, FontInstanceKey, GlTextureCache, IdNamespace, ImageCache, OpacityKey,
46        RendererResources, TransformKey, UpdateImageResult,
47    },
48    styled_dom::{NodeHierarchyItemId, StyledDom},
49    window::{OptionChar, WindowSize, WindowTheme},
50};
51
52pub const DEFAULT_FONT_SIZE_PX: isize = 16;
53pub const DEFAULT_FONT_SIZE: StyleFontSize = StyleFontSize {
54    inner: PixelValue::const_px(DEFAULT_FONT_SIZE_PX),
55};
56pub const DEFAULT_FONT_ID: &str = "serif";
57pub const DEFAULT_TEXT_COLOR: StyleTextColor = StyleTextColor {
58    inner: StyleColorU {
59        r: 0,
60        b: 0,
61        g: 0,
62        a: 255,
63    },
64};
65pub const DEFAULT_LINE_HEIGHT: f32 = 1.0;
66pub const DEFAULT_WORD_SPACING: f32 = 1.0;
67pub const DEFAULT_LETTER_SPACING: f32 = 0.0;
68pub const DEFAULT_TAB_WIDTH: f32 = 4.0;
69
70#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
71#[repr(C)]
72pub struct ResolvedOffsets {
73    pub top: f32,
74    pub left: f32,
75    pub right: f32,
76    pub bottom: f32,
77}
78
79impl ResolvedOffsets {
80    pub const fn zero() -> Self {
81        Self {
82            top: 0.0,
83            left: 0.0,
84            right: 0.0,
85            bottom: 0.0,
86        }
87    }
88    pub fn total_vertical(&self) -> f32 {
89        self.top + self.bottom
90    }
91    pub fn total_horizontal(&self) -> f32 {
92        self.left + self.right
93    }
94}
95
96pub type GlyphIndex = u32;
97
98#[derive(Debug, Default, Copy, Clone, PartialEq, PartialOrd)]
99pub struct GlyphInstance {
100    pub index: GlyphIndex,
101    pub point: LogicalPosition,
102    pub size: LogicalSize,
103}
104
105impl GlyphInstance {
106    pub fn scale_for_dpi(&mut self, scale_factor: f32) {
107        self.point.scale_for_dpi(scale_factor);
108        self.size.scale_for_dpi(scale_factor);
109    }
110}