mirror of
https://github.com/griffi-gh/hUI.git
synced 2024-11-21 22:58:42 -06:00
Deprecate bacgroundcolor, update comments
This commit is contained in:
parent
8a0b8281bc
commit
9600d7f7a9
|
@ -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<Vec4>),
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<TypeId, Vec<Box<dyn Any>>, BuildNoHashHasher<u64>>
|
||||
}
|
||||
|
|
|
@ -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<dyn Fn(&mut SignalStore)>);
|
||||
|
||||
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 {
|
||||
Self(Box::new(move |s: &mut SignalStore| {
|
||||
s.add::<S>(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<T>(Box<dyn Fn(&mut SignalStore, 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 {
|
||||
Self(Box::new(move |s: &mut SignalStore, x| {
|
||||
s.add::<S>(f(x));
|
||||
}))
|
||||
}
|
||||
|
||||
/// Fire the signal with the given argument
|
||||
pub fn fire(&self, s: &mut SignalStore, x: T) {
|
||||
(self.0)(s, x);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue