use egui::{Color32, FontFamily, FontId, Rounding, Stroke, TextStyle};
use super::{
BRAND, GROUND, HAIRLINE, INK, RADIUS, RAISED, SURFACE, State, accent, space, tint, type_scale,
};
pub fn install(ctx: &egui::Context) {
let mut style = egui::Style {
text_styles: text_styles(),
..egui::Style::default()
};
let spacing = &mut style.spacing;
spacing.item_spacing = egui::vec2(space::S, space::XXS);
spacing.button_padding = egui::vec2(space::S, space::XXS);
spacing.interact_size = egui::vec2(space::XL + space::L, space::L);
spacing.indent = space::L;
spacing.window_margin = egui::Margin::same(space::M);
spacing.menu_margin = egui::Margin::same(space::S);
style.visuals = visuals();
ctx.set_style(style);
}
fn text_styles() -> std::collections::BTreeMap<TextStyle, FontId> {
[
(
TextStyle::Small,
FontId::new(type_scale::SMALL, FontFamily::Proportional),
),
(
TextStyle::Body,
FontId::new(type_scale::BODY, FontFamily::Proportional),
),
(
TextStyle::Button,
FontId::new(type_scale::BODY, FontFamily::Proportional),
),
(
TextStyle::Heading,
FontId::new(type_scale::HEADING, FontFamily::Proportional),
),
(
TextStyle::Monospace,
FontId::new(type_scale::MONO, FontFamily::Monospace),
),
]
.into()
}
pub fn visuals() -> egui::Visuals {
let mut v = egui::Visuals::dark();
v.override_text_color = None;
v.panel_fill = GROUND;
v.window_fill = SURFACE;
v.window_stroke = Stroke::NONE;
v.window_rounding = Rounding::same(RADIUS);
v.menu_rounding = Rounding::same(RADIUS);
v.faint_bg_color = SURFACE;
v.extreme_bg_color = SURFACE;
v.code_bg_color = RAISED;
v.hyperlink_color = BRAND;
v.warn_fg_color = accent(State::Annotation);
v.error_fg_color = accent(State::Error);
v.text_cursor.stroke = Stroke::new(2.0, BRAND);
v.selection.bg_fill = tint(State::Working);
v.selection.stroke = Stroke::new(1.0, BRAND);
v.widgets.noninteractive = widget(GROUND, Stroke::new(1.0, HAIRLINE), INK);
v.widgets.inactive = widget(SURFACE, Stroke::NONE, INK);
v.widgets.hovered = widget(RAISED, Stroke::NONE, INK);
v.widgets.active = widget(RAISED, Stroke::new(1.0, BRAND), INK);
v.widgets.open = widget(RAISED, Stroke::NONE, INK);
v.button_frame = true;
v.striped = false;
v
}
fn widget(fill: Color32, boundary: Stroke, ink: Color32) -> egui::style::WidgetVisuals {
egui::style::WidgetVisuals {
bg_fill: fill,
weak_bg_fill: fill,
bg_stroke: boundary,
rounding: Rounding::same(RADIUS),
fg_stroke: Stroke::new(1.0, ink),
expansion: 0.0,
}
}