|
|
|
@ -1,11 +1,12 @@
|
|
|
|
|
use std::collections::HashSet;
|
|
|
|
|
|
|
|
|
|
use winit::event::Event;
|
|
|
|
|
use winit::event::{Event, ElementState, MouseButton};
|
|
|
|
|
|
|
|
|
|
use crate::canvas::canvas_frame::{Drawable, Eventable};
|
|
|
|
|
use crate::drawables::rect::Rect;
|
|
|
|
|
use crate::drawables::sprite::Sprite;
|
|
|
|
|
use crate::util::vertex::VertexTypeContainer;
|
|
|
|
|
use crate::util::tr_event::{TrEvent, TrWindowEvent};
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
|
pub struct Slider {
|
|
|
|
@ -43,6 +44,26 @@ impl Slider {
|
|
|
|
|
value,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update(&mut self) {
|
|
|
|
|
|
|
|
|
|
// 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((self.position.0, self.position.1), (2.0, self.size.1), 1, red);
|
|
|
|
|
let right_guide_bar = Rect::new((self.position.0 + self.size.0, self.position.1), (2.0, self.size.1), 1, blue);
|
|
|
|
|
let line = Rect::new((self.position.0, self.position.1 - (self.size.1 / 2.0)), (self.size.0, 2.0), 1, green);
|
|
|
|
|
|
|
|
|
|
let scale = self.value as f32 / u16::max_value() as f32;
|
|
|
|
|
let handle = Rect::new((self.position.0 + (self.size.0 * scale), self.position.1), (15.0, self.size.1), 1, rg);
|
|
|
|
|
|
|
|
|
|
self.handle = handle;
|
|
|
|
|
self.guide = vec![left_guide_bar, right_guide_bar, line];
|
|
|
|
|
self.scaler = 255;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Drawable for Slider {
|
|
|
|
@ -85,7 +106,24 @@ impl Drawable for Slider {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<T> Eventable<T> for Slider {
|
|
|
|
|
fn notify(&mut self, event: &Event<T>) -> () {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
fn notify(&mut self, event: &TrEvent<T>) -> () {
|
|
|
|
|
match event {
|
|
|
|
|
TrEvent::WindowEvent { event: TrWindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
match button {
|
|
|
|
|
MouseButton::Left => {
|
|
|
|
|
if *state == ElementState::Pressed {
|
|
|
|
|
self.position.0 += 30.0;
|
|
|
|
|
self.value += 10;
|
|
|
|
|
self.update()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|