Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LGUG2Z opened this issue Sep 8, 2024 · 2 comments
Open

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

LGUG2Z opened this issue Sep 8, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@LGUG2Z
Copy link

LGUG2Z commented Sep 8, 2024

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 thebashpotato added the enhancement New feature or request label Sep 9, 2024
@thebashpotato
Copy link
Owner

thebashpotato commented Sep 9, 2024

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
Copy link

philpax commented Sep 23, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants