nativeview_layout/top/
display.rs1use nativeview_engine::InteractionTracker;
7use nativeview_store::{NodeId, NodeStore, RowPatchView};
8use nativeview_tables::container::ContainerEnv;
9use nativeview_tables::media::{ConditionalTier, MediaEnv};
10use nativeview_tables::semantics::SemanticStyleOracle;
11use nativeview_tables::tables::Display;
12
13use crate::scene::{EffectiveBox, ResponsivePatches, StyleCascade};
14use crate::taffy_store::container::scope::{GenSlots, committed_container_env};
15use crate::taffy_store::responsive::{is_node_show_on_hidden, visit_node_responsive_patches};
16
17#[derive(Clone, Copy, Default)]
20pub struct DisplayEnv<'a> {
21 pub media: Option<&'a MediaEnv>,
23 pub(crate) container_envs: Option<&'a GenSlots<ContainerEnv>>,
25 pub interaction: Option<&'a InteractionTracker>,
27}
28
29impl<'a> DisplayEnv<'a> {
30 #[inline]
32 pub fn with_interaction(interaction: Option<&'a InteractionTracker>) -> Self {
33 Self {
34 interaction,
35 ..Self::default()
36 }
37 }
38
39 #[inline]
40 fn cascade(&self) -> StyleCascade<'_, Self> {
41 StyleCascade {
42 responsive: self,
43 interaction: self.interaction,
44 inert: None,
45 }
46 }
47
48 #[inline]
50 pub fn effective_box(&self, store: &NodeStore, id: NodeId) -> EffectiveBox {
51 self.cascade().effective_box(store, id)
52 }
53
54 #[inline]
55 pub fn display(&self, store: &NodeStore, id: NodeId) -> Display {
56 self.effective_box(store, id).display
57 }
58
59 #[inline]
61 pub fn is_display_none(&self, store: &NodeStore, id: NodeId) -> bool {
62 self.cascade().is_display_none(store, id)
63 }
64
65 #[inline]
67 pub fn is_display_contents(&self, store: &NodeStore, id: NodeId) -> bool {
68 self.cascade().is_display_contents(store, id)
69 }
70}
71
72impl ResponsivePatches for DisplayEnv<'_> {
73 #[inline]
74 fn visit_responsive_patches<'a>(
75 &self,
76 store: &'a NodeStore,
77 id: NodeId,
78 f: &mut dyn FnMut(ConditionalTier, RowPatchView<'a>),
79 ) {
80 let Some(media) = self.media else { return };
81 let cenv = self
82 .container_envs
83 .map_or(ContainerEnv::NONE, |envs| committed_container_env(envs, id));
84 visit_node_responsive_patches(store, id, media, cenv, f);
85 }
86
87 #[inline]
88 fn is_show_on_hidden(&self, store: &NodeStore, id: NodeId) -> bool {
89 self.media
90 .is_some_and(|media| is_node_show_on_hidden(store, id, media))
91 }
92}
93
94impl SemanticStyleOracle for DisplayEnv<'_> {
95 #[inline]
96 fn is_display_none(&self, store: &NodeStore, id: NodeId) -> bool {
97 DisplayEnv::is_display_none(self, store, id)
98 }
99
100 #[inline]
101 fn is_display_contents(&self, store: &NodeStore, id: NodeId) -> bool {
102 DisplayEnv::is_display_contents(self, store, id)
103 }
104}