Skip to main content

SliderBuilder

Struct SliderBuilder 

Source
pub struct SliderBuilder { /* private fields */ }
Expand description

Builder for slider views.

Implementations§

Source§

impl SliderBuilder

Source

pub fn new() -> Self

Source

pub fn min(self, min: f64) -> Self

Examples found in repository?
examples/35_slider.rs (line 42)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn max(self, max: f64) -> Self

Examples found in repository?
examples/35_slider.rs (line 43)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn value(self, value: f64) -> Self

Examples found in repository?
examples/35_slider.rs (line 45)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn step(self, step: f64) -> Self

Examples found in repository?
examples/35_slider.rs (line 44)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn label(self, label: impl Into<String>) -> Self

Examples found in repository?
examples/35_slider.rs (line 46)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn on_change(self, callback: impl Fn(f64) + 'static) -> Self

Examples found in repository?
examples/35_slider.rs (line 48)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn color(self, color: Color) -> Self

Examples found in repository?
examples/35_slider.rs (line 47)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }
Source

pub fn build(self) -> View

Examples found in repository?
examples/35_slider.rs (line 49)
21    fn render(&self, cx: Scope) -> View {
22        let show_help = state!(cx, || false);
23
24        cx.use_command(
25            KeyBinding::key(KeyCode::F(1)),
26            with!(show_help => move || show_help.update(|v| *v = !*v)),
27        );
28
29        let r = state!(cx, || 128.0);
30        let g = state!(cx, || 0.0);
31        let b = state!(cx, || 255.0);
32
33        let rv = r.get() as u8;
34        let gv = g.get() as u8;
35        let bv = b.get() as u8;
36
37        View::vstack()
38            .spacing(1)
39            .child(View::styled_text("RGB Color Mixer").bold().build())
40            .child(
41                View::slider()
42                    .min(0.0)
43                    .max(255.0)
44                    .step(1.0)
45                    .value(r.get())
46                    .label(&format!("Red:   {:>3}", rv))
47                    .color(Color::Rgb { r: 255, g: 80, b: 80 })
48                    .on_change(with!(r => move |v: f64| r.set(v)))
49                    .build(),
50            )
51            .child(
52                View::slider()
53                    .min(0.0)
54                    .max(255.0)
55                    .step(1.0)
56                    .value(g.get())
57                    .label(&format!("Green: {:>3}", gv))
58                    .color(Color::Rgb { r: 80, g: 255, b: 80 })
59                    .on_change(with!(g => move |v: f64| g.set(v)))
60                    .build(),
61            )
62            .child(
63                View::slider()
64                    .min(0.0)
65                    .max(255.0)
66                    .step(1.0)
67                    .value(b.get())
68                    .label(&format!("Blue:  {:>3}", bv))
69                    .color(Color::Rgb { r: 80, g: 80, b: 255 })
70                    .on_change(with!(b => move |v: f64| b.set(v)))
71                    .build(),
72            )
73            .child(
74                View::styled_text("████████████████")
75                    .color(Color::Rgb { r: rv, g: gv, b: bv })
76                    .bold()
77                    .build(),
78            )
79            .child(View::styled_text(format!("#{:02X}{:02X}{:02X}", rv, gv, bv)).bold().build())
80            .child(View::styled_text("Tab: switch slider • Left/Right: adjust • F1: help • Ctrl+Q: quit").dim().build())
81            .child(
82                View::modal()
83                    .visible(show_help.get())
84                    .title("Example 35: Slider")
85                    .on_dismiss(with!(show_help => move || show_help.set(false)))
86                    .child(
87                        View::vstack()
88                            .child(View::styled_text("What you're seeing").bold().build())
89                            .child(View::text("• Three sliders for R, G, B"))
90                            .child(View::text("• Color preview swatch"))
91                            .child(View::text("• Live hex code"))
92                            .child(View::gap(1))
93                            .child(View::styled_text("Key concepts").bold().build())
94                            .child(View::text("• View::slider() with min/max/step"))
95                            .child(View::text("• on_change callback with f64"))
96                            .child(View::text("• Color::Rgb for true color"))
97                            .child(View::gap(1))
98                            .child(View::styled_text("Try this").bold().build())
99                            .child(View::text("• Tab between sliders"))
100                            .child(View::text("• Left/Right arrows to adjust"))
101                            .child(View::text("• Watch the preview change"))
102                            .child(View::gap(1))
103                            .child(View::styled_text("Next up").bold().build())
104                            .child(View::text("-> 36_reducer: state machine wizard"))
105                            .child(View::gap(1))
106                            .child(View::styled_text("Press Escape to close").dim().build())
107                            .build(),
108                    )
109                    .build(),
110            )
111            .build()
112    }

Trait Implementations§

Source§

impl Default for SliderBuilder

Source§

fn default() -> SliderBuilder

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

Auto Trait Implementations§

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
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, 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.