Jovian-Entertainment-Studios / Project-Heaven-Code

GNU General Public License v3.0
9 stars 0 forks source link

Implement a custom egui style #1

Closed AlbinSjoegren closed 2 years ago

AlbinSjoegren commented 2 years ago

From SPV sourcecode:

fn setup(
        &mut self,
        ctx: &egui::CtxRef,
        frame: &epi::Frame,
        storage: Option<&dyn epi::Storage>,
    ) {
        #[cfg(feature = "persistence")]
        if let Some(storage) = storage {
            *self = epi::get_value(storage, epi::APP_KEY).unwrap_or_default()
        }

        let mut style: egui::Style = (*ctx.style()).clone();

        style.visuals.extreme_bg_color = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.faint_bg_color = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.code_bg_color = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.hyperlink_color = egui::Color32::from_rgb(255, 0, 0);

        style.visuals.override_text_color = Some(egui::Color32::from_rgb(173, 186, 199));

        style.visuals.window_corner_radius = 10.0;

        style.visuals.button_frame = true;

        style.visuals.collapsing_header_frame = true;

        style.visuals.widgets.noninteractive.bg_fill = egui::Color32::from_rgb(35, 39, 46);

        style.visuals.widgets.noninteractive.fg_stroke =
            egui::Stroke::new(0., egui::Color32::from_rgb(173, 186, 199));

        style.visuals.widgets.inactive.bg_fill = egui::Color32::TRANSPARENT;

        style.visuals.widgets.hovered.bg_fill = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.widgets.active.bg_fill = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.widgets.open.bg_fill = egui::Color32::from_rgb(45, 51, 59);

        style.visuals.widgets.noninteractive.fg_stroke = egui::Stroke{width: 10.0, color: egui::Color32::from_rgb(173, 186, 199)};

        ctx.set_style(style);

        let font_droidsansmono = include_bytes!("data/Droid Sans Mono Nerd Font Complete Mono.otf");
        let mut font = FontDefinitions::default();

        font.font_data.insert(
            "Droid Sans Mono".to_string(),
            egui::FontData{ font: Cow::from(&font_droidsansmono[..]), index: 0 },
        );
        font.fonts_for_family
            .insert(FontFamily::Monospace, vec!["Droid Sans Mono".to_string()]);

        font.fonts_for_family.insert(
            FontFamily::Proportional,
            vec!["Droid Sans Mono".to_string()],
        );
        /*
        font.family_and_size.insert(
            epaint::text::TextStyle::Body,
            (epaint::text::FontFamily::Proportional, 10.0),
        );
        font.family_and_size.insert(
            epaint::text::TextStyle::Body,
            (epaint::text::FontFamily::Monospace, 10.0),
        );
        */
        ctx.set_fonts(font);
    }
AlbinSjoegren commented 2 years ago

We basically only need the ctx variable

AlbinSjoegren commented 2 years ago

Done