atmos/os_lib/web_engine/
paint_update.rs1extern crate alloc;
13
14use alloc::string::String;
15use alloc::vec::Vec;
16use super::repaint_scope::is_paint_only;
17
18#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct PendingStyleUpdate {
21 pub node_idx: usize,
22 pub prop: String,
23 pub val: String,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq)]
28pub enum UpdateScope {
29 Nothing,
31 PaintOnly(Vec<(String, String, String)>),
33 Relayout,
35}
36
37pub fn classify_updates<F>(
42 structural_dirty: bool,
43 updates: &[PendingStyleUpdate],
44 resolve_id: F,
45) -> UpdateScope
46where
47 F: Fn(usize) -> Option<String>,
48{
49 if structural_dirty {
50 return UpdateScope::Relayout;
51 }
52 if updates.is_empty() {
53 return UpdateScope::Nothing;
54 }
55
56 let mut paint_values = Vec::with_capacity(updates.len());
57 for u in updates {
58 match is_paint_only(&u.prop) {
60 Ok(true) => {}
61 _ => return UpdateScope::Relayout,
62 }
63 let Some(eid) = resolve_id(u.node_idx) else {
65 return UpdateScope::Relayout;
66 };
67 if eid.is_empty() {
68 return UpdateScope::Relayout;
69 }
70 paint_values.push((eid, u.prop.clone(), u.val.clone()));
71 }
72
73 UpdateScope::PaintOnly(paint_values)
74}