#![forbid(unsafe_code)]
pub mod a11y;
mod clipboard;
mod diff;
mod element;
mod render;
pub mod runtime;
pub use a11y::{AccessNode, Role, accessibility_tree};
pub use clipboard::{clipboard_text, set_clipboard_text};
pub use diff::{Damage, diff_trees};
pub use element::{Align, BoxStyle, Element, ElementKind, LayoutStyle, SizeOverride};
pub use render::caret_index_at;
pub use render::{apply_scroll, layout, measure, paint, paint_focus, paint_hover};
pub use runtime::{
ActionId, Anchor, ContextId, Cx, DragId, FocusId, Handlers, KeyInput, LayoutNode, NodeContent,
OverlaySpec, ScrollId, TextPosId, ViewportEvent, ViewportId, collect_focusables,
collect_viewports, context_at, drag_at, find_action, find_focus, find_scroll, find_text_pos,
first_text, focus_at, hit_test, scroll_at, text_pos_at, viewport_at,
};
pub use stipple_render::Font;
pub use stipple_layout::Axis;
use stipple_geometry::{Rect, Size};
use stipple_render::Scene;
use stipple_style::Theme;
pub trait View {
fn build(&self, theme: &Theme) -> Element;
}
impl View for Element {
fn build(&self, _theme: &Theme) -> Element {
self.clone()
}
}
pub fn render_view(view: &impl View, size: Size, theme: &Theme, font: Option<&Font>) -> Scene {
let element = view.build(theme);
let tree = layout(
&element,
Rect::from_xywh(0.0, 0.0, size.width, size.height),
font,
);
let mut scene = Scene::new(size);
paint(&tree, &mut scene, font);
scene
}
#[cfg(test)]
mod tests {
use super::*;
use stipple_render::Color;
#[test]
fn render_view_paints_a_root_panel() {
let root = Element::stack(Axis::Vertical, vec![])
.fill(Color::rgb(10, 20, 30))
.padding(stipple_geometry::Insets::uniform(8.0));
let scene = render_view(&root, Size::new(100.0, 100.0), &Theme::light(), None);
assert_eq!(scene.len(), 1);
assert_eq!(scene.logical_size(), Size::new(100.0, 100.0));
}
}