thebashpotato / egui-aesthetix

Easy to use theming library for egui
MIT License
14 stars 8 forks source link

Feature: Make margin/padding/spacing changes optional #10

Open LGUG2Z opened 2 months ago

LGUG2Z commented 2 months ago

Would it be possible to export variants of the themes which do not automatically bundle margin/padding/spacing changes which differ from the default egui theme along with the colorscheme values?

I am working on a status bar in egui and I was interested in using this crate to provide some nice out-of-the-box themes (and also hopefully get some more people contributing themes here?), but these bundled margin/padding/spacing changes can throw users' existing status bar layouts a little out of whack:

Without egui-aesthetix:

image

With egui-aesthetix:

image

thebashpotato commented 2 months ago

Hey, first off thanks for interest in the project and taking time to open an issue.

You are absolutely right, I've been meaning to take some time and refactor the spacing, margin, padding and shadowing.

I do like the idea of every theme keeping the default egui styles (except for the colors) out of the box. But there needs to be an easy way for the user to inject styles.

I feel like,

Step 1 could be, refactoring the Aesthetix trait to have default egui styles which would propagate to what ever theme implements the trait. Clean up the color schemes, then do a release.

Step 2 could be, implement an easy way for styles, padding, etc to be injected into each Theme, maybe supply some prebuilt custom styles that would match the Gnome desktops GUI style (just an example) what do you think?

philpax commented 1 month ago

Hiya, I had the same issue and implemented an adapter that restores the normal spacing (as mentioned in the trait):

struct AesthetixWithNormalSpacing<A: egui_aesthetix::Aesthetix>(A);
impl<A: egui_aesthetix::Aesthetix> egui_aesthetix::Aesthetix for AesthetixWithNormalSpacing<A> {
    fn name(&self) -> &str {
        self.0.name()
    }
    fn primary_accent_color_visuals(&self) -> egui::Color32 {
        self.0.primary_accent_color_visuals()
    }
    fn secondary_accent_color_visuals(&self) -> egui::Color32 {
        self.0.secondary_accent_color_visuals()
    }
    fn bg_primary_color_visuals(&self) -> egui::Color32 {
        self.0.bg_primary_color_visuals()
    }
    fn bg_secondary_color_visuals(&self) -> egui::Color32 {
        self.0.bg_secondary_color_visuals()
    }
    fn bg_triage_color_visuals(&self) -> egui::Color32 {
        self.0.bg_triage_color_visuals()
    }
    fn bg_auxiliary_color_visuals(&self) -> egui::Color32 {
        self.0.bg_auxiliary_color_visuals()
    }
    fn bg_contrast_color_visuals(&self) -> egui::Color32 {
        self.0.bg_contrast_color_visuals()
    }
    fn fg_primary_text_color_visuals(&self) -> Option<egui::Color32> {
        self.0.fg_primary_text_color_visuals()
    }
    fn fg_success_text_color_visuals(&self) -> egui::Color32 {
        self.0.fg_success_text_color_visuals()
    }
    fn fg_warn_text_color_visuals(&self) -> egui::Color32 {
        self.0.fg_warn_text_color_visuals()
    }
    fn fg_error_text_color_visuals(&self) -> egui::Color32 {
        self.0.fg_error_text_color_visuals()
    }
    fn dark_mode_visuals(&self) -> bool {
        self.0.dark_mode_visuals()
    }
    fn margin_style(&self) -> f32 {
        6.0
    }
    fn button_padding(&self) -> egui::Vec2 {
        egui::Vec2::new(6.0, 4.0)
    }
    fn item_spacing_style(&self) -> f32 {
        4.0
    }
    fn scroll_bar_width_style(&self) -> f32 {
        6.0
    }
    fn rounding_visuals(&self) -> f32 {
        4.0
    }
}

contexts.ctx_mut().set_style(Arc::new(
    AesthetixWithNormalSpacing(egui_aesthetix::themes::NordDark).custom_style(),
));

A similar technique could be used to flip the default around, such that that standard egui spacing is used by default, and the custom spacing is applied on top.

EDIT: It might also be worth having fn name(&self) return a Cow<str> or a String. I'd like to have my adapter return the name with a suffix, but the only way to do that would be to add a String field to my struct to borrow from. That's fine, but it's not quite as elegant.