From cc5b2a346e5dfb2077446a9e6f57ceb723c74488 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Sun, 7 Jul 2019 02:53:37 -0700 Subject: [PATCH] going to just use the ol update and click routine --- src/button.rs | 4 ++-- src/slider.rs | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/button.rs b/src/button.rs index 634e012c..1812670c 100644 --- a/src/button.rs +++ b/src/button.rs @@ -36,8 +36,8 @@ impl<'s> Button<'s> { self.text.set_position(position); } - pub fn set_callback(&mut self, callback: &'s FnMut(i32)){ - self.callback = Some(callback); + pub fn is_within(point: Vector2f, button: &Button) -> bool { + button.body.local_bounds().contains(point) } } diff --git a/src/slider.rs b/src/slider.rs index 210047bf..4879a012 100644 --- a/src/slider.rs +++ b/src/slider.rs @@ -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> {