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

egui not respecting text color #2005

Open
steventrouble opened this issue Sep 5, 2022 · 3 comments
Open

egui not respecting text color #2005

steventrouble opened this issue Sep 5, 2022 · 3 comments
Labels
bug Something is broken

Comments

@steventrouble
Copy link
Contributor

steventrouble commented Sep 5, 2022

Describe the bug
When I set the text color to black (#000), the text does not turn black. Instead, it is #585858.

I'm trying to make my text darker so it meets accessibility standards:

https://webaim.org/resources/contrastchecker/?fcolor=585858&bcolor=E6E6E6

But the text isn't getting darker.

Button:
Example button

To Reproduce
Steps to reproduce the behavior:

  1. Set the visuals to the following:

    let mut visuals = egui::Visuals::light();
    visuals.widgets.noninteractive.fg_stroke.color = Color32::BLACK;
    visuals.widgets.active.fg_stroke.color = Color32::BLACK;
    visuals.widgets.inactive.fg_stroke.color = Color32::BLACK;
    visuals.widgets.hovered.fg_stroke.color = Color32::BLACK;
    visuals.widgets.open.fg_stroke.color = Color32::BLACK;
    ctx.set_visuals(visuals);
    
  2. Create a button (or any widget).

Expected behavior
The text color should be black, not grey.

Desktop:

  • OS: Windows 11
@steventrouble steventrouble added the bug Something is broken label Sep 5, 2022
@steventrouble steventrouble changed the title [Accessibility] Default contrast is too low egui not respecting text color Sep 5, 2022
@goldwind-ting
Copy link

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
use eframe::egui;
use egui::Color32;
use egui::FontFamily::Monospace;
use egui::FontId;
use egui::TextStyle::*;

fn main() {
    let options = eframe::NativeOptions::default();
    eframe::run_native(
        "My egui App",
        options,
        Box::new(|_cc| Box::new(MyApp::default())),
    );
}

struct MyApp;

impl Default for MyApp {
    fn default() -> Self {
        Self
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        let mut visuals = egui::Visuals::light();

        visuals.widgets.inactive.bg_fill = Color32::WHITE;
        visuals.widgets.inactive.bg_stroke.color = Color32::RED;
        visuals.widgets.inactive.fg_stroke.color = Color32::BLACK;
        visuals.widgets.inactive.rounding = 1.0.into();

        visuals.widgets.hovered.bg_fill = Color32::WHITE;
        visuals.widgets.hovered.bg_stroke.color = Color32::RED;
        visuals.widgets.hovered.fg_stroke.color = Color32::BLACK;
        visuals.widgets.hovered.rounding = 1.0.into();

        let mut style = (*ctx.style()).clone();
        style.text_styles = [(Button, FontId::new(25.0, Monospace))].into();
        ctx.set_style(style);
        ctx.set_visuals(visuals);
        egui::CentralPanel::default().show(ctx, |ui| ui.button("click me!"));
    }
}

@steventrouble Hi, please try this.

@steventrouble
Copy link
Contributor Author

steventrouble commented Oct 7, 2022

All of those together fix it, but when I lower the font size the text becomes grey again.

All of the above:
image

With the font back to normal:
image

Is this an issue with font aliasing? Any way I can turn that off or tweak the antialiasing method?

@emilk
Copy link
Owner

emilk commented Oct 7, 2022

@steventrouble please try latest master - I recently improved text rendering in #2071

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

3 participants