Slider

Struct Slider 

Source
pub struct Slider<MSG> { /* private fields */ }
Expand description

A slider with value from 0.0 to 1.0

Implementations§

Source§

impl<MSG> Slider<MSG>

Source

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}
Source

pub fn set_value(&mut self, value: f32)

set the value of this slider

Source

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: Debug> Debug for Slider<MSG>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<MSG> Default for Slider<MSG>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<MSG> Widget<MSG> for Slider<MSG>
where MSG: Debug + 'static,

Source§

fn layout(&self) -> Option<&Layout>

return the layout of thiswidget
Source§

fn set_layout(&mut self, layout: Layout)

Source§

fn style(&self) -> Style

return the style of this widget
Source§

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(&self) -> &dyn Any

get an Any reference
Source§

fn as_any_mut(&mut self) -> &mut dyn Any

get an Any mutable reference for casting purposed
Source§

fn set_size(&mut self, width: Option<f32>, _height: Option<f32>)

set the size of the widget
Source§

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 set_id(&mut self, id: &str)

set the id of this widget
Source§

fn get_id(&self) -> &Option<String>

get the id of this widget
Source§

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

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>>]>

get a referemce tp the children of this widget
Source§

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>>>

return a mutable reference to a child at index location
Source§

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_layout
Source§

fn set_focused(&mut self, _focused: bool)

set the widget as focused
Source§

fn as_mut(&mut self) -> Option<&mut Self>
where Self: Sized + 'static,

get a mutable reference of this widget
Source§

fn take_child(&mut self, _index: usize) -> Option<Box<dyn Widget<MSG>>>

take the children at this index location

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.