Setting override_text_color, font sizes in run_native() does not work on Windows
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 72
Description
**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.size`s 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**
```rust
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);
}
}
```
Contributor guide
Research direction
Start by reproducing the issue with the shown eframe::run_native app_creator callback on Windows, then compare the style state there with the state after the update workaround. Trace when cc.egui_ctx style changes are applied relative to app creation and the first update. Done means override_text_color and text_styles font sizes set in the callback take effect on Windows without requiring update-time mutation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- desktop, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100