use iced::widget::{button, container, scrollable, text_editor, text_input};
use iced::{Background, Border, Color};
use crate::view::styles::input_borderless_style;
pub(in crate::view) use crate::view::styles::{
large_dialog_style as modal_dialog_style, modal_backdrop_style,
};
use crate::view::theme::{
tokyo_border, tokyo_muted, tokyo_surface, tokyo_surface_2, tokyo_text, tokyo_text_selection,
};
pub(in crate::view) fn sidebar_chip_style(
status: button::Status,
active: bool,
keyboard_focused: bool,
) -> button::Style {
let background = if active || keyboard_focused {
tokyo_surface()
} else {
match status {
button::Status::Pressed => tokyo_surface_2(),
button::Status::Hovered => tokyo_surface(),
_ => Color::TRANSPARENT,
}
};
button::Style {
background: Some(Background::Color(background)),
text_color: tokyo_text(),
border: Border {
radius: 8.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
..button::Style::default()
}
}
pub(in crate::view) fn breadcrumb_button_style(status: button::Status) -> button::Style {
let text_color = match status {
button::Status::Hovered | button::Status::Pressed => tokyo_text(),
_ => tokyo_muted(),
};
button::Style {
background: None,
text_color,
border: Border {
radius: 4.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
..button::Style::default()
}
}
pub(in crate::view) fn help_search_input_style(
theme: &iced::Theme,
status: text_input::Status,
) -> text_input::Style {
text_input::Style {
selection: tokyo_text_selection(),
..input_borderless_style(theme, status)
}
}
pub(in crate::view) fn help_text_editor_style(
_theme: &iced::Theme,
_status: text_editor::Status,
) -> text_editor::Style {
text_editor::Style {
background: Background::Color(Color::TRANSPARENT),
border: Border {
radius: 0.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
placeholder: tokyo_muted(),
value: tokyo_text(),
selection: tokyo_text_selection(),
}
}
pub(in crate::view) fn separator_horizontal() -> container::Style {
container::Style {
background: Some(Background::Color(iced::Color {
a: 0.35,
..tokyo_border()
})),
..container::Style::default()
}
}
pub(in crate::view) fn separator_vertical() -> container::Style {
separator_horizontal()
}
pub(in crate::view) fn hidden_scrollbar_style(
_theme: &iced::Theme,
_status: scrollable::Status,
) -> scrollable::Style {
let invisible_scroller = scrollable::Scroller {
background: Background::Color(Color::TRANSPARENT),
border: Border {
radius: 0.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
};
let invisible_rail = scrollable::Rail {
background: Some(Background::Color(Color::TRANSPARENT)),
border: Border {
radius: 0.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
scroller: invisible_scroller,
};
scrollable::Style {
container: container::Style::default(),
vertical_rail: invisible_rail,
horizontal_rail: invisible_rail,
gap: None,
auto_scroll: scrollable::AutoScroll {
background: Background::Color(Color::TRANSPARENT),
border: Border {
radius: 0.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
shadow: iced::Shadow::default(),
icon: Color::TRANSPARENT,
},
}
}
#[cfg(test)]
mod tests {
use super::*;
use iced::Theme;
#[test]
fn help_search_input_selection_uses_readable_gray_overlay() {
let style = help_search_input_style(
&Theme::TokyoNight,
text_input::Status::Focused { is_hovered: false },
);
assert_eq!(style.selection, tokyo_text_selection());
}
#[test]
fn breadcrumb_hover_highlights_text_without_own_background() {
let style = breadcrumb_button_style(button::Status::Hovered);
assert_eq!(style.background, None);
assert_eq!(style.text_color, tokyo_text());
}
#[test]
fn help_text_editor_keeps_article_surface_transparent() {
let style = help_text_editor_style(&Theme::TokyoNight, text_editor::Status::Active);
assert_eq!(style.background, Background::Color(Color::TRANSPARENT));
assert_eq!(style.selection, tokyo_text_selection());
}
}