Skip to content

Setting override_text_color, font sizes in run_native() does not work on Windows #5840

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

Open
barries opened this issue Mar 21, 2025 · 0 comments
Labels
bug Something is broken

Comments

@barries
Copy link

barries commented Mar 21, 2025

Describe the bug
Changing at least some style members in eframe::run_native()'s app_creator callback works fine under Linux, but seems to have no effect in Windows. Repro code with workaround below.

To Reproduce
Steps to reproduce the behavior:

  1. Set override_text_color or text_styles's font_id.sizes in eframe::run_native()'s app_creator callback.
  2. Run on Linux
  3. See correct colors and sizes
  4. Run on Windows
  5. See incorrect colors and sizes
  6. Add workaround shown below
  7. Run on Windows
  8. See correct colors and sizes

Expected behavior

See the style changes on Windows.

Desktop (please complete the following information):

  • OS: Ubuntu 22.04 and Windows 11 Pro
  • egui / eframe: 0.31.0

Additional context

impl LogViewerApp {
    ...
    pub fn run(self) -> eframe::Result {
        let native_options = eframe::NativeOptions {
            ...
        };

        eframe::run_native(
            "LogViewer",
            native_options,
            Box::new(|cc| {
                setup_custom_fonts(&cc.egui_ctx);
                cc.egui_ctx.style_mut(|style| { // This doesn't work on Windows. For example, override_text_color is None in update().
                    style.visuals = Visuals {
                        override_text_color: Some(TEXT_COLOR),
                        window_fill:         Color32::WHITE,
                        panel_fill:          Color32::WHITE,
                        ..Visuals::light()
                    };
                    for (_, font_id) in &mut style.text_styles {
                        font_id.size = 16.0;
                    }
                });
                Ok(Box::new(self))
            }),
        )
    }
}

impl eframe::App for LogViewerApp {
    fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
        ctx.style_mut(|style| { // Workaround for the above code not working on Windows
            style.visuals = Visuals {
                override_text_color: Some(TEXT_COLOR),
                window_fill:         Color32::WHITE,
                panel_fill:          Color32::WHITE,
                ..Visuals::light()
            };
            for (_, font_id) in &mut style.text_styles {
                font_id.size = 16.0;
            }
        });
        self.0.update(ctx, frame);
    }
}
@barries barries added the bug Something is broken label Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

No branches or pull requests

1 participant