`Id::new` and `From<&str> for Id` etc are foot-guns: they hide the fact
that an `Id` MUST be globally unique (well, at least unique within your
app).
So this PR removes both and replaces them with `Id::unique`, which is
very explicit.
In places where non-uniqueness is desired, you can use `IdSalt`, which
has the convenient `From<&str>`.
Most changes are in tests.
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
Migration guide for the changelog:
`ViewportCommand::Screenshot` was changed to be callback based.
Previously you needed to iter the input events to check for the
screenshot (but didn't need interior mutability):
```rs
[derive(Default)]
struct MyApp {
screenshot: Option<Arc<egui::ColorImage>>,
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
if ui.button("Screenshot").clicked() {
ui.send_viewport_cmd(ViewportCommand::Screenshot(UserData::default()));
}
let image = ui.input(|i| {
i.events
.iter()
.filter_map(|e| {
if let egui::Event::Screenshot { image, .. } = e {
Some(Arc::clone(image))
} else {
None
}
})
.next_back()
});
if let Some(image) = image {
self.screenshot = Some(image);
}
}
}
```
Now you need to use a mutex, channel, or some other sync primitive to
get the result:
```rs
#[derive(Default)]
struct MyApp {
screenshot: Arc<Mutex<Option<Arc<egui::ColorImage>>>>,
}
impl eframe::App for MyApp {
fn ui(&mut self, ui: &mut egui::Ui, _frame: &mut eframe::Frame) {
if ui.button("Screenshot").clicked() {
let ctx = ui.ctx().clone();
let screenshot_mutex = self.screenshot.clone();
ui.request_screenshot(move |screenshot| {
screenshot_mutex.lock().replace(screenshot);
ctx.request_repaint();
});
}
}
}
```
----
This implements a callback-based screenshot api for egui
Upsides over `ViewportCommand::Screenshot`:
- More convenient api: `ctx.request_screenshot(|screnshot| ...)` (and no
need to downcast UserData)
- Reading screenshot data doesn't require rendering another frame
- Should allow us to add recording as a plugin without special hooks in
egui_kittest (otherwise capturing the last frame would have required
custom hooks in kittest)
- This was also a problem in
[kittest_inspector](https://github.com/rerun-io/kittest_inspector): When
streaming a real app, the frame seen was always a couple frames behind
when the app was idle
Lets you control which keys a `TextEdit` captures while it has focus,
instead of letting egui use them for focus navigation. Needed e.g. for a
completion popup, where Tab and Escape should act on the popup rather
than move focus away.
Split out from:
* https://github.com/emilk/egui/pull/8529
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Allows one to do custom painting in places where reading the
`AtomLayoutResponse` may be hard or impossible.
Also very useful when combined with `AtomKind::Closure`
Closes#8478.
Editing the alpha `DragValue` rebuilt the full HSVA color from the
displayed RGBA values, which could re-quantize RGB. This tracks RGB and
alpha edits separately so alpha-only edits preserve RGB.
Adds regression coverage for gamma-byte and linear numeric color spaces.
- [x] I have followed the instructions in the PR template
Disclosure - AI written PR with GPT 6
I was unable to compile for wasm on my project because I use egui-winnit
instead of eframe
See AI explanation below:
## Summary
* Fixes#8436
`egui-winit` unconditionally compiled `NativeFile`, which implements
`DroppedFile::bytes()`. On wasm32, the trait requires `bytes_async()`
instead, causing compilation to fail.
This change gates the native file implementation and its usage to native
targets. An explicit wasm fallback ignores dropped-file events, which
winit’s web backend does not emit.
Adds a direct wasm compilation check to CI and the local check script,
since eframe’s wasm builds do not compile egui-winit.
## Validation
- wasm32 compilation with default features disabled passes.
- Native Linux/X11 compilation passes.
- Formatting and shell syntax checks pass.
- Strict wasm Clippy encounters six existing, unrelated warnings in
clipboard.rs.
The `Run tests` job takes 9-12 minutes because it finds no cargo cache
and rebuilds all 390 crates; the last run that hit the cache took 4m20s
for the whole job. The repository holds 30 caches totalling 10.6 GB,
over the 10 GB limit, so entries are evicted constantly. Each PR saves
its own ~2.5 GB copy of every job cache, which pushes out the `main`
cache that every new PR starts from.
* `on: [push, pull_request]` ran the whole workflow twice for a PR from
a branch in this repo, doubling both runner time and cache writes. The
push half now only runs for `main`.
* Only `main` writes to the cargo cache (`save-if`). PRs still read it.
* New workflow deletes the caches of a PR when it is closed.
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Updated: `enum-map` 3.1, `env_logger` 0.11.11, `font-types` 0.12.4,
`image` 0.25.10, `log` 0.4.34, `smallvec` 1.16, `webbrowser` 1.2.4, plus
transitive bumps.
`syn` is now allowed to be duplicated in `deny.toml`: the ecosystem is
migrating from syn 2 to syn 3, and syn is build-time only, so the
duplicate costs compile time, not binary size. That unblocks `enum-map`
3.1, `serde` 1.0.229 and `thiserror` 2.0.20.
Held back (comments in `Cargo.toml` explain why): `accesskit*` (kittest
0.4), `glow` (wgpu 30), `harfrust`/`skrifa` (fontique, glifo), `resvg`
(tiny-skia via winit), `smithay-clipboard` (winit), `wasm-bindgen`
family.
* [x] I have followed the instructions in the PR template
🤖 Generated with [Claude Code](https://claude.com/claude-code)
`Font<'a>` was a hand-rolled split borrow of every field of `FontsImpl`,
and it grew a new `&'a mut` for each new feature. `text_layout` now
calls `FontsImpl` directly (`resolve_face`, `glyph_info`,
`allocate_glyph`, `rasterize_cluster`, …) with a cheap `FamilyKey` index
instead of re-hashing the `FontFamily` per glyph.
`font.rs` is renamed to `font_face.rs`, since only `FontFace` is left in
it. `FontsView::characters` replaces `f.fonts.font(family).characters()`
in the font book demo.
`FontsImpl` and `epaint::text::layout` are now crate-private: nothing
outside `epaint` used them, and `Fonts` / `FontsView` cover the public
API. The `fonts` fields of `Fonts` and `FontsView` are private too. The
benchmark that used `layout` directly now calls the new
`Fonts::layout_uncached`.
* [x] I have followed the instructions in the PR template
PR chain, in order:
* #8490
* #8500
* #8501
* #8502
* #8503
* #8504
* #8491
* #8492
* #8493
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
`Family::resolve` is now the only place that decides which face renders
a char: it walks the chain, consults the per-char cache, and falls back
to the replacement face. `Font` no longer reaches into the family's
fields. Asking font providers (#8491) for a missing char becomes one
more branch in `Family::resolve`.
* [x] I have followed the instructions in the PR template
PR chain, in order:
* #8490
* #8500
* #8501
* #8502
* #8503
* #8504
* #8491
* #8492
* #8493
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
`FaceStore` wraps the old `fonts_by_id` and `fonts_by_name` maps and
owns `FontFaceKey`. It has a single `install(name, &FontData)` so fonts
from `FontDefinitions` and fonts found later by a font provider (#8491)
go through the same code.
* [x] I have followed the instructions in the PR template
PR chain, in order:
* #8490
* #8500
* #8501
* #8502
* #8503
* #8504
* #8491
* #8492
* #8493
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
`global_theme_preference_switch` can only toggle between dark and light
mode, with no way back to following the system theme.
`global_theme_preference_buttons` covers all three, and now uses compact
icon-only buttons (💻🌙 ☀), so it fits in a top bar too. The demo app now
uses it.
* Rename `ThemePreference::radio_buttons` to `ThemePreference::buttons`
(old name deprecated)
* Add `ThemePreference::icon` and `ThemePreference::name`
* [x] I have followed the instructions in the PR template
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Run the tests with `--no-fail-fast`, in CI and in `scripts/check.sh`.
`cargo test` stops after the first failing test target, so one failing
snapshot test in `egui_demo_app` hid the failing snapshots of every
later crate, and it took several CI rounds to collect all the new
snapshots. Now one run reports them all and uploads all `.new.png`
files, so one kitdiff pass is enough.
`egui_kittest` already collects all snapshot errors of a test in one
`SnapshotResults` and only panics when it is dropped, so no change is
needed there.
* [x] I have followed the instructions in the PR template
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
`GlyphAtlas` owns the `TextureAtlas` plus every cache that points into
it (outline glyphs keyed by face, and platform-rasterized glyphs).
`FontFace` no longer knows about the atlas: it just renders an outline
to a bitmap.
When the atlas gets full, `Fonts::begin_pass` now clears the bitmaps
instead of reparsing and re-hinting every font face. That also removes
the duplicated `glyph_rasterizer` field on `Fonts`, which only existed
to survive the rebuild. Fonts found by font providers (#8491) will
survive an atlas clear the same way.
* [x] I have followed the instructions in the PR template
PR chain, in order:
* #8490
* #8500
* #8501
* #8502
* #8503
* #8504
* #8491
* #8492
* #8493
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Pure move, no logic changes. First step of a chain that untangles
`Font`, `FontsImpl`, and `CachedFamily` ahead of font providers (#8491).
New files under `crates/epaint/src/text/`: `font_id.rs`, `font_data.rs`,
`font_tweak.rs`, `font_definitions.rs`, `glyph_rasterizer.rs`,
`galley_cache.rs`, `styled_metrics.rs`, `unicode.rs`.
* [x] I have followed the instructions in the PR template
PR chain, in order:
* #8490
* #8500
* #8501
* #8502
* #8503
* #8504
* #8491
* #8492
* #8493
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Some applications / test depend on specific gpu state and may be doing
gpu-readback. This adds a `always_render` flag, which calls `render`
every frame so that the gpu dependent logic will work correctly.
It also saves the last render result so we don't have to render the same
frame twice.
* Closes <https://github.com/emilk/egui/issues/7870>
* [x] I have followed the instructions in the PR template
`WidgetRect` derives `PartialEq`, so a rect with a NaN coordinate is not
equal even to itself, and `close.iter().position(|w| *w ==
hit_click).unwrap()` panicked. We now look the hit up by id.
NaN rects got that far because `Rect::intersect` scrubs NaNs
(`f32::max(NAN, x) == x`), so `interact_rect` can be finite while `rect`
is not, sneaking past the existing NaN guard. Hit-testing now discards
those widgets too.
Finally, `Pos2` claims `Eq` while NaN breaks reflexivity, so `PartialEq`
is now hand-written and panics on NaN in debug builds.
<!--
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!
* Keep PR description short and to the point! No long LLM slop.
* 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 a human has reviewed it
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
animate_value_with_time returned the previous value for one frame when
called with a zero duration because it calculated the current value
before updating the animation target.
Handle zero-duration animations before interpolation so they immediately
return and store the target value. Add a regression test covering
consecutive target changes.
* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
* [x] I have followed the instructions in the PR template
Signed-off-by: cuishuang <imcusg@gmail.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Implements `StyleProvider` for `TextEdit`, so you can fully style it as
you please
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Extracts a shared struct with things that once might want to override
for any atomlayout-based widget.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Adds `egui::Event::PasteImage`, emitted on Ctrl+V/Cmd+V when the
clipboard holds an
image with no usable text representation (mirrors
`OutputCommand::CopyImage` for
the opposite direction). `egui-winit::Clipboard` gains `get_image()`,
backed by
`arboard::Clipboard::get_image()` — the symmetric counterpart to the
`set_image()`
already used for copy. Wired in the winit keyboard-shortcut path and in
both the
glow and wgpu eframe backends' AccessKit-driven paste action.
Straight (unmultiplied) alpha from the OS clipboard is converted via the
existing
`ColorImage::from_rgba_unmultiplied` helper rather than reinterpreting
bytes
directly, since the two aren't bit-compatible for translucent pixels.
Not covered here: the web (wasm32) target — browser clipboard image
reads are
inherently async (`Blob::array_buffer` returns a Promise), while
`Event::PasteImage`
as designed here carries an already-decoded `ColorImage`. Bridging that
needs
either an async event payload or a deferred/queued event on `AppRunner`
— more of
a design decision than a small mirrored addition, flagging it rather
than guessing.
* Related: #2108 (not fixed: web)
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
TextEdit has a min_size field but we completely ignored in the y
direciton. (I probably broke it in #7140).
---------
Co-authored-by: emilk <1148717+emilk@users.noreply.github.com>
Moves global classnames to e.g. `egui::class::ROOT`.
Widget specific classes live on the widgets struct.
Adds some more classes for our buttons styling options (`CLASS_SMALL`
etc), so that custom `StyleProvider`s can choose to implement them
differently or ignore them altogether.
Also removes some styleproviders that were partly or completely unused
(e.g. basestyle / labelstyle). We can add them back once we actually
implement styling for those.
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This happens because `bg_stroke`'s width isn't constant.
| Before | After |
|--------|--------|
| <img width="320" height="320" alt="before"
src="https://github.com/user-attachments/assets/0101e5fb-0781-4867-9891-c91d49dbb969"
/> | <img width="320" height="320" alt="after"
src="https://github.com/user-attachments/assets/4223218a-2f5f-4542-9fe2-67be5799ca81"
/> |
---
<!--
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!
* Keep PR description short and to the point! No long LLM slop.
* 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 a human has reviewed it
* When you have addressed a PR comment, mark it as resolved.
Please be patient! I will review your PR, but my time is limited!
-->
* [x] I have followed the instructions in the PR template
This allows you to see how many more steps it would have taken for the
harness to settle.
Useful to see if you're in a infinite repaint loop or just need a
`harness.run_steps(3)` to give it some more frames to settle.
Should make it easier to make the default step count tighter, which
should make tests faster.
<!--
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!
-->
`constrain_to` overrides `constrain`, so I adjusted it to call
`constrain_to` before `constrain`.
* [x] I have followed the instructions in the PR template
Signed-off-by: limo520 <247564335@qq.com>
The Egui web example was throwing an error in WGPU. In this case, the
error was
```
panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wgpu-30.0.0/src/backend/wgpu_core.rs:1414:26: wgpu error: Validation Error Caused by: In Device::create_render_pipeline, label = ‘egui_pipeline’ In the provided shader, the type given for group 1 binding 2 has a size of 4. Since the device does not support DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED`, the type must have a size that is a multiple of 16 bytes
```
One reference I used was the following Pull Request:
<https://github.com/viridia/quill/pull/14>
The biggest change I made was in `egui-wgpu` to
`r_tex_nearest_filtering`
Shader (`egui.wgsl`)
```wgsl
// Old
@group(1) @binding(2) var<uniform> r_tex_nearest_filtering: u32;
// New
@group(1) @binding(2) var<uniform> r_tex_nearest_filtering: vec4<u32>;
```
And with the corresponding changes in `renderer.rs`, I ran it locally
and it worked perfectly in Firefox 149 and Chromium 151 (Both fail when
attempting to access https://www.egui.rs/#demo, returning the error
described above)
* Closes <https://github.com/emilk/egui/issues/8446>
* Fixes <https://github.com/emilk/egui/issues/8446>
* [X] I have followed the instructions in the PR template
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Fix a build issue in the `egui-wgpu` crate when building for the
`wasm32-unknown-emscripten` target. WGPU does not support the WebGPU
backend on that target.
## Problem
`ViewportBuilder::with_monitor(idx)` is a **no-op on the glow backend**.
A window
built with `.with_monitor(...)` opens on the default monitor, not
fullscreen —
while the exact same code works on wgpu.
The monitor → `Fullscreen::Borderless(Some(monitor))` resolution only
lives in
`egui_winit::create_window`, which the **wgpu** backend uses. The
**glow**
backend builds its windows straight from
`egui_winit::create_winit_window_attributes`
at two sites in `glow_integration.rs` — the initial window and
per-viewport
deferred windows — so the monitor is never applied there.
## Repro
A multi-viewport app on the glow renderer with any viewport built via
`ViewportBuilder::default().with_monitor(1)` opens that window on
monitor 0,
un-fullscreen. Switching to the wgpu renderer places it correctly. Seen
on a
3-monitor GNOME/Wayland setup where the main window and secondary
viewports all
need to land borderless-fullscreen on specific outputs.
## Fix
Extract the resolution into a public
`apply_monitor_to_window_attributes` in
`egui-winit` and call it from `create_window` (unchanged behaviour) plus
both
glow window-creation sites, so `with_monitor` behaves the same on glow
and wgpu.
No public API change beyond the new helper; no behaviour change on wgpu.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Fix transparent child viewports on `Windows` with `glow`
* Closes#3632
* Related #4451
* Related #5072
* Closes#7543
* Related #8116
Transparent native child viewports could become opaque on Windows when
the
selected GL config reports that it does not support transparency.
`glutin_winit::finalize_window` clears the native transparent window
attribute
in that case. However, on affected Windows GL paths, transparent native
windows
and their GL surfaces still composite correctly.
This change preserves the transparent window attribute for explicitly
transparent non-root viewports on Windows by creating those windows
directly.
Tested manually on Windows with glow:
- root transparent viewport
- deferred native child viewport
- immediate native child viewport
<!--
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>
So I first noticed that this function was using a large lookup table
behind a OnceLock. I initially thought about just making it a const, but
when looking at things further. I realized it could be made much
simpler.
If we just treated the numbers as fixed point we can get rid of any of
the floating point calculations and especially divisions. You can see
how efficiently this can compile down here:
https://llvm.godbolt.org/z/K83jEjvdq
You can see all three versions here: https://godbolt.org/z/nWc1as1nq
* First one is basically the original essentially being called by:
`ColorImage::from_rgba_unmultiplied()`
* Second is the const Lookup table instead of the OnceLock and runtime
generation.
* Third is the fixed point implementation.
At least looking at the bytes reported compiler explorer the OnceLock
and the const Table results are in similar size, and the const table is
surprisingly smaller when I compile to a binary object in compiler
explorer. However though the oncelock is producing a lot SIMD
instructions for initialization so I guess not too surprised. The fixed
point math is much smaller than both.
The const table is probably faster, but does bloat the binary images,
and again when it's this fast to compute:
https://llvm.godbolt.org/z/K83jEjvdq I am not sure the extra bytes are
worth it.
Next, what I did was merge `from_rgba_unmultiplied` and
`from_rgba_unmultiplied_const`. Moreover with the fixed point math the
`from_rgba_unmultiplied_const` is probably not necessary anymore, but
it's part of the public API so I left it. Lastly, I just added a sanity
test to make sure the math checks out which it does. You can even sweep
the 2^16 inputs to be sure.