waterui_core/
lib.rs

1//! # `WaterUI` Core
2//!
3//! `waterui_core` provides the essential building blocks for developing cross-platform reactive UIs.
4//! This foundation layer establishes a unified architecture that works consistently across desktop,
5//! mobile, web, and embedded environments.
6
7#![cfg_attr(feature = "nightly", feature(never_type))]
8//!
9//! ## Architecture Overview
10//!
11//! The system is structured around these key concepts:
12//!
13//! ### Declarative View System
14//!
15//! The [`View`] trait forms the foundation of the UI component model:
16//! ```rust,ignore
17//! pub trait View: 'static {
18//!     fn body(self, env: &Environment) -> impl View;
19//! }
20//! ```
21//!
22//! This recursive definition enables composition of complex interfaces from simple
23//! building blocks. Each view receives contextual information and transforms into
24//! its visual representation.
25//!
26//! ### Context Propagation
27//!
28//! The [`Environment`] provides a type-based dependency injection system:
29//!
30//! ```rust
31//! use waterui_core::Environment;
32//!
33//! let env = Environment::new();
34//! // .with() and .install() methods would be used with actual theme and plugin types
35//! ```
36//!
37//! This propagates configuration and resources through the view hierarchy without
38//! explicit parameter passing.
39//!
40//! ### Type Erasure
41//!
42//! [`AnyView`] enables heterogeneous collections by preserving behavior while
43//! erasing concrete types, facilitating dynamic composition patterns.
44//!
45//! ## Component Architecture
46//!
47//! The framework provides several component categories:
48//!
49//! - **Platform Components**: Native UI elements with platform-optimized rendering
50//! - **Reactive Components**: Views that automatically update when data changes
51//! - **Metadata Components**: Elements that carry additional rendering instructions
52//! - **Composite Components**: Higher-order components built from primitive elements
53//!
54//! ## Reactive Data Flow
55//!
56//! State management integrates seamlessly with the view system:
57//!
58//! ```rust
59//! use waterui_core::{Dynamic, binding, Binding};
60//!
61//! // Create a reactive state container
62//! let counter: Binding<i32> = binding(0);
63//!
64//! // Create a view that responds to state changes using Dynamic
65//! let view = Dynamic::watch(counter, |count: i32| {
66//!      format!("Current value: {}", count)
67//! });
68//! ```
69//!
70//! The UI automatically updates when state changes, with efficient rendering that only
71//! updates affected components.
72//!
73//! ## Extensibility
74//!
75//! The plugin interface enables framework extensions without modifying core code:
76//!
77//! ```rust
78//! use waterui_core::{plugin::Plugin, Environment};
79//!
80//! struct MyPlugin;
81//! impl Plugin for MyPlugin {}
82//!
83//! let mut env = Environment::new();
84//! MyPlugin.install(&mut env);
85//! ```
86//!
87//! This enables modular functionality like theming, localization, and platform-specific features.
88
89#![cfg_attr(not(feature = "std"), no_std)]
90extern crate alloc;
91
92#[macro_use]
93mod macros;
94mod components;
95pub use anyview::AnyView;
96pub use components::*;
97pub mod env;
98pub mod event;
99pub mod view;
100pub mod views;
101pub use env::Environment;
102pub use view::View;
103pub mod extract;
104pub mod handler;
105pub mod plugin;
106pub use anyhow::Error;
107pub mod animation;
108pub use animation::AnimationExt;
109pub use nami as reactive;
110pub use nami::{Binding, Computed, Signal, SignalExt, binding, constant};
111pub use waterui_str::Str;
112pub mod id;
113pub mod layout;
114/// Module for resolving reactive values in different environments.
115pub mod resolve;