forked from iced-rs/iced_aw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
number_input.rs
61 lines (54 loc) · 1.47 KB
/
number_input.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// This example demonstrates how to use the number input widget
//
// It was written by leang27 <[email protected]>
use iced::{
widget::{Container, Row, Text},
Alignment, Element, Length,
};
use iced_aw::number_input;
#[derive(Default, Debug)]
pub struct NumberInputDemo {
value: f32,
}
#[derive(Debug, Clone)]
pub enum Message {
NumInpChanged(f32),
}
fn main() -> iced::Result {
iced::application(
"Number Input example",
NumberInputDemo::update,
NumberInputDemo::view,
)
.window_size(iced::Size {
width: 250.0,
height: 200.0,
})
.font(iced_fonts::REQUIRED_FONT_BYTES)
.run()
}
impl NumberInputDemo {
fn update(&mut self, message: self::Message) {
let Message::NumInpChanged(val) = message;
println!("Value changed to {:?}", val);
self.value = val;
}
fn view(&self) -> Element<Message> {
let lb_minute = Text::new("Number Input:");
let txt_minute = number_input(self.value, -10.0..250.0, Message::NumInpChanged)
.style(number_input::number_input::primary)
.step(0.5);
Container::new(
Row::new()
.spacing(10)
.align_y(Alignment::Center)
.push(lb_minute)
.push(txt_minute),
)
.width(Length::Fill)
.height(Length::Fill)
.center_x(Length::Fill)
.center_y(Length::Fill)
.into()
}
}