Skip to main content

horizon_lattice_core/
lib.rs

1//! Core systems for Horizon Lattice.
2//!
3//! This crate provides the foundational components of the Horizon Lattice GUI framework:
4
5#![warn(missing_docs)]
6// Allow complex types in the meta-object system - these are intentional for type-safe signal/slot
7#![allow(clippy::type_complexity)]
8//!
9//! - **Event Loop**: The main application event loop built on winit
10//! - **Application**: Global application state and lifecycle management
11//! - **Object Model**: Parent-child ownership, naming, dynamic properties
12//! - **Signal/Slot System**: Type-safe inter-object communication
13//! - **Property System**: Reactive properties with change notification
14//! - **Timers**: One-shot and repeating timer system
15//! - **Task Queue**: Deferred/idle task processing
16//! - **Scheduler**: Background work scheduling with one-shot and periodic tasks
17//!
18//! # Signal/Slot Example
19//!
20//! ```
21//! use horizon_lattice_core::{Signal, Property};
22//!
23//! // Create a signal that notifies when a value changes
24//! let value_changed = Signal::<i32>::new();
25//!
26//! // Connect a slot to handle the signal
27//! let conn_id = value_changed.connect(|value| {
28//!     println!("Value changed to: {}", value);
29//! });
30//!
31//! // Emit the signal
32//! value_changed.emit(42);
33//!
34//! // Disconnect when done
35//! value_changed.disconnect(conn_id);
36//! ```
37//!
38//! # Property Example
39//!
40//! ```
41//! use horizon_lattice_core::{Property, Signal};
42//!
43//! // A reactive counter with change notification
44//! struct Counter {
45//!     value: Property<i32>,
46//!     value_changed: Signal<i32>,
47//! }
48//!
49//! impl Counter {
50//!     fn new() -> Self {
51//!         Self {
52//!             value: Property::new(0),
53//!             value_changed: Signal::new(),
54//!         }
55//!     }
56//!
57//!     fn increment(&self) {
58//!         let new_value = self.value.get() + 1;
59//!         if self.value.set(new_value) {
60//!             self.value_changed.emit(new_value);
61//!         }
62//!     }
63//! }
64//! ```
65//!
66//! # Event Loop Example
67//!
68//! ```no_run
69//! use horizon_lattice_core::{Application, LatticeEvent};
70//! use std::time::Duration;
71//!
72//! fn main() -> Result<(), Box<dyn std::error::Error>> {
73//!     let app = Application::new()?;
74//!
75//!     // Set up an event handler
76//!     app.set_event_handler(|event| {
77//!         match event {
78//!             LatticeEvent::Timer { id } => {
79//!                 println!("Timer {:?} fired!", id);
80//!             }
81//!             _ => {}
82//!         }
83//!     });
84//!
85//!     // Start a repeating timer
86//!     let _timer_id = app.start_repeating_timer(Duration::from_secs(1));
87//!
88//!     // Post a deferred task
89//!     app.post_task(|| {
90//!         println!("Idle task executed!");
91//!     });
92//!
93//!     // Run the event loop (blocks until quit)
94//!     Ok(app.run()?)
95//! }
96//! ```
97
98mod application;
99#[cfg(feature = "tokio")]
100pub mod async_runtime;
101mod error;
102mod event;
103pub mod invocation;
104pub mod logging;
105pub mod meta;
106pub mod object;
107pub mod progress;
108pub mod property;
109mod scheduler;
110pub mod signal;
111mod task;
112pub mod thread_check;
113pub mod threadpool;
114mod timer;
115pub mod worker;
116
117pub use application::{Application, WindowEventHandler};
118pub use error::{
119    LatticeError, Result, SchedulerError, SignalError, ThreadError, ThreadPoolError, TimerError,
120};
121pub use event::{EventPriority, LatticeEvent};
122pub use logging::{ObjectTreeDebug, PerfSpan, TreeFormatOptions, TreeStyle};
123pub use meta::{
124    MetaError, MetaObject, MetaProperty, MetaResult, MethodMeta, SignalMeta, TypeRegistry,
125    init_type_registry,
126};
127pub use object::{
128    Object, ObjectBase, ObjectError, ObjectId, ObjectRegistry, ObjectResult, SharedObjectRegistry,
129    WidgetState, global_registry, init_global_registry, object_cast, object_cast_mut,
130};
131pub use progress::{AggregateProgress, ProgressReporter, ProgressUpdate};
132pub use property::{
133    Binding, IntoProperty, Property, PropertyError, PropertyMeta, ReadOnlyProperty,
134};
135pub use scheduler::{ScheduledTaskId, ScheduledTaskKind};
136pub use signal::{ConnectionGuard, ConnectionId, ConnectionType, Signal, SignalEmitter};
137pub use task::TaskId;
138pub use thread_check::{
139    ThreadAffinity, are_thread_checks_enabled, is_main_thread, main_thread_id,
140    set_thread_checks_enabled,
141};
142pub use timer::TimerId;
143pub use worker::{Worker, WorkerBuilder, WorkerConfig};
144
145// Re-export winit types that users may need
146pub use winit::event::Modifiers;
147pub use winit::event_loop::ActiveEventLoop;
148pub use winit::window::{Window, WindowAttributes, WindowId};