refactor: remove extra opacity where it was added

This commit is contained in:
Ashley Wulber 2026-04-21 11:14:23 -04:00 committed by Ashley Wulber
parent 732785a50c
commit 2d7f66d528
4 changed files with 31 additions and 10 deletions

View file

@ -373,7 +373,6 @@ impl Context {
let cosmic = theme.cosmic(); let cosmic = theme.cosmic();
let corners = cosmic.corner_radii; let corners = cosmic.corner_radii;
let mut bg = cosmic.background(theme.transparent).base; let mut bg = cosmic.background(theme.transparent).base;
bg.alpha = (bg.alpha + if cosmic.is_dark { 0.6 } else { 0.5 }).min(1.);
iced_widget::container::Style { iced_widget::container::Style {
text_color: Some(cosmic.background(theme.transparent).on.into()), text_color: Some(cosmic.background(theme.transparent).on.into()),
background: Some(Color::from(bg).into()), background: Some(Color::from(bg).into()),

View file

@ -389,7 +389,9 @@ pub enum Container<'a> {
WindowBackground, WindowBackground,
Background, Background,
Card, Card,
ContextDrawer, ContextDrawer {
transparent: bool,
},
Custom(Box<dyn Fn(&Theme) -> iced_container::Style + 'a>), Custom(Box<dyn Fn(&Theme) -> iced_container::Style + 'a>),
Dialog, Dialog,
Dropdown, Dropdown,
@ -587,11 +589,8 @@ impl iced_container::Catalog for Theme {
} }
} }
Container::ContextDrawer => { Container::ContextDrawer { transparent } => {
let mut a = Container::primary(cosmic, self.transparent); let mut a = Container::primary(cosmic, self.transparent && *transparent);
if let Some(Background::Color(ref mut color)) = a.background {
color.a = (color.a + if cosmic.is_dark { 0.60 } else { 0.5 }).min(1.);
}
if cosmic.is_high_contrast { if cosmic.is_high_contrast {
a.border.width = 1.; a.border.width = 1.;

View file

@ -66,7 +66,6 @@ impl StyleSheet for Theme {
let cosmic = self.cosmic(); let cosmic = self.cosmic();
let component = &cosmic.background(self.transparent).component; let component = &cosmic.background(self.transparent).component;
let mut bg = component.base; let mut bg = component.base;
bg.alpha = (bg.alpha + if cosmic.is_dark { 0.6 } else { 0.5 }).min(1.);
match style { match style {
MenuBarStyle::Default => Appearance { MenuBarStyle::Default => Appearance {

View file

@ -31,6 +31,24 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
on_close: Message, on_close: Message,
max_width: f32, max_width: f32,
) -> Element<'a, Message> ) -> Element<'a, Message>
where
Drawer: Into<Element<'a, Message>>,
{
Self::new_inner_overlay(
title, actions, header, footer, drawer, on_close, max_width, false,
)
}
pub fn new_inner_overlay<Drawer>(
title: Option<Cow<'a, str>>,
actions: Option<Element<'a, Message>>,
header: Option<Element<'a, Message>>,
footer: Option<Element<'a, Message>>,
drawer: Drawer,
on_close: Message,
max_width: f32,
overlay: bool,
) -> Element<'a, Message>
where where
Drawer: Into<Element<'a, Message>>, Drawer: Into<Element<'a, Message>>,
{ {
@ -43,6 +61,7 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
drawer: Element<'a, Message>, drawer: Element<'a, Message>,
on_close: Message, on_close: Message,
max_width: f32, max_width: f32,
overlay: bool,
) -> Element<'a, Message> { ) -> Element<'a, Message> {
let cosmic_theme::Spacing { let cosmic_theme::Spacing {
space_xxs, space_xxs,
@ -105,7 +124,9 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
container( container(
LayerContainer::new(pane) LayerContainer::new(pane)
.layer(cosmic_theme::Layer::Primary) .layer(cosmic_theme::Layer::Primary)
.class(crate::style::Container::ContextDrawer) .class(crate::style::Container::ContextDrawer {
transparent: !overlay,
})
.width(Length::Fill) .width(Length::Fill)
.height(Length::Fill) .height(Length::Fill)
.max_width(max_width), .max_width(max_width),
@ -124,6 +145,7 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
drawer.into(), drawer.into(),
on_close, on_close,
max_width, max_width,
overlay,
) )
} }
@ -142,7 +164,9 @@ impl<'a, Message: Clone + 'static> ContextDrawer<'a, Message> {
Content: Into<Element<'a, Message>>, Content: Into<Element<'a, Message>>,
Drawer: Into<Element<'a, Message>>, Drawer: Into<Element<'a, Message>>,
{ {
let drawer = Self::new_inner(title, actions, header, footer, drawer, on_close, max_width); let drawer = Self::new_inner_overlay(
title, actions, header, footer, drawer, on_close, max_width, true,
);
ContextDrawer { ContextDrawer {
id: None, id: None,