going to just use the ol update and click routine

master
mitchellhansen 5 years ago
parent 35b4907d5d
commit cc5b2a346e

@ -36,8 +36,8 @@ impl<'s> Button<'s> {
self.text.set_position(position); self.text.set_position(position);
} }
pub fn set_callback(&mut self, callback: &'s FnMut(i32)){ pub fn is_within(point: Vector2f, button: &Button) -> bool {
self.callback = Some(callback); button.body.local_bounds().contains(point)
} }
} }

@ -9,6 +9,7 @@ pub struct Slider<'a> {
right_button: Button<'a>, right_button: Button<'a>,
slider_button: Button<'a>, slider_button: Button<'a>,
rail: RectangleShape<'a>, rail: RectangleShape<'a>,
root_position: Vector2f,
} }
impl<'a> Slider<'a> { 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), 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), slider_button: Button::new(Vector2f::new(30.0, 50.0), slider_position, font),
rail: RectangleShape::with_size(Vector2f::new(150.0, 2.0)), 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.left_button.set_text("<");
slider.right_button.set_text(">"); slider.right_button.set_text(">");
@ -42,10 +42,18 @@ impl<'a> Slider<'a> {
slider slider
} }
pub fn set_value(&mut self, inp: i32){ 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; 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> { impl<'s> Drawable for Slider<'s> {

Loading…
Cancel
Save