1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Theme plugin system (experimental) (#8153)

<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md)
before opening a Pull Request!

* Keep your PR:s small and focused.
* The PR title is what ends up in the changelog, so make it descriptive!
* If applicable, add a screenshot or gif.
* If it is a non-trivial addition, consider adding a demo for it to
`egui_demo_lib`, or a new example.
* Do NOT open PR:s from your `master` branch, as that makes it hard for
maintainers to test and add commits to your PR.
* Remember to run `cargo fmt` and `cargo clippy`.
* Open the PR as a draft until you have self-reviewed it and run
`./scripts/check.sh`.
* When you have addressed a PR comment, mark it as resolved.

Please be patient! I will review your PR, but my time is limited!
-->

# What it does

Addition of a new system of theme plugins which allow the user to use
different rules engine to compute the style for the available
specialised widget style.

# How to use

Create a engine implementing the trait `ThemePlugin` and `ThemeStyle<S:
StyleStruct>` and implement the necessary methods, then register this
way (example for `ButtonStyle`):
```ui.add_theme::<ButtonStyle>(&mycustomengine);```

Now all button will call the `ThemeStyle<ButtonStyle>` method to compute the correct style and later use the cached value to avoid the costly computation.

If no valid `ThemeStyle<S>` or engine is available then it fallback to the default style.

* Closes part of <https://github.com/emilk/egui/issues/3284>
* [x] I have followed the instructions in the PR template

---------

Co-authored-by: adrien <221212@umons.ac.be>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
This commit is contained in:
YouStones
2026-08-21 15:05:45 +02:00
committed by GitHub
parent f5c9373e26
commit 97603fc082
21 changed files with 857 additions and 336 deletions

View File

@@ -10,7 +10,7 @@ version.workspace = true
ignored = ["image"] # We need the png feature
[dev-dependencies]
egui = { workspace = true, default-features = true }
egui = { workspace = true, default-features = true, features = ["experimental"] }
egui_kittest = { workspace = true, features = ["snapshot", "wgpu"] }
egui_extras = { workspace = true, features = ["image"] }
image = { workspace = true, features = ["png"] }

View File

@@ -1,5 +1,7 @@
use egui::{
Align, Atom, AtomExt as _, AtomLayout, Button, Direction, Frame, Layout, TextWrapMode, Ui, Vec2,
Align, Atom, AtomExt as _, AtomLayout, Button, Direction, Frame, Layout, TextWrapMode, Ui,
Vec2,
widget_style::{ButtonStyle, StyleArgs},
};
use egui_kittest::{HarnessBuilder, SnapshotResult, SnapshotResults};
@@ -129,11 +131,14 @@ fn test_atom_layout_nesting_and_direction() {
let style = ui.style();
let canvas_frame = Frame::canvas(style);
let button_frame = style
.button_style(
&egui::widget_style::Classes::default(),
egui::widget_style::WidgetState::Inactive,
)
let button_frame = ui
.get_widget_style::<ButtonStyle>(&StyleArgs {
classes: &egui::widget_style::Classes::default(),
state: egui::widget_style::WidgetState::Inactive,
ctx: ui,
stack: ui.stack(),
style,
})
.frame;
let row = |direction: Direction| {