|
|
|
@ -9,6 +9,7 @@ pub struct Slider<'a> {
|
|
|
|
|
right_button: Button<'a>,
|
|
|
|
|
slider_button: Button<'a>,
|
|
|
|
|
rail: RectangleShape<'a>,
|
|
|
|
|
root_position: Vector2f,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a> Slider<'a> {
|
|
|
|
@ -30,10 +31,9 @@ impl<'a> Slider<'a> {
|
|
|
|
|
right_button: Button::new(Vector2f::new(30.0, 50.0), right_button_position, font),
|
|
|
|
|
slider_button: Button::new(Vector2f::new(30.0, 50.0), slider_position, font),
|
|
|
|
|
rail: RectangleShape::with_size(Vector2f::new(150.0, 2.0)),
|
|
|
|
|
root_position: position,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
slider.left_button.set_callback(&|a| slider.set_value(a));
|
|
|
|
|
|
|
|
|
|
slider.left_button.set_text("<");
|
|
|
|
|
slider.right_button.set_text(">");
|
|
|
|
|
|
|
|
|
@ -42,10 +42,18 @@ impl<'a> Slider<'a> {
|
|
|
|
|
slider
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_value(&mut self, inp: i32){
|
|
|
|
|
self.value += 1.0;
|
|
|
|
|
pub fn click(&mut self, click: Vector2f) {
|
|
|
|
|
if Button::is_within(click, &self.left_button) {
|
|
|
|
|
self.value -= 1.0;
|
|
|
|
|
}
|
|
|
|
|
if Button::is_within(click, &self.right_button) {
|
|
|
|
|
self.value += 1.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn update(&mut self) {
|
|
|
|
|
self.slider_button.set_position(self.root_position + Vector2f::new(self.value,0.0));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'s> Drawable for Slider<'s> {
|
|
|
|
|