-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1596 from casperstorm/feat/slider-orientation
Added a VerticalSlider widget.
- Loading branch information
Showing
8 changed files
with
578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "slider" | ||
version = "0.1.0" | ||
authors = ["Casper Rogild Storm<casper@rogildstorm.com>"] | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
iced = { path = "../.." } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
## Slider | ||
|
||
A `Slider` is a bar and a handle that selects a single value from a range of values. | ||
There exists both `Slider` and `VerticalSlider` depending on which orientation you need. | ||
|
||
<div align="center"> | ||
<img src="sliders.gif"> | ||
</div> | ||
|
||
You can run it with `cargo run`: | ||
|
||
``` | ||
cargo run --package slider | ||
``` |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use iced::widget::{column, container, slider, text, vertical_slider}; | ||
use iced::{Element, Length, Sandbox, Settings}; | ||
|
||
pub fn main() -> iced::Result { | ||
Slider::run(Settings::default()) | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Message { | ||
SliderChanged(u8), | ||
} | ||
|
||
pub struct Slider { | ||
slider_value: u8, | ||
} | ||
|
||
impl Sandbox for Slider { | ||
type Message = Message; | ||
|
||
fn new() -> Slider { | ||
Slider { slider_value: 50 } | ||
} | ||
|
||
fn title(&self) -> String { | ||
String::from("Slider - Iced") | ||
} | ||
|
||
fn update(&mut self, message: Message) { | ||
match message { | ||
Message::SliderChanged(value) => { | ||
self.slider_value = value; | ||
} | ||
} | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
let value = self.slider_value; | ||
|
||
let h_slider = | ||
container(slider(0..=100, value, Message::SliderChanged)) | ||
.width(Length::Units(250)); | ||
|
||
let v_slider = | ||
container(vertical_slider(0..=100, value, Message::SliderChanged)) | ||
.height(Length::Units(200)); | ||
|
||
let text = text(format!("{value}")); | ||
|
||
container( | ||
column![ | ||
container(v_slider).width(Length::Fill).center_x(), | ||
container(h_slider).width(Length::Fill).center_x(), | ||
container(text).width(Length::Fill).center_x(), | ||
] | ||
.spacing(25), | ||
) | ||
.height(Length::Fill) | ||
.width(Length::Fill) | ||
.center_x() | ||
.center_y() | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.