use iced::widget::container;
use iced::{Background, Border, Color, Theme};
use super::super::theme::{
tokyo_blue, tokyo_board, tokyo_border, tokyo_modal_backdrop, tokyo_red, tokyo_red_fill,
tokyo_selection_blue, tokyo_text,
};
pub(crate) fn app_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 0.0, 0.0, Color::TRANSPARENT)
}
pub(crate) fn menu_bar_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 0.0, 0.0, Color::TRANSPARENT)
}
pub(crate) fn board_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 8.0, 1.0, tokyo_border())
}
pub(crate) fn schematic_board_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 0.0, 0.0, Color::TRANSPARENT)
}
pub(crate) fn menu_bar_divider_style(_theme: &Theme) -> container::Style {
container::Style {
background: Some(Background::Color(tokyo_board())),
border: Border {
radius: 0.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
..container::Style::default()
}
}
pub(crate) fn panel_style(theme: &Theme) -> container::Style {
board_style(theme)
}
pub(crate) fn modal_backdrop_style(_theme: &Theme) -> container::Style {
container::Style {
background: Some(Background::Color(tokyo_modal_backdrop())),
..container::Style::default()
}
}
pub(crate) fn large_dialog_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 12.0, 1.0, tokyo_border())
}
pub(crate) fn inset_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 6.0, 1.0, tokyo_border())
}
pub(crate) fn status_tooltip_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 6.0, 1.0, tokyo_border())
}
pub(crate) fn error_inset_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 8.0, 1.5, tokyo_red())
}
pub(crate) fn schematic_block_style(_theme: &Theme) -> container::Style {
surface_style(None, 6.0, 1.0, tokyo_border())
}
pub(crate) fn mux_header_style(_theme: &Theme) -> container::Style {
container::Style {
background: None,
text_color: Some(tokyo_text()),
border: Border {
radius: iced::border::Radius {
top_left: 6.0,
top_right: 6.0,
bottom_right: 0.0,
bottom_left: 0.0,
},
width: 1.0,
color: tokyo_border(),
},
..container::Style::default()
}
}
pub(crate) fn mux_panel_style(_theme: &Theme) -> container::Style {
surface_style(None, 6.0, 1.0, tokyo_border())
}
pub(crate) fn mux_chip_style(_theme: &Theme) -> container::Style {
surface_style(None, 6.0, 1.0, tokyo_border())
}
pub(crate) fn legend_label_style(_theme: &Theme) -> container::Style {
surface_style(Some(tokyo_board()), 0.0, 0.0, Color::TRANSPARENT)
}
pub(crate) fn transparent_style(_theme: &Theme) -> container::Style {
surface_style(None, 0.0, 0.0, Color::TRANSPARENT)
}
pub(crate) fn input_shell_style(_theme: &Theme, focused: bool) -> container::Style {
let border_color = if focused {
tokyo_blue()
} else {
tokyo_border()
};
surface_style(Some(tokyo_board()), 6.0, 1.0, border_color)
}
pub(crate) fn opcode_dropdown_style(_theme: &Theme) -> container::Style {
container::Style {
text_color: Some(tokyo_text()),
background: Some(Background::Color(tokyo_board())),
border: Border {
radius: iced::border::Radius {
top_left: 7.0,
top_right: 7.0,
bottom_right: 7.0,
bottom_left: 7.0,
},
width: 1.0,
color: tokyo_border(),
},
..container::Style::default()
}
}
pub(crate) fn memory_row_container_style(selected: bool, halted: bool) -> container::Style {
if halted {
return container::Style {
background: Some(Background::Color(tokyo_red_fill())),
text_color: Some(tokyo_text()),
border: Border {
radius: 6.0.into(),
width: 0.0,
color: Color::TRANSPARENT,
},
..container::Style::default()
};
}
let background = if selected {
Some(Background::Color(tokyo_selection_blue()))
} else {
None
};
container::Style {
background,
text_color: Some(tokyo_text()),
border: Border {
radius: if selected { 6.0.into() } else { 0.0.into() },
width: 0.0,
color: Color::TRANSPARENT,
},
..container::Style::default()
}
}
pub(crate) fn solid_style(color: Color, radius: f32) -> container::Style {
container::Style {
background: Some(Background::Color(color)),
border: Border {
radius: radius.into(),
..Border::default()
},
..container::Style::default()
}
}
pub(crate) fn surface_style(
background: Option<Color>,
radius: f32,
border_width: f32,
border_color: Color,
) -> container::Style {
container::Style {
text_color: Some(tokyo_text()),
background: background.map(Background::Color),
border: Border {
radius: radius.into(),
width: border_width,
color: border_color,
},
..container::Style::default()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn opcode_dropdown_has_rounded_top_corners() {
let style = opcode_dropdown_style(&Theme::TokyoNight);
assert!(style.border.radius.top_left > 0.0);
assert!(style.border.radius.top_right > 0.0);
}
#[test]
fn regular_tooltips_share_status_tooltip_surface() {
let inset = inset_style(&Theme::TokyoNight);
let status = status_tooltip_style(&Theme::TokyoNight);
assert_eq!(inset.background, status.background);
}
#[test]
fn input_shell_background_matches_app_plate() {
let idle = input_shell_style(&Theme::TokyoNight, false);
let focused = input_shell_style(&Theme::TokyoNight, true);
assert_eq!(idle.background, Some(Background::Color(tokyo_board())));
assert_eq!(focused.background, Some(Background::Color(tokyo_board())));
}
#[test]
fn menu_bar_divider_paints_as_app_plate() {
let divider = menu_bar_divider_style(&Theme::TokyoNight);
assert_eq!(divider.background, Some(Background::Color(tokyo_board())));
}
}