summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar 13r0ck <brock@szu.email>2022-12-22 13:53:56 -0700
committerLibravatar 13r0ck <brock@szu.email>2022-12-22 13:53:56 -0700
commit5b556250befc1f9a5a3bb7ff10696496765f4fe7 (patch)
tree50dbd3ea55254b58fa880226d32078a45806bd97
parenta6d0d5773f0561a841a84b538523cbd97e91eccd (diff)
downloadiced-5b556250befc1f9a5a3bb7ff10696496765f4fe7.tar.gz
iced-5b556250befc1f9a5a3bb7ff10696496765f4fe7.tar.bz2
iced-5b556250befc1f9a5a3bb7ff10696496765f4fe7.zip
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.
-rw-r--r--native/src/widget/helpers.rs2
-rw-r--r--native/src/widget/toggler.rs18
2 files changed, 10 insertions, 10 deletions
diff --git a/native/src/widget/helpers.rs b/native/src/widget/helpers.rs
index 8cc1ae82..5b241f83 100644
--- a/native/src/widget/helpers.rs
+++ b/native/src/widget/helpers.rs
@@ -162,7 +162,7 @@ where
Renderer: crate::text::Renderer,
Renderer::Theme: widget::toggler::StyleSheet,
{
- widget::Toggler::new(is_checked, label, f)
+ widget::Toggler::new(label, is_checked, f)
}
/// Creates a new [`TextInput`].
diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs
index 1ae65ba6..3696bf04 100644
--- a/native/src/widget/toggler.rs
+++ b/native/src/widget/toggler.rs
@@ -24,9 +24,9 @@ pub use iced_style::toggler::{Appearance, StyleSheet};
/// TogglerToggled(bool),
/// }
///
-/// let is_active = true;
+/// let is_checked = true;
///
-/// Toggler::new(is_active, String::from("Toggle me!"), |b| Message::TogglerToggled(b));
+/// Toggler::new(String::from("Toggle me!"), is_checked, |b| Message::TogglerToggled(b));
/// ```
#[allow(missing_debug_implementations)]
pub struct Toggler<'a, Message, Renderer>
@@ -34,7 +34,7 @@ where
Renderer: text::Renderer,
Renderer::Theme: StyleSheet,
{
- is_active: bool,
+ is_checked: bool,
on_toggle: Box<dyn Fn(bool) -> Message + 'a>,
label: Option<String>,
width: Length,
@@ -63,15 +63,15 @@ where
/// will receive the new state of the [`Toggler`] and must produce a
/// `Message`.
pub fn new<F>(
- is_active: bool,
label: impl Into<Option<String>>,
+ is_checked: bool,
f: F,
) -> Self
where
F: 'a + Fn(bool) -> Message,
{
Toggler {
- is_active,
+ is_checked,
on_toggle: Box::new(f),
label: label.into(),
width: Length::Fill,
@@ -193,7 +193,7 @@ where
let mouse_over = layout.bounds().contains(cursor_position);
if mouse_over {
- shell.publish((self.on_toggle)(!self.is_active));
+ shell.publish((self.on_toggle)(!self.is_checked));
event::Status::Captured
} else {
@@ -260,9 +260,9 @@ where
let is_mouse_over = bounds.contains(cursor_position);
let style = if is_mouse_over {
- theme.hovered(&self.style, self.is_active)
+ theme.hovered(&self.style, self.is_checked)
} else {
- theme.active(&self.style, self.is_active)
+ theme.active(&self.style, self.is_checked)
};
let border_radius = bounds.height / BORDER_RADIUS_RATIO;
@@ -289,7 +289,7 @@ where
let toggler_foreground_bounds = Rectangle {
x: bounds.x
- + if self.is_active {
+ + if self.is_checked {
bounds.width - 2.0 * space - (bounds.height - (4.0 * space))
} else {
2.0 * space