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

Fix window border corner appearance #732

Merged
merged 2 commits into from
Nov 26, 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
35 changes: 32 additions & 3 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,30 @@ impl<App: Application> ApplicationExt for App {
header = header.end(element.map(Message::App));
}

header.apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_header")))
header
// Needed for apps without a content container, but with a header bar
.apply(container)
.style(move |theme| container::Style {
background: if content_container {
None
} else {
Some(iced::Background::Color(
theme.cosmic().background.base.into(),
))
},
border: iced::Border {
radius: [
theme.cosmic().radius_s()[0] - 1.0,
theme.cosmic().radius_s()[1] - 1.0,
theme.cosmic().radius_0()[2],
theme.cosmic().radius_0()[3],
]
.into(),
..Default::default()
},
..Default::default()
})
.apply(|w| id_container(w, iced_core::id::Id::new("COSMIC_header")))
})
} else {
None
Expand All @@ -892,11 +915,17 @@ impl<App: Application> ApplicationExt for App {
.apply(container)
.padding(if sharp_corners { 0 } else { 1 })
.style(move |theme| container::Style {
background: if content_container {
Some(iced::Background::Color(
theme.cosmic().background.base.into(),
))
} else {
None
},
border: iced::Border {
color: theme.cosmic().bg_divider().into(),
width: if sharp_corners { 0.0 } else { 1.0 },
// x + 2.0 is used to prevent corner artifacts
radius: theme.cosmic().radius_s().map(|x| x + 2.0).into(),
radius: theme.cosmic().radius_s().into(),
},
..Default::default()
});
Expand Down
26 changes: 4 additions & 22 deletions src/theme/style/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,8 @@ impl iced_container::Catalog for Theme {
Container::WindowBackground => iced_container::Style {
icon_color: Some(Color::from(cosmic.background.on)),
text_color: Some(Color::from(cosmic.background.on)),
background: Some(iced::Background::Color(cosmic.background.base.into())),
border: Border {
radius: [
cosmic.corner_radii.radius_0[0],
cosmic.corner_radii.radius_0[1],
cosmic.corner_radii.radius_s[2],
cosmic.corner_radii.radius_s[3],
]
.into(),
..Default::default()
},
background: None,
border: Border::default(),
shadow: Shadow::default(),
},

Expand Down Expand Up @@ -513,17 +504,8 @@ impl iced_container::Catalog for Theme {
iced_container::Style {
icon_color: Some(icon_color),
text_color: Some(text_color),
background: Some(iced::Background::Color(cosmic.background.base.into())),
border: Border {
radius: [
cosmic.corner_radii.radius_s[0],
cosmic.corner_radii.radius_s[1],
cosmic.corner_radii.radius_0[2],
cosmic.corner_radii.radius_0[3],
]
.into(),
..Default::default()
},
background: None,
border: Border::default(),
shadow: Shadow::default(),
}
}
Expand Down
15 changes: 12 additions & 3 deletions src/widget/header_bar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2022 System76 <[email protected]>
// SPDX-License-Identifier: MPL-2.0

use crate::cosmic_theme::Density;
use crate::{ext::CollectionWidget, widget, Element};
use crate::cosmic_theme::{Density, Spacing};
use crate::{theme, widget, Element};
use apply::Apply;
use derive_setters::Setters;
use iced::Length;
Expand Down Expand Up @@ -287,6 +287,12 @@ impl<'a, Message: Clone + 'static> Widget<Message, crate::Theme, crate::Renderer
impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
/// Converts the headerbar builder into an Iced element.
pub fn view(mut self) -> Element<'a, Message> {
let Spacing {
space_xxxs,
space_xxs,
..
} = theme::active().cosmic().spacing;

// Take ownership of the regions to be packed.
let start = std::mem::take(&mut self.start);
let center = std::mem::take(&mut self.center);
Expand All @@ -307,6 +313,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
// If elements exist in the start region, append them here.
.push(
widget::row::with_children(start)
.spacing(space_xxxs)
.align_y(iced::Alignment::Center)
.apply(widget::container)
.align_x(iced::Alignment::Start)
Expand All @@ -316,6 +323,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
// This will otherwise use the title as a widget if a title was defined.
.push(if !center.is_empty() {
widget::row::with_children(center)
.spacing(space_xxxs)
.align_y(iced::Alignment::Center)
.apply(widget::container)
.center_x(Length::Fill)
Expand All @@ -327,6 +335,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
})
.push(
widget::row::with_children(end)
.spacing(space_xxs)
.align_y(iced::Alignment::Center)
.apply(widget::container)
.align_x(iced::Alignment::End)
Expand Down Expand Up @@ -418,7 +427,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
.take()
.map(|m| icon!("window-close-symbolic", 16, m)),
)
.spacing(8)
.spacing(theme::active().cosmic().space_xxs())
.apply(widget::container)
.center_y(Length::Fill)
.into()
Expand Down
Loading