Skip to content

Commit

Permalink
chore: toggle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Apr 15, 2024
1 parent dd3c1d7 commit 714acf7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
29 changes: 21 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,38 @@ categories = ["gui"]

[features]
default = ["iced"]
iced = ["dep:iced", "dep:iced_runtime", "dep:iced_widget", "dep:iced_futures", "dep:iced_core", "dep:iced_style"]
iced = [
"dep:iced",
"dep:iced_runtime",
"dep:iced_widget",
"dep:iced_futures",
"dep:iced_core",
"dep:iced_style",
]
once_cell = ["dep:once_cell"]
wayland-libcosmic = ["libcosmic", "libcosmic/wayland"]
winit-libcosmic = ["libcosmic", "libcosmic/winit"]
wayland-libcosmic = ["libcosmic", "libcosmic/wayland"]
winit-libcosmic = ["libcosmic", "libcosmic/winit"]
libcosmic = ["dep:libcosmic"]

[workspace]
members = [
"examples/*"
]
members = ["examples/*"]

[dependencies]
iced = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", features = ["tokio"], optional = true }
iced = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", features = [
"tokio",
], optional = true }
iced_runtime = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", optional = true }
iced_widget = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", optional = true }
iced_futures = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", optional = true }
iced_core = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", optional = true }
iced_style = { git = "https://github.com/iced-rs/iced", rev = "5540ac0", optional = true }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [ "tokio" ], optional = true }
libcosmic = { git = "https://github.com/pop-os/libcosmic/", default-features = false, features = [
"tokio",
], optional = true }
once_cell = { version = "1.18.0", optional = true }
float-cmp = "0.9"

# [patch.'https://github.com/pop-os/libcosmic']
# libcosmic = { path = "../libcosmic" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }
# cosmic-theme = { path = "../libcosmic/cosmic-theme" }
38 changes: 18 additions & 20 deletions src/widget/cosmic_toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ where
layout::Node::new(iced_core::Size::ZERO)
}
},
|_| layout::Node::new(iced_core::Size::new(2.0 * self.size, self.size)),
|_| layout::Node::new(Size::new(48., 24.)),
)
}

Expand Down Expand Up @@ -305,50 +305,48 @@ where
)
};

let border_radius = bounds.height / BORDER_RADIUS_RATIO;
let space = SPACE_RATIO * bounds.height;
let space = style.handle_margin;

let toggler_background_bounds = Rectangle {
x: bounds.x + space,
y: bounds.y + space,
width: bounds.width - (2.0 * space),
height: bounds.height - (2.0 * space),
x: bounds.x,
y: bounds.y,
width: bounds.width,
height: bounds.height,
};

renderer.fill_quad(
renderer::Quad {
bounds: toggler_background_bounds,
border: Border {
width: 1.0,
color: style.background_border.unwrap_or(style.background),
radius: border_radius.into(),
radius: style.border_radius,
..Default::default()
},
shadow: Default::default(),
..renderer::Quad::default()
},
style.background,
);

let toggler_foreground_bounds = Rectangle {
x: bounds.x
+ lerp(
2.0 * space,
bounds.width - 2.0 * space - (bounds.height - (4.0 * space)),
space,
bounds.width - space - (bounds.height - (2.0 * space)),
self.percent,
),
y: bounds.y + (2.0 * space),
width: bounds.height - (4.0 * space),
height: bounds.height - (4.0 * space),

y: bounds.y + space,
width: bounds.height - (2.0 * space),
height: bounds.height - (2.0 * space),
};

renderer.fill_quad(
renderer::Quad {
bounds: toggler_foreground_bounds,
border: Border {
width: 1.0,
color: style.foreground_border.unwrap_or(style.foreground),
radius: border_radius.into(),
radius: style.handle_radius,
..Default::default()
},
shadow: Default::default(),
..renderer::Quad::default()
},
style.foreground,
);
Expand Down

0 comments on commit 714acf7

Please sign in to comment.