libcosmic/src/widget/navigation/macros.rs

59 lines
2 KiB
Rust
Raw Normal View History

// Copyright 2022 System76 <info@system76.com>
// SPDX-License-Identifier: MPL-2.0
2022-10-12 19:44:44 -07:00
pub mod nav_bar {
use crate::Theme;
2022-11-11 05:06:54 +01:00
use iced::{widget, Background, Color};
2022-10-12 19:44:44 -07:00
#[macro_export]
macro_rules! nav_button {
2022-12-21 08:58:17 -07:00
($icon: expr, $title:expr, $active:expr) => {{
$crate::iced::widget::Button::new(
$crate::iced::widget::row!(
$crate::widget::icon($icon, 16)
2022-12-19 15:43:05 -07:00
.style(if $active {
2022-12-20 16:02:44 -07:00
$crate::theme::Svg::SymbolicLink
2022-12-19 15:43:05 -07:00
} else {
$crate::theme::Svg::Symbolic
2022-12-21 08:58:17 -07:00
}),
$crate::iced::widget::Text::new($title)
.vertical_alignment($crate::iced::alignment::Vertical::Center),
$crate::iced::widget::horizontal_space($crate::iced::Length::Fill),
2022-12-19 15:43:05 -07:00
)
2022-12-21 08:58:17 -07:00
.spacing(8)
)
2022-12-21 10:06:50 -07:00
.padding([10, 16])
2022-12-21 08:58:17 -07:00
.style(if $active {
$crate::theme::Button::LinkActive
2022-10-12 19:44:44 -07:00
} else {
2022-12-21 08:58:17 -07:00
$crate::theme::Button::Text
})
2022-10-12 19:44:44 -07:00
}};
}
pub fn nav_bar_sections_style(theme: &Theme) -> widget::container::Appearance {
2022-10-12 19:44:44 -07:00
let cosmic = &theme.cosmic().primary;
widget::container::Appearance {
text_color: Some(cosmic.on.into()),
background: Some(Background::Color(cosmic.base.into())),
border_radius: 8.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
pub fn nav_bar_pages_style(theme: &Theme) -> widget::container::Appearance {
let primary = &theme.cosmic().primary;
let secondary = &theme.cosmic().secondary;
widget::container::Appearance {
text_color: Some(primary.on.into()),
background: Some(Background::Color(secondary.component.base.into())),
border_radius: 8.0,
border_width: 0.0,
border_color: Color::TRANSPARENT,
}
}
2022-10-12 19:44:44 -07:00
pub use nav_button;
}