Skip to content

Commit 5b55625

Browse files
committed
Use same name & order for toggler::new and helper
The helper function for the toggler widget switched the order and name of the arguments passed when creating the toggler widget. This just standardizes the order whether the dev is using the helper or the associated function.
1 parent a6d0d57 commit 5b55625

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

native/src/widget/helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ where
162162
Renderer: crate::text::Renderer,
163163
Renderer::Theme: widget::toggler::StyleSheet,
164164
{
165-
widget::Toggler::new(is_checked, label, f)
165+
widget::Toggler::new(label, is_checked, f)
166166
}
167167

168168
/// Creates a new [`TextInput`].

native/src/widget/toggler.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ pub use iced_style::toggler::{Appearance, StyleSheet};
2424
/// TogglerToggled(bool),
2525
/// }
2626
///
27-
/// let is_active = true;
27+
/// let is_checked = true;
2828
///
29-
/// Toggler::new(is_active, String::from("Toggle me!"), |b| Message::TogglerToggled(b));
29+
/// Toggler::new(String::from("Toggle me!"), is_checked, |b| Message::TogglerToggled(b));
3030
/// ```
3131
#[allow(missing_debug_implementations)]
3232
pub struct Toggler<'a, Message, Renderer>
3333
where
3434
Renderer: text::Renderer,
3535
Renderer::Theme: StyleSheet,
3636
{
37-
is_active: bool,
37+
is_checked: bool,
3838
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
3939
label: Option<String>,
4040
width: Length,
@@ -63,15 +63,15 @@ where
6363
/// will receive the new state of the [`Toggler`] and must produce a
6464
/// `Message`.
6565
pub fn new<F>(
66-
is_active: bool,
6766
label: impl Into<Option<String>>,
67+
is_checked: bool,
6868
f: F,
6969
) -> Self
7070
where
7171
F: 'a + Fn(bool) -> Message,
7272
{
7373
Toggler {
74-
is_active,
74+
is_checked,
7575
on_toggle: Box::new(f),
7676
label: label.into(),
7777
width: Length::Fill,
@@ -193,7 +193,7 @@ where
193193
let mouse_over = layout.bounds().contains(cursor_position);
194194

195195
if mouse_over {
196-
shell.publish((self.on_toggle)(!self.is_active));
196+
shell.publish((self.on_toggle)(!self.is_checked));
197197

198198
event::Status::Captured
199199
} else {
@@ -260,9 +260,9 @@ where
260260
let is_mouse_over = bounds.contains(cursor_position);
261261

262262
let style = if is_mouse_over {
263-
theme.hovered(&self.style, self.is_active)
263+
theme.hovered(&self.style, self.is_checked)
264264
} else {
265-
theme.active(&self.style, self.is_active)
265+
theme.active(&self.style, self.is_checked)
266266
};
267267

268268
let border_radius = bounds.height / BORDER_RADIUS_RATIO;
@@ -289,7 +289,7 @@ where
289289

290290
let toggler_foreground_bounds = Rectangle {
291291
x: bounds.x
292-
+ if self.is_active {
292+
+ if self.is_checked {
293293
bounds.width - 2.0 * space - (bounds.height - (4.0 * space))
294294
} else {
295295
2.0 * space

0 commit comments

Comments
 (0)