Skip to content

Commit

Permalink
Simplify slider example
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 31, 2024
1 parent cd03a0d commit 468f6a4
Showing 1 changed file with 18 additions and 23 deletions.
41 changes: 18 additions & 23 deletions examples/slider/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ pub enum Message {
}

pub struct Slider {
slider_value: u8,
slider_default: u8,
slider_step: u8,
slider_step_fine: u8,
value: u8,
default: u8,
step: u8,
shift_step: u8,
}

impl Sandbox for Slider {
type Message = Message;

fn new() -> Slider {
Slider {
slider_value: 50,
slider_default: 50,
slider_step: 5,
slider_step_fine: 1,
value: 50,
default: 50,
step: 5,
shift_step: 1,
}
}

Expand All @@ -36,34 +36,29 @@ impl Sandbox for Slider {
fn update(&mut self, message: Message) {
match message {
Message::SliderChanged(value) => {
self.slider_value = value;
self.value = value;
}
}
}

fn view(&self) -> Element<Message> {
let value = self.slider_value;
let default = self.slider_default;
let step = self.slider_step;
let step_fine = self.slider_step_fine;

let h_slider = container(
slider(0..=100, value, Message::SliderChanged)
.default(default)
.step(step)
.step_fine(step_fine),
slider(0..=100, self.value, Message::SliderChanged)
.default(self.default)
.step(self.step)
.shift_step(self.shift_step),
)
.width(250);

let v_slider = container(
vertical_slider(0..=100, value, Message::SliderChanged)
.default(default)
.step(step)
.step_fine(step_fine),
vertical_slider(0..=100, self.value, Message::SliderChanged)
.default(self.default)
.step(self.step)
.shift_step(self.shift_step),
)
.height(200);

let text = text(format!("{value}"));
let text = text(self.value);

container(
column![
Expand Down

0 comments on commit 468f6a4

Please sign in to comment.