diff --git a/hui/src/background.rs b/hui/src/background.rs index 146667c..47243cb 100644 --- a/hui/src/background.rs +++ b/hui/src/background.rs @@ -1,4 +1,5 @@ -//! background color, gradient and texturing +//! (deprecated) background color, gradient and texturing +#![allow(deprecated)] use glam::{vec4, Vec3, Vec4}; use crate::rectangle::Corners; @@ -10,11 +11,20 @@ use crate::rectangle::Corners; // } //TODO: move this into the color module? +/// Represents the background color of an element +/// +/// Can be either a solid color, a gradient or transparent +#[deprecated(note = "Use `CornersColors` instead")] #[derive(Clone, Copy, Default, Debug, PartialEq)] pub enum BackgroundColor { + /// Transparent background (alpha = 0) #[default] Transparent, + + /// Solid, RGBA color Solid(Vec4), + + /// Simple gradient color, with different colors for each corner Gradient(Corners), } diff --git a/hui/src/rectangle.rs b/hui/src/rectangle.rs index 3213bba..68917ff 100644 --- a/hui/src/rectangle.rs +++ b/hui/src/rectangle.rs @@ -1,4 +1,4 @@ -//! Contains types which represent the sides and corners of a rectangular shape. +//! contains types which represent the sides and corners of a rectangular shape. mod rect; pub use rect::Rect; diff --git a/hui/src/signal.rs b/hui/src/signal.rs index 2016d5e..1347e6f 100644 --- a/hui/src/signal.rs +++ b/hui/src/signal.rs @@ -1,17 +1,21 @@ +//! signal handling for UI events + use std::any::{Any, TypeId}; use hashbrown::HashMap; use nohash_hasher::BuildNoHashHasher; pub mod trigger; -/// A marker trait for signals +/// A marker trait for UI Signals pub trait Signal: Any {} // #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] // pub(crate) struct DummySignal; // impl UiSignal for DummySignal {} +/// Internal storage for signals pub struct SignalStore { + //TODO use a multithreaded queue instead, to allow easily offloading ui processing to a different thread ///XXX: is this truly the most efficient structure? sig: HashMap>, BuildNoHashHasher> } diff --git a/hui/src/signal/trigger.rs b/hui/src/signal/trigger.rs index 5204080..f5081b8 100644 --- a/hui/src/signal/trigger.rs +++ b/hui/src/signal/trigger.rs @@ -1,31 +1,39 @@ -//use crate::element::UiElement; -use super::{Signal, SignalStore}; +//! Contains the implementation of signal triggers, which simplify creation of custom elements +use super::{Signal, SignalStore}; +//use crate::element::UiElement; + +/// Signal trigger that does not take any arguments #[allow(clippy::complexity)] pub struct SignalTrigger(Box); impl SignalTrigger { + /// Create a new signal trigger from a function or a constructor pub fn new S + 'static>(f: F) -> Self { Self(Box::new(move |s: &mut SignalStore| { s.add::(f()); })) } + /// Fire the signal pub fn fire(&self, s: &mut SignalStore) { (self.0)(s); } } +/// Signal trigger that takes a single argument and passes it to the signal #[allow(clippy::complexity)] pub struct SignalTriggerArg(Box); impl SignalTriggerArg { + /// Create a new signal trigger from a function or a constructor pub fn new S + 'static>(f: F) -> Self { Self(Box::new(move |s: &mut SignalStore, x| { s.add::(f(x)); })) } + /// Fire the signal with the given argument pub fn fire(&self, s: &mut SignalStore, x: T) { (self.0)(s, x); }