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