Skip to main content

Crate horizon_lattice_core

Crate horizon_lattice_core 

Source
Expand description

Core systems for Horizon Lattice.

This crate provides the foundational components of the Horizon Lattice GUI framework:

  • Event Loop: The main application event loop built on winit
  • Application: Global application state and lifecycle management
  • Object Model: Parent-child ownership, naming, dynamic properties
  • Signal/Slot System: Type-safe inter-object communication
  • Property System: Reactive properties with change notification
  • Timers: One-shot and repeating timer system
  • Task Queue: Deferred/idle task processing
  • Scheduler: Background work scheduling with one-shot and periodic tasks

§Signal/Slot Example

use horizon_lattice_core::{Signal, Property};

// Create a signal that notifies when a value changes
let value_changed = Signal::<i32>::new();

// Connect a slot to handle the signal
let conn_id = value_changed.connect(|value| {
    println!("Value changed to: {}", value);
});

// Emit the signal
value_changed.emit(42);

// Disconnect when done
value_changed.disconnect(conn_id);

§Property Example

use horizon_lattice_core::{Property, Signal};

// A reactive counter with change notification
struct Counter {
    value: Property<i32>,
    value_changed: Signal<i32>,
}

impl Counter {
    fn new() -> Self {
        Self {
            value: Property::new(0),
            value_changed: Signal::new(),
        }
    }

    fn increment(&self) {
        let new_value = self.value.get() + 1;
        if self.value.set(new_value) {
            self.value_changed.emit(new_value);
        }
    }
}

§Event Loop Example

use horizon_lattice_core::{Application, LatticeEvent};
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new()?;

    // Set up an event handler
    app.set_event_handler(|event| {
        match event {
            LatticeEvent::Timer { id } => {
                println!("Timer {:?} fired!", id);
            }
            _ => {}
        }
    });

    // Start a repeating timer
    let _timer_id = app.start_repeating_timer(Duration::from_secs(1));

    // Post a deferred task
    app.post_task(|| {
        println!("Idle task executed!");
    });

    // Run the event loop (blocks until quit)
    Ok(app.run()?)
}

Re-exports§

pub use logging::ObjectTreeDebug;
pub use logging::PerfSpan;
pub use logging::TreeFormatOptions;
pub use logging::TreeStyle;
pub use meta::MetaError;
pub use meta::MetaObject;
pub use meta::MetaProperty;
pub use meta::MetaResult;
pub use meta::MethodMeta;
pub use meta::SignalMeta;
pub use meta::TypeRegistry;
pub use meta::init_type_registry;
pub use object::Object;
pub use object::ObjectBase;
pub use object::ObjectError;
pub use object::ObjectId;
pub use object::ObjectRegistry;
pub use object::ObjectResult;
pub use object::SharedObjectRegistry;
pub use object::WidgetState;
pub use object::global_registry;
pub use object::init_global_registry;
pub use object::object_cast;
pub use object::object_cast_mut;
pub use progress::AggregateProgress;
pub use progress::ProgressReporter;
pub use progress::ProgressUpdate;
pub use property::Binding;
pub use property::IntoProperty;
pub use property::Property;
pub use property::PropertyError;
pub use property::PropertyMeta;
pub use property::ReadOnlyProperty;
pub use signal::ConnectionGuard;
pub use signal::ConnectionId;
pub use signal::ConnectionType;
pub use signal::Signal;
pub use signal::SignalEmitter;
pub use thread_check::ThreadAffinity;
pub use thread_check::are_thread_checks_enabled;
pub use thread_check::is_main_thread;
pub use thread_check::main_thread_id;
pub use thread_check::set_thread_checks_enabled;
pub use worker::Worker;
pub use worker::WorkerBuilder;
pub use worker::WorkerConfig;

Modules§

invocation
Queued invocation registry for cross-thread signal delivery.
logging
Logging and debugging facilities for Horizon Lattice.
meta
Meta-object system for Horizon Lattice.
object
Object model for Horizon Lattice.
progress
Progress reporting for background tasks.
property
Property system for Horizon Lattice.
signal
Signal/slot system for Horizon Lattice.
thread_check
Thread safety verification utilities for Horizon Lattice.
threadpool
Thread pool for background task execution.
worker
Worker pattern for dedicated background thread processing.

Macros§

assert_main_thread
Panics if the current thread is not the main thread.
debug_assert_main_thread
Debug-only assertion that panics if not on the main thread.
lattice_debug
Log a debug-level message to the Horizon Lattice target.
lattice_error
Log an error-level message to the Horizon Lattice target.
lattice_info
Log an info-level message to the Horizon Lattice target.
lattice_trace
Macros for common tracing patterns.
lattice_warn
Log a warning-level message to the Horizon Lattice target.

Structs§

ActiveEventLoop
Target that associates windows with an EventLoop.
Application
The main application event loop and coordinator.
Modifiers
Describes keyboard modifiers event.
ScheduledTaskId
A unique identifier for a scheduled task.
TaskId
A unique identifier for a deferred task.
TimerId
A unique identifier for a timer.
Window
Represents a window.
WindowAttributes
Attributes used when creating a window.
WindowId
Identifier of a window. Unique for each window.

Enums§

EventPriority
Priority levels for internal events. Higher priority events are processed first within the same event loop iteration.
LatticeError
The main error type for Horizon Lattice operations.
LatticeEvent
Internal events dispatched through the Horizon Lattice event loop.
ScheduledTaskKind
The type of scheduled task.
SchedulerError
Scheduler-specific errors.
SignalError
Signal-specific errors.
ThreadError
Thread safety-specific errors.
ThreadPoolError
Thread pool-specific errors.
TimerError
Timer-specific errors.

Type Aliases§

Result
A specialized Result type for Horizon Lattice operations.
WindowEventHandler
The main application struct, managing the event loop and global state.