parent
0619b79d34
commit
799e337e37
@ -0,0 +1,68 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use winit::event::Event;
|
||||
|
||||
use crate::canvas::canvas_frame::{Drawable, Eventable};
|
||||
use crate::drawables::rect::Rect;
|
||||
use crate::drawables::sprite::Sprite;
|
||||
use crate::util::vertex::VertexType;
|
||||
|
||||
pub struct Slider {
|
||||
handle: Rect,
|
||||
guide: Vec<Rect>,
|
||||
|
||||
scaler: u32,
|
||||
position: (f32, f32),
|
||||
size: (f32, f32),
|
||||
value: u16,
|
||||
}
|
||||
|
||||
impl Slider {
|
||||
pub fn new(size: (f32, f32), position: (f32, f32), value: u16) -> Slider {
|
||||
|
||||
// render the guide first
|
||||
let red = (1.0, 0.0, 0.0, 0.0);
|
||||
let green = (0.0, 1.0, 0.0, 0.0);
|
||||
let blue = (0.0, 1.0, 1.0, 0.0);
|
||||
let rg = (1.0, 1.0, 0.0, 0.0);
|
||||
|
||||
let left_guide_bar = Rect::new((position.0, position.1), (0.01, size.1), 1, red);
|
||||
let right_guide_bar = Rect::new((position.0 + size.0, position.1), (0.01, size.1), 1, blue);
|
||||
let line = Rect::new((position.0, position.1 - (size.1 / 2.0) ), (size.0, 0.01), 1, green);
|
||||
|
||||
let scale = value as f32 / u16::max_value() as f32;
|
||||
let handle = Rect::new((position.0 + (size.0 * scale), position.1), (0.03, size.1), 1, rg);
|
||||
|
||||
Slider {
|
||||
handle: handle,
|
||||
guide: vec![left_guide_bar, right_guide_bar, line],
|
||||
scaler: 255,
|
||||
position,
|
||||
size,
|
||||
value,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drawable for Slider {
|
||||
fn get(&self, window_size: (u32, u32)) -> Vec<VertexType> {
|
||||
let mut vertices = self.handle.get(window_size).clone();
|
||||
|
||||
vertices.extend_from_slice(
|
||||
self.guide.iter()
|
||||
.map(|x| x.get(window_size))
|
||||
.flatten()
|
||||
.collect::<Vec<VertexType>>()
|
||||
.as_slice()
|
||||
);
|
||||
|
||||
vertices.extend_from_slice(self.guide[0].get(window_size).as_slice());
|
||||
vertices
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Eventable<T> for Slider {
|
||||
fn notify(&mut self, event: &Event<T>) -> () {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
Loading…
Reference in new issue