Skip to content

Commit

Permalink
fix(dropdown): styling
Browse files Browse the repository at this point in the history
  • Loading branch information
git-f0x authored and mmstick committed Dec 25, 2024
1 parent 2d06ec4 commit 58fc034
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 69 deletions.
30 changes: 9 additions & 21 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,14 +703,11 @@ impl<App: Application> ApplicationExt for App {
.focused_window()
.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 {
if nav_bar_active {
[0, window_padding, window_padding, 0]
[0, 8, 8, 0]
} else {
[0, window_padding, window_padding, window_padding]
[0, 8, 8, 8]
}
} else {
[0, 0, 0, 0]
Expand All @@ -724,11 +721,7 @@ impl<App: Application> ApplicationExt for App {
.nav_bar()
.map(|nav| id_container(nav, iced_core::id::Id::new("COSMIC_nav_bar")))
{
widgets.push(
container(nav)
.padding([0, window_padding, window_padding, window_padding])
.into(),
);
widgets.push(container(nav).padding([0, 8, 8, 8]).into());
true
} else {
false
Expand Down Expand Up @@ -760,7 +753,7 @@ impl<App: Application> ApplicationExt for App {
})
.apply(container)
.padding(if content_container {
[0, window_padding, window_padding, 0]
[0, 8, 8, 0]
} else {
[0, 0, 0, 0]
})
Expand Down Expand Up @@ -808,7 +801,7 @@ impl<App: Application> ApplicationExt for App {
})
.apply(container)
.padding(if content_container {
[0, window_padding, window_padding, 0]
[0, 8, 8, 0]
} else {
[0, 0, 0, 0]
})
Expand All @@ -825,14 +818,10 @@ impl<App: Application> ApplicationExt for App {
});
let content_col = crate::widget::column::with_capacity(2)
.push(content_row)
.push_maybe(self.footer().map(|footer| {
container(footer.map(Message::App)).padding([
0,
window_padding,
window_padding,
window_padding,
])
}));
.push_maybe(
self.footer()
.map(|footer| container(footer.map(Message::App)).padding([0, 8, 8, 8])),
);
let content: Element<_> = if core.window.content_container {
content_col
.apply(container)
Expand All @@ -851,7 +840,6 @@ impl<App: Application> ApplicationExt for App {
let mut header = crate::widget::header_bar()
.focused(focused)
.title(&core.window.header_title)
.horizontal_padding(window_padding)
.on_drag(Message::Cosmic(cosmic::Message::Drag))
.on_right_click(Message::Cosmic(cosmic::Message::ShowWindowMenu))
.on_double_click(Message::Cosmic(cosmic::Message::Maximize));
Expand Down
25 changes: 11 additions & 14 deletions src/theme/style/iced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,20 +536,17 @@ impl iced_container::Catalog for Theme {

Container::Secondary => Container::secondary(cosmic),

Container::Dropdown => {
let theme = self.cosmic();

iced_container::Style {
icon_color: None,
text_color: None,
background: Some(iced::Background::Color(theme.primary.base.into())),
border: Border {
radius: cosmic.corner_radii.radius_xs.into(),
..Default::default()
},
shadow: Shadow::default(),
}
}
Container::Dropdown => iced_container::Style {
icon_color: None,
text_color: None,
background: Some(iced::Background::Color(cosmic.bg_component_color().into())),
border: Border {
color: cosmic.bg_component_divider().into(),
width: 1.0,
radius: cosmic.corner_radii.radius_s.into(),
},
shadow: Shadow::default(),
},

Container::Tooltip => iced_container::Style {
icon_color: None,
Expand Down
30 changes: 15 additions & 15 deletions src/widget/dropdown/menu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,21 +156,21 @@ impl<'a, Message: 'a> Overlay<'a, Message> {
style,
} = menu;

let mut container = Container::new(Scrollable::new(List {
options,
icons,
hovered_option,
selected_option,
on_selected,
on_option_hovered,
text_size,
text_line_height,
padding,
}));

container = container
.padding(padding)
.class(crate::style::Container::Dropdown);
let mut container = Container::new(Scrollable::new(
Container::new(List {
options,
icons,
hovered_option,
selected_option,
on_selected,
on_option_hovered,
text_size,
text_line_height,
padding,
})
.padding(padding),
))
.class(crate::style::Container::Dropdown);

state.tree.diff(&mut container as &mut dyn Widget<_, _, _>);

Expand Down
28 changes: 14 additions & 14 deletions src/widget/dropdown/multi/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,20 @@ impl<'a, Message: 'a> Overlay<'a, Message> {
style,
} = menu;

let mut container = Container::new(Scrollable::new(InnerList {
options,
hovered_option,
selected_option,
on_selected,
on_option_hovered,
padding,
text_size,
text_line_height,
}));

container = container
.padding(padding)
.class(crate::style::Container::Dropdown);
let mut container = Container::new(Scrollable::new(
Container::new(InnerList {
options,
hovered_option,
selected_option,
on_selected,
on_option_hovered,
padding,
text_size,
text_line_height,
})
.padding(padding),
))
.class(crate::style::Container::Dropdown);

state.tree.diff(&mut container as &mut dyn Widget<_, _, _>);

Expand Down
6 changes: 1 addition & 5 deletions src/widget/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub fn header_bar<'a, Message>() -> HeaderBar<'a, Message> {
center: Vec::new(),
end: Vec::new(),
density: None,
horizontal_padding: 8,
focused: false,
on_double_click: None,
}
Expand Down Expand Up @@ -75,9 +74,6 @@ pub struct HeaderBar<'a, Message> {
#[setters(strip_option)]
density: Option<Density>,

/// Horizontal padding of the headerbar
horizontal_padding: u16,

/// Focused state of the window
focused: bool,
}
Expand Down Expand Up @@ -346,7 +342,7 @@ impl<'a, Message: Clone + 'static> HeaderBar<'a, Message> {
)
.align_y(iced::Alignment::Center)
.height(Length::Fixed(height))
.padding([0, self.horizontal_padding])
.padding([0, 8])
.spacing(8)
.apply(widget::container)
.class(crate::theme::Container::HeaderBar {
Expand Down

0 comments on commit 58fc034

Please sign in to comment.