Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use same name & order for toggler::new and helper #1616

Merged
merged 1 commit into from
Jan 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion native/src/widget/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
18 changes: 9 additions & 9 deletions native/src/widget/toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ 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>
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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down