@@ -7,21 +7,21 @@ use dodrio::bumpalo;
7
7
use std:: rc:: Rc ;
8
8
9
9
/// A toggler that can be toggled.
10
- ///
10
+ ///
11
11
/// # Example
12
- ///
12
+ ///
13
13
/// ```
14
14
/// # use iced_web::Toggler;
15
- ///
15
+ ///
16
16
/// pub enum Message {
17
17
/// TogglerToggled(bool),
18
18
/// }
19
- ///
19
+ ///
20
20
/// let is_active = true;
21
- ///
21
+ ///
22
22
/// Toggler::new(is_active, String::from("Toggle me!"), Message::TogglerToggled);
23
23
/// ```
24
- ///
24
+ ///
25
25
#[ allow( missing_debug_implementations) ]
26
26
pub struct Toggler < Message > {
27
27
is_active : bool ,
@@ -34,16 +34,20 @@ pub struct Toggler<Message> {
34
34
35
35
impl < Message > Toggler < Message > {
36
36
/// Creates a new [`Toggler`].
37
- ///
37
+ ///
38
38
/// It expects:
39
39
/// * a boolean describing whether the [`Toggler`] is active or not
40
40
/// * An optional label for the [`Toggler`]
41
41
/// * a function that will be called when the [`Toggler`] is toggled. It
42
42
/// will receive the new state of the [`Toggler`] and must produce a
43
43
/// `Message`.
44
- ///
44
+ ///
45
45
/// [`Toggler`]: struct.Toggler.html
46
- pub fn new < F > ( is_active : bool , label : impl Into < Option < String > > , f : F ) -> Self
46
+ pub fn new < F > (
47
+ is_active : bool ,
48
+ label : impl Into < Option < String > > ,
49
+ f : F ,
50
+ ) -> Self
47
51
where
48
52
F : ' static + Fn ( bool ) -> Message ,
49
53
{
@@ -58,23 +62,23 @@ impl<Message> Toggler<Message> {
58
62
}
59
63
60
64
/// Sets the width of the [`Toggler`].
61
- ///
65
+ ///
62
66
/// [`Toggler`]: struct.Toggler.html
63
67
pub fn width ( mut self , width : Length ) -> Self {
64
68
self . width = width;
65
69
self
66
70
}
67
71
68
72
/// Sets the style of the [`Toggler`].
69
- ///
73
+ ///
70
74
/// [`Toggler`]: struct.Toggler.html
71
75
pub fn style ( mut self , style : impl Into < Box < dyn StyleSheet > > ) -> Self {
72
76
self . style = style. into ( ) ;
73
77
self
74
78
}
75
79
76
80
/// Sets the id of the [`Toggler`].
77
- ///
81
+ ///
78
82
/// [`Toggler`]: struct.Toggler.html
79
83
pub fn id ( mut self , id : impl Into < String > ) -> Self {
80
84
self . id = Some ( id. into ( ) ) ;
95
99
use dodrio:: builder:: * ;
96
100
use dodrio:: bumpalo:: collections:: String ;
97
101
98
- let toggler_label = & self . label . as_ref ( ) . map ( |label| {
99
- String :: from_str_in ( & label, bump) . into_bump_str ( )
100
- } ) ;
102
+ let toggler_label = & self
103
+ . label
104
+ . as_ref ( )
105
+ . map ( |label| String :: from_str_in ( & label, bump) . into_bump_str ( ) ) ;
101
106
102
107
let event_bus = bus. clone ( ) ;
103
108
let on_toggle = self . on_toggle . clone ( ) ;
@@ -125,9 +130,7 @@ where
125
130
} )
126
131
. finish ( ) ;
127
132
128
- let toggler = span ( bump)
129
- . children ( vec ! [ span( bump) . finish( ) ] )
130
- . finish ( ) ;
133
+ let toggler = span ( bump) . children ( vec ! [ span( bump) . finish( ) ] ) . finish ( ) ;
131
134
132
135
label
133
136
. attr (
@@ -140,7 +143,7 @@ where
140
143
bumpalo:: format!( in bump, "width: {}; align-items: center" , css:: length( self . width) )
141
144
. into_bump_str ( )
142
145
)
143
- . children (
146
+ . children (
144
147
if let Some ( label) = toggler_label {
145
148
vec ! [
146
149
text( label) ,
@@ -165,4 +168,4 @@ where
165
168
fn from ( toggler : Toggler < Message > ) -> Element < ' a , Message > {
166
169
Element :: new ( toggler)
167
170
}
168
- }
171
+ }
0 commit comments