-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
genusistimelord
committed
Nov 20, 2023
1 parent
529199c
commit 5f56c7e
Showing
9 changed files
with
522 additions
and
59 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "slidebar" | ||
version = "0.1.0" | ||
authors = ["Andrew Wheeler <[email protected]>"] | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
iced_aw.workspace = true | ||
iced.workspace = true |
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,57 @@ | ||
use iced::{ | ||
widget::{Column, Container, Text}, | ||
Element, Length, Sandbox, Settings, | ||
}; | ||
|
||
use iced_aw::SlideBar; | ||
|
||
fn main() -> iced::Result { | ||
SlideBarExample::run(Settings::default()) | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
enum Message { | ||
SliderBarChange(u32), | ||
} | ||
|
||
struct SlideBarExample { | ||
value: u32, | ||
} | ||
|
||
impl Sandbox for SlideBarExample { | ||
type Message = Message; | ||
|
||
fn new() -> Self { | ||
SlideBarExample { value: 1 } | ||
} | ||
|
||
fn title(&self) -> String { | ||
String::from("Slider Bar example") | ||
} | ||
|
||
fn update(&mut self, message: Message) { | ||
let Message::SliderBarChange(v) = message; | ||
self.value = v; | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
let bar = SlideBar::new(0..=100, self.value, Message::SliderBarChange).width(100.0); | ||
|
||
let content_all = Column::new() | ||
.spacing(10) | ||
.push( | ||
Text::new(format!("Value is {}", self.value)) | ||
.width(Length::Fill) | ||
.vertical_alignment(iced::alignment::Vertical::Center).horizontal_alignment(iced::alignment::Horizontal::Center), | ||
) | ||
.push(bar) | ||
.align_items(iced::Alignment::Center); | ||
|
||
Container::new(content_all) | ||
.width(Length::Fill) | ||
.height(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
//! Common types for reuse. | ||
//! | ||
use iced_widget::core::{Padding, Rectangle}; | ||
|
||
/// Methods for creating inner bounds | ||
#[allow(missing_debug_implementations)] | ||
pub enum InnerBounds { | ||
/// Create inner bounds ratio to the outer bounds | ||
Ratio(f32, f32), | ||
/// Create inner bounds by padding the outer bounds | ||
Padding(Padding), | ||
/// Create square inner bounds | ||
Square(f32), | ||
/// Create inner bounds with a custom function | ||
Custom(Box<dyn Fn(Rectangle) -> Rectangle>), | ||
} | ||
impl InnerBounds { | ||
/// Gets the inner bounds of the Set type. | ||
pub fn get_bounds(&self, outer_bounds: Rectangle) -> Rectangle { | ||
use InnerBounds::{Custom, Padding, Ratio, Square}; | ||
match self { | ||
Ratio(w, h) => { | ||
let width = w * outer_bounds.width; | ||
let height = h * outer_bounds.height; | ||
let x = outer_bounds.x + (outer_bounds.width - width) * 0.5; | ||
let y = outer_bounds.y + (outer_bounds.height - height) * 0.5; | ||
Rectangle { | ||
x, | ||
y, | ||
width, | ||
height, | ||
} | ||
} | ||
Padding(p) => { | ||
let x = outer_bounds.x + p.left; | ||
let y = outer_bounds.y + p.top; | ||
let width = outer_bounds.width - p.horizontal(); | ||
let height = outer_bounds.width - p.vertical(); | ||
Rectangle { | ||
x, | ||
y, | ||
width, | ||
height, | ||
} | ||
} | ||
Square(l) => { | ||
let width = *l; | ||
let height = *l; | ||
let x = outer_bounds.x + (outer_bounds.width - width) * 0.5; | ||
let y = outer_bounds.y + (outer_bounds.height - height) * 0.5; | ||
Rectangle { | ||
x, | ||
y, | ||
width, | ||
height, | ||
} | ||
} | ||
Custom(f) => f(outer_bounds), | ||
} | ||
} | ||
} |
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.