fix(style): use radius_s for nav bar toggle

This commit is contained in:
Vukašin Vojinović 2024-12-05 21:16:10 +01:00 committed by Michael Murphy
parent 75a11b3c84
commit 2d06ec4226
5 changed files with 35 additions and 27 deletions

View file

@ -703,11 +703,14 @@ impl<App: Application> ApplicationExt for App {
.focused_window() .focused_window()
.is_some_and(|i| Some(i) == self.core().main_window_id()); .is_some_and(|i| Some(i) == self.core().main_window_id());
// Offset for the window border
let window_padding = if sharp_corners { 8 } else { 7 };
let main_content_padding = if content_container { let main_content_padding = if content_container {
if nav_bar_active { if nav_bar_active {
[0, 8, 8, 0] [0, window_padding, window_padding, 0]
} else { } else {
[0, 8, 8, 8] [0, window_padding, window_padding, window_padding]
} }
} else { } else {
[0, 0, 0, 0] [0, 0, 0, 0]
@ -721,7 +724,11 @@ impl<App: Application> ApplicationExt for App {
.nav_bar() .nav_bar()
.map(|nav| id_container(nav, iced_core::id::Id::new("COSMIC_nav_bar"))) .map(|nav| id_container(nav, iced_core::id::Id::new("COSMIC_nav_bar")))
{ {
widgets.push(container(nav).padding([0, 8, 8, 8]).into()); widgets.push(
container(nav)
.padding([0, window_padding, window_padding, window_padding])
.into(),
);
true true
} else { } else {
false false
@ -753,7 +760,7 @@ impl<App: Application> ApplicationExt for App {
}) })
.apply(container) .apply(container)
.padding(if content_container { .padding(if content_container {
[0, 8, 8, 0] [0, window_padding, window_padding, 0]
} else { } else {
[0, 0, 0, 0] [0, 0, 0, 0]
}) })
@ -801,7 +808,7 @@ impl<App: Application> ApplicationExt for App {
}) })
.apply(container) .apply(container)
.padding(if content_container { .padding(if content_container {
[0, 8, 8, 0] [0, window_padding, window_padding, 0]
} else { } else {
[0, 0, 0, 0] [0, 0, 0, 0]
}) })
@ -818,10 +825,14 @@ impl<App: Application> ApplicationExt for App {
}); });
let content_col = crate::widget::column::with_capacity(2) let content_col = crate::widget::column::with_capacity(2)
.push(content_row) .push(content_row)
.push_maybe( .push_maybe(self.footer().map(|footer| {
self.footer() container(footer.map(Message::App)).padding([
.map(|footer| container(footer.map(Message::App)).padding([0, 8, 8, 8])), 0,
); window_padding,
window_padding,
window_padding,
])
}));
let content: Element<_> = if core.window.content_container { let content: Element<_> = if core.window.content_container {
content_col content_col
.apply(container) .apply(container)
@ -840,6 +851,7 @@ impl<App: Application> ApplicationExt for App {
let mut header = crate::widget::header_bar() let mut header = crate::widget::header_bar()
.focused(focused) .focused(focused)
.title(&core.window.header_title) .title(&core.window.header_title)
.horizontal_padding(window_padding)
.on_drag(Message::Cosmic(cosmic::Message::Drag)) .on_drag(Message::Cosmic(cosmic::Message::Drag))
.on_right_click(Message::Cosmic(cosmic::Message::ShowWindowMenu)) .on_right_click(Message::Cosmic(cosmic::Message::ShowWindowMenu))
.on_double_click(Message::Cosmic(cosmic::Message::Maximize)); .on_double_click(Message::Cosmic(cosmic::Message::Maximize));
@ -852,8 +864,7 @@ impl<App: Application> ApplicationExt for App {
Message::Cosmic(cosmic::Message::ToggleNavBarCondensed) Message::Cosmic(cosmic::Message::ToggleNavBarCondensed)
} else { } else {
Message::Cosmic(cosmic::Message::ToggleNavBar) Message::Cosmic(cosmic::Message::ToggleNavBar)
}) });
.class(crate::theme::Button::HeaderBar);
header = header.start(toggle); header = header.start(toggle);
} }

View file

@ -14,13 +14,13 @@ use crate::{
#[derive(Default)] #[derive(Default)]
pub enum Button { pub enum Button {
AppletIcon, AppletIcon,
AppletMenu,
Custom { Custom {
active: Box<dyn Fn(bool, &crate::Theme) -> Style>, active: Box<dyn Fn(bool, &crate::Theme) -> Style>,
disabled: Box<dyn Fn(&crate::Theme) -> Style>, disabled: Box<dyn Fn(&crate::Theme) -> Style>,
hovered: Box<dyn Fn(bool, &crate::Theme) -> Style>, hovered: Box<dyn Fn(bool, &crate::Theme) -> Style>,
pressed: Box<dyn Fn(bool, &crate::Theme) -> Style>, pressed: Box<dyn Fn(bool, &crate::Theme) -> Style>,
}, },
AppletMenu,
Destructive, Destructive,
HeaderBar, HeaderBar,
Icon, Icon,
@ -31,6 +31,7 @@ pub enum Button {
MenuFolder, MenuFolder,
MenuItem, MenuItem,
MenuRoot, MenuRoot,
NavToggle,
#[default] #[default]
Standard, Standard,
Suggested, Suggested,
@ -73,7 +74,7 @@ pub fn appearance(
} }
} }
Button::Icon | Button::IconVertical | Button::HeaderBar => { Button::Icon | Button::IconVertical | Button::HeaderBar | Button::NavToggle => {
if matches!(style, Button::IconVertical) { if matches!(style, Button::IconVertical) {
corner_radii = &cosmic.corner_radii.radius_m; corner_radii = &cosmic.corner_radii.radius_m;
if selected { if selected {
@ -82,6 +83,9 @@ pub fn appearance(
))); )));
} }
} }
if matches!(style, Button::NavToggle) {
corner_radii = &cosmic.corner_radii.radius_s;
}
let (background, text, icon) = color(&cosmic.icon_button); let (background, text, icon) = color(&cosmic.icon_button);
appearance.background = Some(Background::Color(background)); appearance.background = Some(Background::Color(background));

View file

@ -528,17 +528,7 @@ impl iced_container::Catalog for Theme {
} }
} }
Container::ContextDrawer => { Container::ContextDrawer => Container::primary(cosmic),
let mut appearance = Container::primary(cosmic);
appearance.shadow = Shadow {
color: cosmic.shade.into(),
offset: Vector::new(0.0, 0.0),
blur_radius: 16.0,
};
appearance
}
Container::Background => Container::background(cosmic), Container::Background => Container::background(cosmic),

View file

@ -22,6 +22,7 @@ pub fn header_bar<'a, Message>() -> HeaderBar<'a, Message> {
center: Vec::new(), center: Vec::new(),
end: Vec::new(), end: Vec::new(),
density: None, density: None,
horizontal_padding: 8,
focused: false, focused: false,
on_double_click: None, on_double_click: None,
} }
@ -74,6 +75,9 @@ pub struct HeaderBar<'a, Message> {
#[setters(strip_option)] #[setters(strip_option)]
density: Option<Density>, density: Option<Density>,
/// Horizontal padding of the headerbar
horizontal_padding: u16,
/// Focused state of the window /// Focused state of the window
focused: bool, focused: bool,
} }
@ -299,7 +303,6 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
let mut end = std::mem::take(&mut self.end); let mut end = std::mem::take(&mut self.end);
// Also packs the window controls at the very end. // Also packs the window controls at the very end.
end.push(widget::horizontal_space().width(Length::Fixed(12.0)).into());
end.push(self.window_controls()); end.push(self.window_controls());
let height = match self.density.unwrap_or_else(crate::config::header_size) { let height = match self.density.unwrap_or_else(crate::config::header_size) {
@ -343,7 +346,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
) )
.align_y(iced::Alignment::Center) .align_y(iced::Alignment::Center)
.height(Length::Fixed(height)) .height(Length::Fixed(height))
.padding([0, 8]) .padding([0, self.horizontal_padding])
.spacing(8) .spacing(8)
.apply(widget::container) .apply(widget::container)
.class(crate::theme::Container::HeaderBar { .class(crate::theme::Container::HeaderBar {

View file

@ -20,7 +20,7 @@ pub fn nav_bar_toggle<Message>() -> NavBarToggle<Message> {
NavBarToggle { NavBarToggle {
active: false, active: false,
on_toggle: None, on_toggle: None,
class: crate::theme::Button::Text, class: crate::theme::Button::NavToggle,
selected: false, selected: false,
} }
} }