azul_core/
ui_description.rs

1use std::{
2    collections::BTreeMap,
3};
4use azul_css::{Css, CssDeclaration, CssProperty, CssPropertyType};
5use crate::{
6    FastHashMap,
7    id_tree::{NodeId, NodeDataContainer},
8    dom::{DomId, DomString},
9    ui_state::{UiState, HoverGroup},
10    callbacks::HitTestItem,
11    style::HtmlCascadeInfo,
12};
13
14#[derive(Debug)]
15pub struct UiDescription {
16    /// DOM ID of this arena (so that multiple DOMs / IFrames can be displayed in one window)
17    pub dom_id: DomId,
18    /// Data necessary for matching nodes properly (necessary to resolve CSS paths in callbacks)
19    pub html_tree: NodeDataContainer<HtmlCascadeInfo>,
20    /// ID of the root node of the arena (usually NodeId(0))
21    pub ui_descr_root: NodeId,
22    /// This field is created from the Css
23    pub styled_nodes: NodeDataContainer<StyledNode>,
24    /// The style properties that should be overridden for this frame, cloned from the `Css`
25    pub dynamic_css_overrides: BTreeMap<NodeId, FastHashMap<DomString, CssProperty>>,
26    /// In order to hit-test :hover and :active selectors, need to insert tags for all rectangles
27    /// that have a non-:hover path, for example if we have `#thing:hover`, then all nodes selected by `#thing`
28    /// need to get a TagId, otherwise, they can't be hit-tested.
29    pub selected_hover_nodes: BTreeMap<NodeId, HoverGroup>,
30}
31
32impl UiDescription {
33    /// Applies the styles to the nodes calculated from the `layout_screen`
34    /// function and calculates the final display list that is submitted to the
35    /// renderer.
36    pub fn new(
37        ui_state: &mut UiState,
38        style: &Css,
39        focused_node: &Option<(DomId, NodeId)>,
40        hovered_nodes: &BTreeMap<NodeId, HitTestItem>,
41        is_mouse_down: bool,
42    ) -> Self {
43
44        let ui_description = crate::style::match_dom_selectors(
45            ui_state,
46            &style,
47            focused_node,
48            hovered_nodes,
49            is_mouse_down,
50        );
51
52        // Important: Create all the tags for the :hover and :active selectors
53        ui_state.create_tags_for_hover_nodes(&ui_description.selected_hover_nodes);
54
55        ui_description
56    }
57}
58
59#[derive(Debug, Default, Clone, PartialEq, Hash, PartialOrd, Eq, Ord)]
60pub struct StyledNode {
61    /// The CSS constraints, after the cascading step
62    pub css_constraints: BTreeMap<CssPropertyType, CssDeclaration>,
63}