#![deny(missing_docs)]
#![doc = include_str!("../README.md")]
pub mod byte_blend;
pub mod dev_overlay;
pub const FRAME_CLEAR_COLOR: [f32; 4] = [18.0 / 255.0, 18.0 / 255.0, 24.0 / 255.0, 1.0];
pub mod brush_sampling;
pub mod font_source;
pub mod geometry;
pub mod glyph_mask;
pub mod glyph_reach;
pub mod graph;
mod graph_hash;
pub mod graph_scene;
pub mod hit_graph;
pub mod image_compare;
#[cfg(feature = "installed-fonts")]
pub mod installed_fonts;
pub mod layer_composition;
mod layer_recycling;
pub mod layer_shadow;
pub mod layer_transform;
mod node_window_bounds;
pub mod primitive_emit;
pub mod raster_cache;
pub mod render_contract;
pub mod rgb565;
pub mod scene_builder;
pub mod scene_pick;
pub mod shape_sdf;
pub mod space;
pub mod style_shared;
pub mod text_atlas;
pub mod text_canvas;
pub mod text_decoration;
pub mod text_fonts;
pub mod text_glyphs;
pub mod text_mask_gamma;
pub mod text_paint;
pub mod text_raster;
mod text_shadow;
mod thread_state;
#[cfg(test)]
#[path = "tests/pointer_slices.rs"]
mod pointer_slices;
use cranpose_core::{MemoryApplier, collections::map::HashSet};
use cranpose_foundation::nodes::input::PointerEvent;
use cranpose_ui::LayoutTree;
pub use cranpose_ui_graphics::Brush;
use cranpose_ui_graphics::Size;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum NodeUpdate {
Content,
Draws,
Layer,
Moved,
MovedLayer,
}
impl NodeUpdate {
#[must_use]
pub fn merge(self, other: Self) -> Self {
use NodeUpdate::{Content, Draws, Layer, Moved, MovedLayer};
match (self, other) {
(Content, _) | (_, Content) => Content,
(Draws, Draws) => Draws,
(Draws, _) | (_, Draws) => Content,
(Moved, Moved) => Moved,
(Layer, Layer) => Layer,
(Moved | Layer | MovedLayer, Moved | Layer | MovedLayer) => MovedLayer,
}
}
}
pub type SceneUpdates<'a> = &'a [(cranpose_core::NodeId, NodeUpdate)];
pub trait HitTestTarget {
fn dispatch(&self, event: PointerEvent);
fn dispatch_with_applier(&self, _applier: &mut MemoryApplier, event: PointerEvent) {
self.dispatch(event);
}
fn node_id(&self) -> cranpose_core::NodeId;
fn pointer_icon(&self) -> Option<cranpose_ui_graphics::PointerIcon> {
None
}
fn capture_path(&self) -> Vec<cranpose_core::NodeId> {
vec![self.node_id()]
}
}
pub trait RenderScene {
type HitTarget: HitTestTarget + Clone;
fn clear(&mut self);
fn hit_test(&self, x: f32, y: f32) -> Vec<Self::HitTarget>;
fn hit_test_near(&self, _x: f32, _y: f32) -> Option<Self::HitTarget> {
None
}
fn hit_test_nodes(&self, x: f32, y: f32) -> Vec<cranpose_core::NodeId> {
self.hit_test(x, y)
.into_iter()
.map(|h| h.node_id())
.collect()
}
fn find_target(&self, node_id: cranpose_core::NodeId) -> Option<Self::HitTarget>;
fn hit_test_ray(
&self,
_scene: cranpose_core::NodeId,
_ray: cranpose_ui_graphics::space::Ray,
) -> Vec<Self::HitTarget> {
Vec::new()
}
fn surface_windows(
&self,
_visit: &mut dyn FnMut(cranpose_core::NodeId, cranpose_ui_graphics::ProjectiveTransform),
) {
}
fn surface_window_bounds(
&self,
_node_id: cranpose_core::NodeId,
) -> Option<cranpose_ui_graphics::Rect> {
None
}
fn node_window_bounds(
&self,
_visit: &mut dyn FnMut(cranpose_core::NodeId, cranpose_ui_graphics::Rect),
) {
}
fn layer_moves(&self) -> u64 {
0
}
fn collect_retained_visual_observation_nodes(
&self,
nodes: &mut HashSet<cranpose_core::NodeId>,
) -> bool {
nodes.clear();
false
}
}
pub trait Renderer {
type Scene: RenderScene;
type Error;
fn attach_app_context_services(&mut self, _app_context: &cranpose_ui::AppContext) {}
fn apply_installed_fonts(&mut self, _app_context: &cranpose_ui::AppContext) {}
fn set_root_scale(&mut self, _scale: f32) {}
fn scene(&self) -> &Self::Scene;
fn scene_mut(&mut self) -> &mut Self::Scene;
fn rebuild_scene(
&mut self,
layout_tree: &LayoutTree,
viewport: Size,
) -> Result<(), Self::Error>;
fn rebuild_scene_from_applier(
&mut self,
applier: &mut MemoryApplier,
root: cranpose_core::NodeId,
viewport: Size,
) -> Result<(), Self::Error>;
fn update_scene_from_applier(
&mut self,
applier: &mut MemoryApplier,
root: cranpose_core::NodeId,
viewport: Size,
updates: SceneUpdates<'_>,
) -> Result<(), Self::Error> {
let _ = updates;
self.rebuild_scene_from_applier(applier, root, viewport)
}
fn update_visual_scene_from_applier(
&mut self,
applier: &mut MemoryApplier,
root: cranpose_core::NodeId,
viewport: Size,
updates: SceneUpdates<'_>,
) -> Result<(), Self::Error> {
self.update_scene_from_applier(applier, root, viewport, updates)
}
fn draw_dev_overlay(&mut self, _overlay: &cranpose_ui::PreparedTextLayout, _viewport: Size) {}
fn set_inspector_overlay(&mut self, _graph: Option<graph::RenderGraph>) {}
fn note_held_still(&mut self) {}
fn note_pointer_held(&mut self) {}
fn build_while_idle(&mut self) -> bool {
false
}
fn needs_frame_warmup(&self) -> bool {
false
}
fn awaits_pipelines(&self) -> bool {
false
}
}