-
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.
updated number input to newest style
- Loading branch information
genusistimelord
committed
May 21, 2024
1 parent
f215636
commit b802445
Showing
10 changed files
with
124 additions
and
202 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,115 +1,56 @@ | ||
use iced::{ | ||
alignment, font, | ||
theme::Theme, | ||
widget::{container, text, Container, Row, Text}, | ||
window, Alignment, Application, Command, Element, Length, Settings, | ||
widget::{Container, Row, Text}, | ||
Alignment, Element, Length, | ||
}; | ||
use iced_aw::{number_input, style::NumberInputStyles}; | ||
|
||
#[derive(Debug)] | ||
enum NumberInputDemo { | ||
Loading, | ||
Loaded(State), | ||
} | ||
use iced_aw::number_input; | ||
|
||
#[derive(Default, Debug)] | ||
pub struct State { | ||
pub struct NumberInputDemo { | ||
value: f32, | ||
} | ||
|
||
#[derive(Debug, Clone)] | ||
pub enum Message { | ||
NumInpChanged(f32), | ||
Loaded(Result<(), String>), | ||
FontLoaded(Result<(), font::Error>), | ||
} | ||
|
||
fn main() -> iced::Result { | ||
NumberInputDemo::run(Settings { | ||
default_text_size: iced::Pixels(12.0), | ||
window: window::Settings { | ||
size: iced::Size { | ||
width: 250.0, | ||
height: 200.0, | ||
}, | ||
..Default::default() | ||
}, | ||
..Settings::default() | ||
iced::program( | ||
"Number Input example", | ||
NumberInputDemo::update, | ||
NumberInputDemo::view, | ||
) | ||
.window_size(iced::Size { | ||
width: 250.0, | ||
height: 200.0, | ||
}) | ||
.font(iced_aw::BOOTSTRAP_FONT_BYTES) | ||
.run() | ||
} | ||
|
||
async fn load() -> Result<(), String> { | ||
Ok(()) | ||
} | ||
|
||
impl Application for NumberInputDemo { | ||
type Message = Message; | ||
type Theme = Theme; | ||
type Executor = iced::executor::Default; | ||
type Flags = (); | ||
|
||
fn new(_flags: ()) -> (NumberInputDemo, Command<Message>) { | ||
( | ||
NumberInputDemo::Loading, | ||
Command::batch(vec![ | ||
font::load(iced_aw::BOOTSTRAP_FONT_BYTES).map(Message::FontLoaded), | ||
Command::perform(load(), Message::Loaded), | ||
]), | ||
) | ||
} | ||
|
||
fn title(&self) -> String { | ||
String::from("Number Input Demo") | ||
} | ||
|
||
fn update(&mut self, message: self::Message) -> Command<Message> { | ||
match self { | ||
NumberInputDemo::Loading => { | ||
if let Message::Loaded(_) = message { | ||
*self = NumberInputDemo::Loaded(State { value: 27.0 }) | ||
} | ||
} | ||
NumberInputDemo::Loaded(State { value }) => { | ||
if let Message::NumInpChanged(val) = message { | ||
*value = val; | ||
} | ||
} | ||
} | ||
|
||
Command::none() | ||
impl NumberInputDemo { | ||
fn update(&mut self, message: self::Message) { | ||
let Message::NumInpChanged(val) = message; | ||
self.value = val; | ||
} | ||
|
||
fn view(&self) -> Element<Message> { | ||
match self { | ||
NumberInputDemo::Loading => container( | ||
text("Loading...") | ||
.horizontal_alignment(alignment::Horizontal::Center) | ||
.size(50), | ||
) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.center_y() | ||
.center_x() | ||
.into(), | ||
NumberInputDemo::Loaded(State { value }) => { | ||
let lb_minute = Text::new("Number Input:"); | ||
let txt_minute = number_input(*value, 0.0..250.0, Message::NumInpChanged) | ||
.style(NumberInputStyles::Default) | ||
.step(0.5); | ||
|
||
Container::new( | ||
Row::new() | ||
.spacing(10) | ||
.align_items(Alignment::Center) | ||
.push(lb_minute) | ||
.push(txt_minute), | ||
) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.center_x() | ||
.center_y() | ||
.into() | ||
} | ||
} | ||
let lb_minute = Text::new("Number Input:"); | ||
let txt_minute = number_input(self.value, 0.0..250.0, Message::NumInpChanged) | ||
.style(number_input::number_input::primary) | ||
.step(0.5); | ||
|
||
Container::new( | ||
Row::new() | ||
.spacing(10) | ||
.align_items(Alignment::Center) | ||
.push(lb_minute) | ||
.push(txt_minute), | ||
) | ||
.width(Length::Fill) | ||
.height(Length::Fill) | ||
.center_x(Length::Fill) | ||
.center_y(Length::Fill) | ||
.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
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
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.