use std::sync::Arc;
pub use nativeview_abi::{NvSizeConstraints as SizeConstraints, NvSurfaceMeasure as SurfaceMeasure};
use nativeview_engine::{InteractionTracker, LayoutRect, Viewport};
use nativeview_store::{ChangeSet, NodeId, NodeStore, RowPatchView, TableSlot};
use nativeview_tables::media::{ConditionalTier, MediaEnv};
use crate::{LeafMeasureHook, ParagraphStore, ResolvedBoxEdges, TextMeasurer, TopLayerIndex};
pub trait StoreLayoutEngine: Send {
fn name(&self) -> &'static str;
fn sync_changes(&mut self, store: &NodeStore, changes: &ChangeSet);
fn top_layer(&self) -> &TopLayerIndex;
fn sync_changes_with_interaction(
&mut self,
store: &NodeStore,
changes: &ChangeSet,
_interaction: Option<&InteractionTracker>,
) {
self.sync_changes(store, changes);
}
fn compute_layout(&mut self, store: &NodeStore, root: NodeId, viewport: Viewport) -> bool;
fn compute_layout_with_interaction(
&mut self,
store: &NodeStore,
root: NodeId,
viewport: Viewport,
_interaction: Option<&InteractionTracker>,
) -> bool {
self.compute_layout(store, root, viewport)
}
fn sync_interaction_paragraphs(
&mut self,
_store: &NodeStore,
_interaction: &InteractionTracker,
_dirty_nodes: &[NodeId],
) -> (&[NodeId], &[NodeId]) {
(&[], &[])
}
fn paragraphs(&self) -> Option<&ParagraphStore> {
None
}
fn paragraphs_mut(&mut self) -> Option<&mut ParagraphStore> {
None
}
fn measure_root(
&mut self,
_store: &NodeStore,
_root: NodeId,
_constraints: SizeConstraints,
_ideal: bool,
) -> SurfaceMeasure {
SurfaceMeasure {
width: 0.0,
height: 0.0,
first_baseline: f32::NAN,
last_baseline: f32::NAN,
}
}
fn layout_of(&self, id: NodeId) -> Option<LayoutRect>;
fn changed_rects(&self) -> Option<&[NodeId]> {
None
}
fn set_capture_box_edges(&mut self, _enabled: bool) {}
fn capture_box_edges(&self) -> bool {
false
}
fn box_edges_of(&self, _id: NodeId) -> Option<ResolvedBoxEdges> {
None
}
fn set_text_measurer(&mut self, measurer: Arc<dyn TextMeasurer>);
fn register_measure_hook(&mut self, _slot: TableSlot, _hook: Arc<dyn LeafMeasureHook>) -> bool {
false
}
fn reset(&mut self);
fn set_media_env(&mut self, _env: MediaEnv) -> bool {
false
}
fn visit_responsive_patches<'a>(
&self,
_store: &'a NodeStore,
_id: NodeId,
_f: &mut dyn FnMut(ConditionalTier, RowPatchView<'a>),
) {
}
fn is_show_on_hidden(&self, _store: &NodeStore, _id: NodeId) -> bool {
false
}
fn responsive_epoch(&self) -> u64 {
0
}
}
pub type DynLayoutEngine = Box<dyn StoreLayoutEngine>;
impl<L: StoreLayoutEngine + ?Sized> StoreLayoutEngine for Box<L> {
fn name(&self) -> &'static str {
(**self).name()
}
fn sync_changes(&mut self, store: &NodeStore, changes: &ChangeSet) {
(**self).sync_changes(store, changes);
}
fn top_layer(&self) -> &TopLayerIndex {
(**self).top_layer()
}
fn sync_changes_with_interaction(
&mut self,
store: &NodeStore,
changes: &ChangeSet,
interaction: Option<&InteractionTracker>,
) {
(**self).sync_changes_with_interaction(store, changes, interaction);
}
fn compute_layout(&mut self, store: &NodeStore, root: NodeId, viewport: Viewport) -> bool {
(**self).compute_layout(store, root, viewport)
}
fn compute_layout_with_interaction(
&mut self,
store: &NodeStore,
root: NodeId,
viewport: Viewport,
interaction: Option<&InteractionTracker>,
) -> bool {
(**self).compute_layout_with_interaction(store, root, viewport, interaction)
}
fn sync_interaction_paragraphs(
&mut self,
store: &NodeStore,
interaction: &InteractionTracker,
dirty_nodes: &[NodeId],
) -> (&[NodeId], &[NodeId]) {
(**self).sync_interaction_paragraphs(store, interaction, dirty_nodes)
}
fn paragraphs(&self) -> Option<&ParagraphStore> {
(**self).paragraphs()
}
fn paragraphs_mut(&mut self) -> Option<&mut ParagraphStore> {
(**self).paragraphs_mut()
}
fn measure_root(
&mut self,
store: &NodeStore,
root: NodeId,
constraints: SizeConstraints,
ideal: bool,
) -> SurfaceMeasure {
(**self).measure_root(store, root, constraints, ideal)
}
fn layout_of(&self, id: NodeId) -> Option<LayoutRect> {
(**self).layout_of(id)
}
fn changed_rects(&self) -> Option<&[NodeId]> {
(**self).changed_rects()
}
fn set_capture_box_edges(&mut self, enabled: bool) {
(**self).set_capture_box_edges(enabled);
}
fn capture_box_edges(&self) -> bool {
(**self).capture_box_edges()
}
fn box_edges_of(&self, id: NodeId) -> Option<ResolvedBoxEdges> {
(**self).box_edges_of(id)
}
fn set_text_measurer(&mut self, measurer: Arc<dyn TextMeasurer>) {
(**self).set_text_measurer(measurer);
}
fn register_measure_hook(&mut self, slot: TableSlot, hook: Arc<dyn LeafMeasureHook>) -> bool {
(**self).register_measure_hook(slot, hook)
}
fn reset(&mut self) {
(**self).reset();
}
fn set_media_env(&mut self, env: MediaEnv) -> bool {
(**self).set_media_env(env)
}
fn visit_responsive_patches<'a>(
&self,
store: &'a NodeStore,
id: NodeId,
f: &mut dyn FnMut(ConditionalTier, RowPatchView<'a>),
) {
(**self).visit_responsive_patches(store, id, f);
}
fn is_show_on_hidden(&self, store: &NodeStore, id: NodeId) -> bool {
(**self).is_show_on_hidden(store, id)
}
fn responsive_epoch(&self) -> u64 {
(**self).responsive_epoch()
}
}