emilk / egui

egui: an easy-to-use immediate mode GUI in Rust that runs on both web and native
https://www.egui.rs/
Apache License 2.0
22.04k stars 1.59k forks source link

egui not respecting text color #2005

Open steventrouble opened 2 years ago

steventrouble commented 2 years ago

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:

goldwind-ting commented 2 years ago
#![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 commented 2 years ago

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 commented 2 years ago

@steventrouble please try latest master - I recently improved text rendering in https://github.com/emilk/egui/pull/2071