emilk / emilk/egui

[REGRESSION] in visuals scoping: ui.set_visuals affects entire app since v0.34.1

Open
#8,074 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

### Describe the bug
After upgrading to egui 0.34.1, I am unable to maintain two different visual styles (e.g., a blue sidebar and a white main panel) within the same frame. Even when wrapping the style changes inside a ui.scope or ui.child_ui, the last call to a visuals-changing function seems to "leak" or override the global context, causing the entire application to adopt the last defined style.

In previous versions, I could successfully isolate these styles.

### To Reproduce
I am using a pattern similar to this but separated in different modules `mainpanel.rs` and `menu.rs` (called in order `menu.rs` first and `mainpanel.rs` as last) in the 0.34.1:
```rust
// Sidebar with blue background
egui::Panel::left("side_panel").show_inside(ui, |ui| {
ui.scope(|ui| {
// UiVisuals is a module that provide a built and personalized egui::Visuals Struct
ui.set_visuals(UiVisuals::panel_visuals());
ui.label("This should be on a blue background");
});
});

// Main content with white background
egui::CentralPanel::default().show_inside(ui, |ui| {
ui.scope(|ui| {
ui.set_visuals(UiVisuals::default_visuals());
ui.label("This should be on a white background");
});
});
```

and I was using this method in 0.33.3, although the set visual is outside the designated UI I was still able to isolate the color change to the panel I wanted:
```rust
// Sidebar with blue background
// UiVisuals is a module that provide a built and personalized egui::Visuals Struct
ctx.set_visuals(UiVisuals::panel_visuals());
egui::SidePanel::left("side_panel").show(ctx, |ui| {
ui.label("This should be on a blue background");
});

// Main content with white background
ctx.set_visuals(UiVisuals::default_visuals());
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("This should be on a white background");
});
```

### Expected behavior
The SidePanel should remain blue and the CentralPanel should remain white. Instead, the entire app (including the sidebar) turns white because the CentralPanel logic runs last.

### Environment

egui version: 0.34.1

Platform: WASM

OS: Linux NixOS

### Additional context
It seems that ui.style_mut().visuals or ctx.set_visuals() is no longer strictly scoped when called inside panels or scopes, or there is a conflict in how panel_fill is inherited during the layout pass.

Contributor guide

Open the contributing guide

Research direction

Reproduce the regression in the 0.34.1 pattern using the modules named mainpanel.rs and menu.rs, then inspect how ui.set_visuals, ui.scope, ui.child_ui, and panel_fill interact during layout. Done means the SidePanel stays blue while the CentralPanel stays white, without the later CentralPanel style changing the whole app.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, wasm
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.