Deprecate bacgroundcolor, update comments

This commit is contained in:
griffi-gh 2024-03-21 23:09:19 +01:00
parent 8a0b8281bc
commit 9600d7f7a9
4 changed files with 27 additions and 5 deletions

View file

@ -1,4 +1,5 @@
//! background color, gradient and texturing //! (deprecated) background color, gradient and texturing
#![allow(deprecated)]
use glam::{vec4, Vec3, Vec4}; use glam::{vec4, Vec3, Vec4};
use crate::rectangle::Corners; use crate::rectangle::Corners;
@ -10,11 +11,20 @@ use crate::rectangle::Corners;
// } // }
//TODO: move this into the color module? //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)] #[derive(Clone, Copy, Default, Debug, PartialEq)]
pub enum BackgroundColor { pub enum BackgroundColor {
/// Transparent background (alpha = 0)
#[default] #[default]
Transparent, Transparent,
/// Solid, RGBA color
Solid(Vec4), Solid(Vec4),
/// Simple gradient color, with different colors for each corner
Gradient(Corners<Vec4>), Gradient(Corners<Vec4>),
} }

View file

@ -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; mod rect;
pub use rect::Rect; pub use rect::Rect;

View file

@ -1,17 +1,21 @@
//! signal handling for UI events
use std::any::{Any, TypeId}; use std::any::{Any, TypeId};
use hashbrown::HashMap; use hashbrown::HashMap;
use nohash_hasher::BuildNoHashHasher; use nohash_hasher::BuildNoHashHasher;
pub mod trigger; pub mod trigger;
/// A marker trait for signals /// A marker trait for UI Signals
pub trait Signal: Any {} pub trait Signal: Any {}
// #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)] // #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
// pub(crate) struct DummySignal; // pub(crate) struct DummySignal;
// impl UiSignal for DummySignal {} // impl UiSignal for DummySignal {}
/// Internal storage for signals
pub struct SignalStore { 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? ///XXX: is this truly the most efficient structure?
sig: HashMap<TypeId, Vec<Box<dyn Any>>, BuildNoHashHasher<u64>> sig: HashMap<TypeId, Vec<Box<dyn Any>>, BuildNoHashHasher<u64>>
} }

View file

@ -1,31 +1,39 @@
//use crate::element::UiElement; //! Contains the implementation of signal triggers, which simplify creation of custom elements
use super::{Signal, SignalStore};
use super::{Signal, SignalStore};
//use crate::element::UiElement;
/// Signal trigger that does not take any arguments
#[allow(clippy::complexity)] #[allow(clippy::complexity)]
pub struct SignalTrigger(Box<dyn Fn(&mut SignalStore)>); pub struct SignalTrigger(Box<dyn Fn(&mut SignalStore)>);
impl SignalTrigger { impl SignalTrigger {
/// Create a new signal trigger from a function or a constructor
pub fn new<S: Signal + 'static, F: Fn() -> S + 'static>(f: F) -> Self { pub fn new<S: Signal + 'static, F: Fn() -> S + 'static>(f: F) -> Self {
Self(Box::new(move |s: &mut SignalStore| { Self(Box::new(move |s: &mut SignalStore| {
s.add::<S>(f()); s.add::<S>(f());
})) }))
} }
/// Fire the signal
pub fn fire(&self, s: &mut SignalStore) { pub fn fire(&self, s: &mut SignalStore) {
(self.0)(s); (self.0)(s);
} }
} }
/// Signal trigger that takes a single argument and passes it to the signal
#[allow(clippy::complexity)] #[allow(clippy::complexity)]
pub struct SignalTriggerArg<T>(Box<dyn Fn(&mut SignalStore, T)>); pub struct SignalTriggerArg<T>(Box<dyn Fn(&mut SignalStore, T)>);
impl<T> SignalTriggerArg<T> { impl<T> SignalTriggerArg<T> {
/// Create a new signal trigger from a function or a constructor
pub fn new<S: Signal, F: Fn(T) -> S + 'static>(f: F) -> Self { pub fn new<S: Signal, F: Fn(T) -> S + 'static>(f: F) -> Self {
Self(Box::new(move |s: &mut SignalStore, x| { Self(Box::new(move |s: &mut SignalStore, x| {
s.add::<S>(f(x)); s.add::<S>(f(x));
})) }))
} }
/// Fire the signal with the given argument
pub fn fire(&self, s: &mut SignalStore, x: T) { pub fn fire(&self, s: &mut SignalStore, x: T) {
(self.0)(s, x); (self.0)(s, x);
} }