diff --git a/src/app/mod.rs b/src/app/mod.rs index eb53a67ecf2..6051a2e91f9 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -882,7 +882,30 @@ impl 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 @@ -892,11 +915,17 @@ impl 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() }); diff --git a/src/theme/style/iced.rs b/src/theme/style/iced.rs index f51e2650ab0..1bf20524c7a 100644 --- a/src/theme/style/iced.rs +++ b/src/theme/style/iced.rs @@ -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(), }, @@ -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(), } } diff --git a/src/widget/header_bar.rs b/src/widget/header_bar.rs index 972f92a4297..7108e65263b 100644 --- a/src/widget/header_bar.rs +++ b/src/widget/header_bar.rs @@ -1,8 +1,8 @@ // Copyright 2022 System76 // 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; @@ -287,6 +287,12 @@ impl<'a, Message: Clone + 'static> Widget 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); @@ -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) @@ -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) @@ -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) @@ -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()