feat: add custom border radius property for windows
This commit is contained in:
parent
3e78eb2381
commit
d3aa7197d1
4 changed files with 22 additions and 6 deletions
|
|
@ -15,6 +15,13 @@ pub struct CornerRadii {
|
||||||
pub radius_l: [f32; 4],
|
pub radius_l: [f32; 4],
|
||||||
/// extra large corner radii
|
/// extra large corner radii
|
||||||
pub radius_xl: [f32; 4],
|
pub radius_xl: [f32; 4],
|
||||||
|
/// window corner radii (used by compositor for window decorations)
|
||||||
|
#[serde(default = "default_radius_window")]
|
||||||
|
pub radius_window: [f32; 4],
|
||||||
|
}
|
||||||
|
|
||||||
|
fn default_radius_window() -> [f32; 4] {
|
||||||
|
[22.0; 4]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CornerRadii {
|
impl Default for CornerRadii {
|
||||||
|
|
@ -26,6 +33,7 @@ impl Default for CornerRadii {
|
||||||
radius_m: [16.0; 4],
|
radius_m: [16.0; 4],
|
||||||
radius_l: [32.0; 4],
|
radius_l: [32.0; 4],
|
||||||
radius_xl: [160.0; 4],
|
radius_xl: [160.0; 4],
|
||||||
|
radius_window: [22.0; 4],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -653,6 +653,14 @@ impl Theme {
|
||||||
self.corner_radii.radius_s
|
self.corner_radii.radius_s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use]
|
||||||
|
#[allow(clippy::doc_markdown)]
|
||||||
|
#[inline]
|
||||||
|
/// get @radius_window (window corner radius for compositor)
|
||||||
|
pub fn radius_window(&self) -> [f32; 4] {
|
||||||
|
self.corner_radii.radius_window
|
||||||
|
}
|
||||||
|
|
||||||
#[must_use]
|
#[must_use]
|
||||||
#[allow(clippy::doc_markdown)]
|
#[allow(clippy::doc_markdown)]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
||||||
|
|
@ -657,7 +657,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
|
|
||||||
let theme = THEME.lock().unwrap();
|
let theme = THEME.lock().unwrap();
|
||||||
let t = theme.cosmic();
|
let t = theme.cosmic();
|
||||||
let radii = t.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
|
let radii = t.radius_window();
|
||||||
let cur_rad = CornerRadius {
|
let cur_rad = CornerRadius {
|
||||||
top_left: radii[0].round() as u32,
|
top_left: radii[0].round() as u32,
|
||||||
top_right: radii[1].round() as u32,
|
top_right: radii[1].round() as u32,
|
||||||
|
|
@ -797,7 +797,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
|
|
||||||
let t = cosmic_theme.cosmic();
|
let t = cosmic_theme.cosmic();
|
||||||
|
|
||||||
let radii = t.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
|
let radii = t.radius_window();
|
||||||
let cur_rad = CornerRadius {
|
let cur_rad = CornerRadius {
|
||||||
top_left: radii[0].round() as u32,
|
top_left: radii[0].round() as u32,
|
||||||
top_right: radii[1].round() as u32,
|
top_right: radii[1].round() as u32,
|
||||||
|
|
@ -943,7 +943,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
|
|
||||||
let t = cosmic_theme.cosmic();
|
let t = cosmic_theme.cosmic();
|
||||||
|
|
||||||
let radii = t.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
|
let radii = t.radius_window();
|
||||||
let cur_rad = CornerRadius {
|
let cur_rad = CornerRadius {
|
||||||
top_left: radii[0].round() as u32,
|
top_left: radii[0].round() as u32,
|
||||||
top_right: radii[1].round() as u32,
|
top_right: radii[1].round() as u32,
|
||||||
|
|
@ -1219,7 +1219,7 @@ impl<T: Application> Cosmic<T> {
|
||||||
|
|
||||||
let theme = THEME.lock().unwrap();
|
let theme = THEME.lock().unwrap();
|
||||||
let t = theme.cosmic();
|
let t = theme.cosmic();
|
||||||
let radii = t.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
|
let radii = t.radius_window();
|
||||||
let cur_rad = CornerRadius {
|
let cur_rad = CornerRadius {
|
||||||
top_left: radii[0].round() as u32,
|
top_left: radii[0].round() as u32,
|
||||||
top_right: radii[1].round() as u32,
|
top_right: radii[1].round() as u32,
|
||||||
|
|
|
||||||
|
|
@ -470,8 +470,8 @@ impl iced_container::Catalog for Theme {
|
||||||
fn style(&self, class: &Self::Class<'_>) -> iced_container::Style {
|
fn style(&self, class: &Self::Class<'_>) -> iced_container::Style {
|
||||||
let cosmic = self.cosmic();
|
let cosmic = self.cosmic();
|
||||||
|
|
||||||
// Ensures visually aligned radii for content and window corners
|
// Use dedicated window radius from theme
|
||||||
let window_corner_radius = cosmic.radius_s().map(|x| if x < 4.0 { x } else { x + 4.0 });
|
let window_corner_radius = cosmic.radius_window();
|
||||||
|
|
||||||
match class {
|
match class {
|
||||||
Container::Transparent => iced_container::Style::default(),
|
Container::Transparent => iced_container::Style::default(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue