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

chore: toggle fixes #23

Merged
merged 1 commit into from
Apr 15, 2024
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
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 @@
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 @@ -265,11 +265,11 @@
viewport: &Rectangle,
) {
/// Makes sure that the border radius of the toggler looks good at every size.
const BORDER_RADIUS_RATIO: f32 = 32.0 / 13.0;

Check warning on line 268 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

constant `BORDER_RADIUS_RATIO` is never used

Check warning on line 268 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

constant `BORDER_RADIUS_RATIO` is never used

/// The space ratio between the background Quad and the Toggler bounds, and
/// between the background Quad and foreground Quad.
const SPACE_RATIO: f32 = 0.05;

Check warning on line 272 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

constant `SPACE_RATIO` is never used

Check warning on line 272 in src/widget/cosmic_toggler.rs

View workflow job for this annotation

GitHub Actions / wayland

constant `SPACE_RATIO` is never used

let mut children = layout.children();

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

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
Loading