Unify circular corner geometry and shader masks
This commit is contained in:
1 parent
0162870cca
commit
f110ec80e1
19 files changed
+277
-135
No files matched your search
@@ -604,6 +604,9 @@ pub fn resolve_with_context(
|
||||
*path = theme_path(directory, path);
|
||||
}
|
||||
validate(&tokens)?;
|
||||
// Effects regions encode integer logical radii; publish the same value
|
||||
// to the shell and compositor, without rewriting the authored config.
|
||||
tokens.geometry.shell_radius = tokens.geometry.shell_radius.round();
|
||||
let requested_accent = tokens.colors.accent.clone();
|
||||
transform(&mut tokens, &policy.accessibility, &mut warnings);
|
||||
let theme = ResolvedTheme {
|
||||
@@ -1297,6 +1300,22 @@ pub fn import_family(id: &str, source: &str) -> Result<ImportedFamily, String> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn resolved_shell_radius_matches_integer_effect_regions() {
|
||||
for (requested, expected) in [(0.0, 0.0), (0.4, 0.0), (13.4, 13.0), (13.5, 14.0)] {
|
||||
let document = crate::Document::parse(&format!(
|
||||
"theme {{ geometry {{ shell-radius {requested}; window-radius 7.25; }} }}"
|
||||
))
|
||||
.unwrap();
|
||||
let result = super::resolve(&document, std::path::Path::new("/tmp"), jiff::Timestamp::now(), |_| {
|
||||
Err("unexpected theme file".into())
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(result.theme.tokens.geometry.shell_radius, expected);
|
||||
assert_eq!(result.theme.tokens.geometry.window_radius, 7.25);
|
||||
}
|
||||
}
|
||||
|
||||
use super::*;
|
||||
|
||||
fn candidate(source: &str) -> Result<Candidate, String> {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
/// Radius of a concentric inset, in the same units as the outer radius.
|
||||
pub fn inner_radius(outer: f32, padding: f32) -> f32 {
|
||||
(outer - padding).max(0.0)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn inset_corners_preserve_the_center_and_saturate() {
|
||||
assert_eq!(inner_radius(14.0, 4.0), 10.0);
|
||||
assert_eq!(inner_radius(7.5, 2.25), 5.25);
|
||||
assert_eq!(inner_radius(14.0, 0.0), 14.0);
|
||||
assert_eq!(inner_radius(14.0, 14.0), 0.0);
|
||||
assert_eq!(inner_radius(14.0, 20.0), 0.0);
|
||||
assert_eq!(inner_radius(0.0, 4.0), 0.0);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ pub mod calendar;
|
||||
mod contrast;
|
||||
pub mod controls;
|
||||
pub mod gallery;
|
||||
mod geometry;
|
||||
pub mod icons;
|
||||
pub mod material;
|
||||
pub mod menus;
|
||||
@@ -14,6 +15,7 @@ mod typography;
|
||||
|
||||
pub use button::accent_button;
|
||||
pub use contrast::{accent_color, accent_pair, apply, composite, contrast, foreground, luminance};
|
||||
pub use geometry::inner_radius;
|
||||
pub use palette::{Palette, mix, parse_color, surface_shade};
|
||||
pub use presets::{PRESETS, Preset};
|
||||
pub use typography::{font, text};
|
||||
@@ -78,20 +78,25 @@ pub fn separator<'a, M: 'a>(foreground: Color, opacity: f32) -> Element<'a, M> {
|
||||
|
||||
pub fn switch<'a, M: 'a>(enabled: bool, palette: crate::Palette, opacity: f32) -> Element<'a, M> {
|
||||
let (track, thumb) = crate::controls::switch_colors(palette, enabled, false);
|
||||
let track_radius = 10.;
|
||||
let padding = 2.;
|
||||
let knob = container(cosmic::widget::Space::new().width(16).height(16))
|
||||
.width(16)
|
||||
.height(16)
|
||||
.class(crate::controls::surface(Color { a: opacity, ..thumb }, 8.));
|
||||
.class(crate::controls::surface(
|
||||
Color { a: opacity, ..thumb },
|
||||
crate::inner_radius(track_radius, padding),
|
||||
));
|
||||
container(knob)
|
||||
.width(36)
|
||||
.height(20)
|
||||
.padding(2)
|
||||
.padding(padding)
|
||||
.align_x(if enabled {
|
||||
cosmic::iced::alignment::Horizontal::Right
|
||||
} else {
|
||||
cosmic::iced::alignment::Horizontal::Left
|
||||
})
|
||||
.class(crate::controls::surface(track.scale_alpha(opacity), 10.))
|
||||
.class(crate::controls::surface(track.scale_alpha(opacity), track_radius))
|
||||
.into()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user