use super::Tint;
use crate::density;
use crate::theme::{self, surface, FontScale};
use iced::widget::{container, text, text::IntoFragment, Text};
use iced::{Background, Border, Element};
const CHIP_FILL_ALPHA: f32 = 0.10;
const CHIP_BORDER_ALPHA: f32 = 0.45;
pub fn chip<'a, Message: 'a>(
label: impl IntoFragment<'a>,
tint: Tint,
scale: FontScale,
) -> Element<'a, Message> {
let color = tint.iced();
container(
text(label)
.font(theme::mono_font())
.size(scale.apply(density::META_TEXT_BASE * 0.9))
.color(color)
.wrapping(iced::widget::text::Wrapping::None),
)
.padding([1.0, scale.apply(6.0)])
.style(move |_t: &iced::Theme| container::Style {
background: Some(Background::Color(iced::Color { a: CHIP_FILL_ALPHA, ..color })),
border: Border {
radius: density::nested_radius().into(),
width: 1.0,
color: iced::Color { a: CHIP_BORDER_ALPHA, ..color },
},
..container::Style::default()
})
.into()
}
pub fn removable_chip<'a, Message: Clone + 'a>(
label: impl IntoFragment<'a>,
on_remove: Message,
scale: FontScale,
) -> Element<'a, Message> {
let size = scale.apply(density::META_TEXT_BASE * 0.9);
let cross = iced::widget::button(text("\u{00d7}").size(size).color(theme::text_dim()))
.padding([0.0, scale.apply(2.0)])
.on_press(on_remove)
.style(|_t: &iced::Theme, status| iced::widget::button::Style {
background: matches!(status, iced::widget::button::Status::Hovered)
.then(|| Background::Color(surface::card())),
text_color: theme::text(),
border: Border { radius: density::nested_radius().into(), ..Border::default() },
..iced::widget::button::Style::default()
});
container(
iced::widget::row![
text(label)
.font(theme::mono_font())
.size(size)
.color(theme::text())
.wrapping(iced::widget::text::Wrapping::None),
cross,
]
.spacing(scale.apply(2.0))
.align_y(iced::Alignment::Center),
)
.padding([0.0, scale.apply(4.0)])
.style(|_t: &iced::Theme| container::Style {
background: Some(Background::Color(surface::row())),
border: Border { radius: density::nested_radius().into(), width: 1.0, color: surface::card_border() },
..container::Style::default()
})
.into()
}
pub fn keycap<'a, Message: 'a>(label: impl IntoFragment<'a>, scale: FontScale) -> Element<'a, Message> {
container(
text(label)
.font(iced::Font { weight: iced::font::Weight::Semibold, ..theme::mono_font() })
.size(scale.apply(density::META_TEXT_BASE * 0.85))
.color(theme::text()),
)
.padding([1.0, scale.apply(6.0)])
.style(|_t: &iced::Theme| container::Style {
background: Some(Background::Color(surface::sidebar())),
border: Border {
radius: density::nested_radius().into(),
width: 1.0,
color: surface::card_border(),
},
..container::Style::default()
})
.into()
}
pub fn config_line<'a>(content: impl IntoFragment<'a>, scale: FontScale) -> Text<'a> {
text(content)
.font(theme::mono_font())
.size(scale.apply(density::META_TEXT_BASE * 0.9))
.color(theme::text_dim())
}