background
This commit is contained in:
parent
ddd2e363c2
commit
01e33afd93
3 changed files with 363 additions and 13 deletions
|
@ -133,3 +133,81 @@ impl UIColor for Colors {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO : Gradient
|
||||
|
||||
pub struct Gradient {
|
||||
start: Box<dyn UIColor>,
|
||||
middle: Option<Box<dyn UIColor>>,
|
||||
end: Option<Box<dyn UIColor>>,
|
||||
pos_start: Option<u8>,
|
||||
pos_middle: Option<u8>,
|
||||
pos_end: Option<u8>,
|
||||
}
|
||||
|
||||
impl Gradient {
|
||||
pub fn from<C: UIColor + 'static>(start: C) -> Self {
|
||||
Self {
|
||||
start: Box::new(start),
|
||||
middle: None,
|
||||
end: None,
|
||||
pos_end: None,
|
||||
pos_middle: None,
|
||||
pos_start: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn via<C: UIColor + 'static>(mut self, middle: C) -> Self {
|
||||
self.middle = Some(Box::new(middle));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn to<C: UIColor + 'static>(mut self, end: C) -> Self {
|
||||
self.end = Some(Box::new(end));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn step_start(mut self, percentage: u8) -> Self {
|
||||
assert!(percentage <= 100, "Percentage should be under 100%");
|
||||
self.pos_start = Some(percentage);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn step_middle(mut self, percentage: u8) -> Self {
|
||||
assert!(percentage <= 100, "Percentage should be under 100%");
|
||||
self.pos_middle = Some(percentage);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn step_end(mut self, percentage: u8) -> Self {
|
||||
assert!(percentage <= 100, "Percentage should be under 100%");
|
||||
self.pos_end = Some(percentage);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn color_class(&self) -> Vec<String> {
|
||||
let mut classes = vec![format!("from-{}", self.start.color_class())];
|
||||
|
||||
if let Some(via) = &self.middle {
|
||||
classes.push(format!("via-{}", via.color_class()));
|
||||
}
|
||||
|
||||
if let Some(end) = &self.end {
|
||||
classes.push(format!("to-{}", end.color_class()));
|
||||
}
|
||||
|
||||
if let Some(step) = &self.pos_start {
|
||||
classes.push(format!("from-{step}%"));
|
||||
}
|
||||
|
||||
if let Some(step) = &self.pos_middle {
|
||||
classes.push(format!("via-{step}%"));
|
||||
}
|
||||
|
||||
if let Some(step) = &self.pos_end {
|
||||
classes.push(format!("to-{step}%"));
|
||||
}
|
||||
|
||||
classes
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue