pub struct Slider<MSG> { /* private fields */ }Expand description
A slider with value from 0.0 to 1.0
Implementations§
Source§impl<MSG> Slider<MSG>
impl<MSG> Slider<MSG>
Sourcepub fn new(value: f32) -> Self
pub fn new(value: f32) -> Self
create a new slider with value
Examples found in repository?
examples/demo.rs (line 23)
17fn build_ui() -> Box<dyn Widget<()>> {
18 println!("building the ui");
19 let mut root_node = FlexBox::new();
20 root_node.set_scroll_top(0.0);
21 root_node.vertical();
22
23 let mut slider = Slider::new(0.5);
24 slider.use_thick_track(true);
25 let mut tab1 = TabBox::new();
26 tab1.set_tab_labels(vec![
27 "Tab1".into(),
28 "Tab2".into(),
29 "Tab3".into(),
30 "Tab4".into(),
31 "Tab5".into(),
32 "And more tabs..".into(),
33 ]);
34 tab1.set_active_tab(1);
35 //tab1.set_size(None, Some(30.0));
36
37 let mut gb1 = GroupBox::new();
38 gb1.set_label("Selection");
39
40 let cb1 = Checkbox::new("Checkbox1");
41 let cb2 = Checkbox::new("Checkbox2");
42 let rb1 = Radio::new("Radio1");
43 let rb2 = Radio::new("Radio2");
44 let mut link1 = Link::new("https://github.com", "Github");
45 link1.set_border(true);
46
47 let mut list_box1 = ListBox::new();
48 list_box1.set_list(vec![
49 "Item1".into(),
50 "Item2".into(),
51 "Item3".into(),
52 "Item4".into(),
53 "Item5".into(),
54 "Item6".into(),
55 ]);
56
57 tab1.add_child_to_tab(0, Box::new(list_box1));
58
59 gb1.add_child(Box::new(cb1));
60 gb1.add_child(Box::new(cb2));
61 gb1.add_child(Box::new(rb1));
62 gb1.add_child(Box::new(rb2));
63 gb1.add_child(Box::new(link1));
64
65 let input1 = TextInput::new("Hello world!");
66
67 let input2 =
68 TextInput::new("The quick brown fox jumps over the lazy dog...");
69
70 let mut text_area1: TextArea<()> = TextArea::new(
71 "This is a text area\
72 \n1. With a line that is a bit long.. but not very long....\
73 \n2. and another line\
74 \n3. With a veryyyyyyy looooooooooooooooooooooooooooooooooooonnnnnnnnnnngggggggg line\
75 \n4. and another line...............\
76 \n5. With a line\
77 \n6. With a line and not too long\
78 \n7. and another line\
79 \n8. With a line\
80 \n9. and another line\
81 \n10. and another line with another pharse\
82 \n11. With a line\
83 \n12. and another line\
84 \n13. With a line\
85 \n14. and another line not so loooooooooooooooooooooooooong\
86 \n15. With a line\
87 \n16. With a line\
88 \n17. and another line\
89 \n18. With a line\
90 \n19. and another line\
91 \n20. This is the last line and also a looooooooooooooooooooong line",
92 );
93 //text_area1.set_size(Some(60.0), Some(10.0));
94
95 let mut btn2: Button<()> = Button::new("Button2");
96 btn2.set_rounded(true);
97 btn2.set_id("btn2");
98 let mut img: Image<()> =
99 Image::new(include_bytes!("../horse.jpg").to_vec());
100
101 let mut btn1: Button<()> = Button::new("Button 1");
102 btn1.set_id("btn1");
103
104 btn1.add_click_listener(Callback::from(|_| {
105 eprintln!("btn1 is clicked");
106 }));
107
108 root_node.add_child(Box::new(btn1));
109 root_node.add_child(Box::new(slider));
110 root_node.add_child(Box::new(btn2));
111 tab1.add_child(Box::new(gb1));
112 let mut row = FlexBox::new();
113 row.horizontal();
114 row.set_expand_width(true);
115 row.set_expand_height(false);
116 row.add_child(Box::new(img));
117 root_node.add_child(Box::new(row));
118 root_node.add_child(Box::new(tab1));
119 //root_node.add_child(Box::new(gb1));
120 root_node.add_child(Box::new(input1));
121 root_node.add_child(Box::new(input2));
122 root_node.add_child(Box::new(text_area1));
123 Box::new(root_node)
124}Sourcepub fn use_thick_track(&mut self, use_thick: bool)
pub fn use_thick_track(&mut self, use_thick: bool)
set the use thick track, default is false
Examples found in repository?
examples/demo.rs (line 24)
17fn build_ui() -> Box<dyn Widget<()>> {
18 println!("building the ui");
19 let mut root_node = FlexBox::new();
20 root_node.set_scroll_top(0.0);
21 root_node.vertical();
22
23 let mut slider = Slider::new(0.5);
24 slider.use_thick_track(true);
25 let mut tab1 = TabBox::new();
26 tab1.set_tab_labels(vec![
27 "Tab1".into(),
28 "Tab2".into(),
29 "Tab3".into(),
30 "Tab4".into(),
31 "Tab5".into(),
32 "And more tabs..".into(),
33 ]);
34 tab1.set_active_tab(1);
35 //tab1.set_size(None, Some(30.0));
36
37 let mut gb1 = GroupBox::new();
38 gb1.set_label("Selection");
39
40 let cb1 = Checkbox::new("Checkbox1");
41 let cb2 = Checkbox::new("Checkbox2");
42 let rb1 = Radio::new("Radio1");
43 let rb2 = Radio::new("Radio2");
44 let mut link1 = Link::new("https://github.com", "Github");
45 link1.set_border(true);
46
47 let mut list_box1 = ListBox::new();
48 list_box1.set_list(vec![
49 "Item1".into(),
50 "Item2".into(),
51 "Item3".into(),
52 "Item4".into(),
53 "Item5".into(),
54 "Item6".into(),
55 ]);
56
57 tab1.add_child_to_tab(0, Box::new(list_box1));
58
59 gb1.add_child(Box::new(cb1));
60 gb1.add_child(Box::new(cb2));
61 gb1.add_child(Box::new(rb1));
62 gb1.add_child(Box::new(rb2));
63 gb1.add_child(Box::new(link1));
64
65 let input1 = TextInput::new("Hello world!");
66
67 let input2 =
68 TextInput::new("The quick brown fox jumps over the lazy dog...");
69
70 let mut text_area1: TextArea<()> = TextArea::new(
71 "This is a text area\
72 \n1. With a line that is a bit long.. but not very long....\
73 \n2. and another line\
74 \n3. With a veryyyyyyy looooooooooooooooooooooooooooooooooooonnnnnnnnnnngggggggg line\
75 \n4. and another line...............\
76 \n5. With a line\
77 \n6. With a line and not too long\
78 \n7. and another line\
79 \n8. With a line\
80 \n9. and another line\
81 \n10. and another line with another pharse\
82 \n11. With a line\
83 \n12. and another line\
84 \n13. With a line\
85 \n14. and another line not so loooooooooooooooooooooooooong\
86 \n15. With a line\
87 \n16. With a line\
88 \n17. and another line\
89 \n18. With a line\
90 \n19. and another line\
91 \n20. This is the last line and also a looooooooooooooooooooong line",
92 );
93 //text_area1.set_size(Some(60.0), Some(10.0));
94
95 let mut btn2: Button<()> = Button::new("Button2");
96 btn2.set_rounded(true);
97 btn2.set_id("btn2");
98 let mut img: Image<()> =
99 Image::new(include_bytes!("../horse.jpg").to_vec());
100
101 let mut btn1: Button<()> = Button::new("Button 1");
102 btn1.set_id("btn1");
103
104 btn1.add_click_listener(Callback::from(|_| {
105 eprintln!("btn1 is clicked");
106 }));
107
108 root_node.add_child(Box::new(btn1));
109 root_node.add_child(Box::new(slider));
110 root_node.add_child(Box::new(btn2));
111 tab1.add_child(Box::new(gb1));
112 let mut row = FlexBox::new();
113 row.horizontal();
114 row.set_expand_width(true);
115 row.set_expand_height(false);
116 row.add_child(Box::new(img));
117 root_node.add_child(Box::new(row));
118 root_node.add_child(Box::new(tab1));
119 //root_node.add_child(Box::new(gb1));
120 root_node.add_child(Box::new(input1));
121 root_node.add_child(Box::new(input2));
122 root_node.add_child(Box::new(text_area1));
123 Box::new(root_node)
124}Trait Implementations§
Source§impl<MSG> Widget<MSG> for Slider<MSG>where
MSG: Debug + 'static,
impl<MSG> Widget<MSG> for Slider<MSG>where
MSG: Debug + 'static,
fn set_layout(&mut self, layout: Layout)
Source§fn draw(&self, buf: &mut Buffer) -> Vec<Cmd>
fn draw(&self, buf: &mut Buffer) -> Vec<Cmd>
this is called in the render loop in the renderer where the widget
writes into the buffer. The result will then be written into the
stdout terminal.
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
get an Any mutable reference for casting purposed
Source§fn process_event(&mut self, event: Event) -> Vec<MSG>
fn process_event(&mut self, event: Event) -> Vec<MSG>
this process the event and all callbacks attached to the widgets will be dispatched.
Source§fn get_offset(&self) -> (f32, f32)
fn get_offset(&self) -> (f32, f32)
return the offset of the parent,
this before any of it’s children to be drawn
Source§fn add_child(&mut self, _child: Box<dyn Widget<MSG>>) -> bool
fn add_child(&mut self, _child: Box<dyn Widget<MSG>>) -> bool
add a child to this widget
returns true if it can accept a child, false otherwise
Source§fn children(&self) -> Option<&[Box<dyn Widget<MSG>>]>
fn children(&self) -> Option<&[Box<dyn Widget<MSG>>]>
get a referemce tp the children of this widget
Source§fn children_mut(&mut self) -> Option<&mut [Box<dyn Widget<MSG>>]>
fn children_mut(&mut self) -> Option<&mut [Box<dyn Widget<MSG>>]>
get a mutable reference to the children of this widget
Source§fn child_mut(&mut self, _index: usize) -> Option<&mut Box<dyn Widget<MSG>>>
fn child_mut(&mut self, _index: usize) -> Option<&mut Box<dyn Widget<MSG>>>
return a mutable reference to a child at index location
Source§fn style_node(&self, stretch: &mut Stretch) -> Option<Node>
fn style_node(&self, stretch: &mut Stretch) -> Option<Node>
build a node with styles from this widget and its children
The Layout tree is then calculated see
layout::compute_layoutSource§fn set_focused(&mut self, _focused: bool)
fn set_focused(&mut self, _focused: bool)
set the widget as focused
Auto Trait Implementations§
impl<MSG> Freeze for Slider<MSG>
impl<MSG> !RefUnwindSafe for Slider<MSG>
impl<MSG> !Send for Slider<MSG>
impl<MSG> !Sync for Slider<MSG>
impl<MSG> Unpin for Slider<MSG>
impl<MSG> !UnwindSafe for Slider<MSG>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more