`ColorImage` fields are now private. Use `resolution()`, `pixels()`,
`pixels_mut()`, and `source_size()` instead.
Also renames `size` to `resolution` in several texture-related APIs
(`ImageData`, `TextureHandle`, `TextureMeta`, `TextureAtlas`,
`Fonts::font_image_resolution`).
`ColorImage::new` now panics if `width * height != pixels.len()`.
## Motivation
A) Make `ColorImage` always valid
B) Stop confusing using the confusing word `size` where `resolution` is
better
Improes non-`syntect` highlighter in `egui_extras::syntax_highlighting`.
* `TokenType` is now public, with new `CodeTheme::format` and
`CodeTheme::format_mut`, so apps can match the colors to their own theme
* New `TokenType::Function`: an identifier directly followed by `(`
* `/* block comments */` for C, C++, JavaScript, JSON and Rust
* Backslash escapes in strings, so `"say \"hi\""` is one string
* `'single'`, `"""triple"""` and `'''triple'''` strings in Python and
TOML, `'char'` literals in C/C++, and `` `template` `` strings in
JavaScript
* New languages: JavaScript/TypeScript, shell (bash, sh, zsh) and YAML
* `jsonc` and `json5` are now highlighted as JSON
The demo snapshots are rendered with `--all-features`, which uses
`syntect`, so they are unaffected.
The new `egui_extras/tests/syntax_highlighting.rs` snapshot test covers
the fallback highlighter, run by a new CI step without `syntect`.
* [x] I have followed the instructions in the PR template
This PR was written by Claude Code (an LLM) on behalf of @emilk, and
needs a human review before leaving draft.
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* Part of https://github.com/emilk/egui/issues/5735
Enables the `clippy::std_instead_of_alloc` lint in `egui`, `emath`,
`epaint`, `ecolor`, `epaint_default_fonts` and `egui_extras`, and fixes
all the warnings (`std::sync::Arc` → `alloc::sync::Arc`, etc). Each
crate gets `extern crate alloc;` where needed.
This is enabled per-crate (via `#![warn(…)]` in `lib.rs`) rather than
workspace-wide, to avoid sprinkling `extern crate alloc;` across every
example and test.
The non-`syntect` fallback highlighter in `egui_extras` now supports SQL
(`"sql"`):
* `-- line comments`
* `'single-quoted'` strings
* Case-insensitive keywords (`SELECT`, `select`, …)
Also: `_` is now treated as part of a word for all languages, so
identifiers like `order_id` (SQL) or `self_ref` (Rust) no longer get a
keyword highlighted inside them.
Snapshot test in `egui_demo_lib/tests/misc.rs` renders SQL with both
backends (`sql_fallback_*` / `sql_syntect_*`). Note: CI runs
`--all-features`, so only the syntect snapshots are checked there; the
fallback ones are checked by `cargo test -p egui_demo_lib`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Currently `ImageCrateLoader` spawns threads to load every image, while
`WebPLoader` doesn't.
This is particularly bad since the webp loader is used for animations,
which take longer than normal images and can *really* stall the app on
load.
* Related to <https://github.com/emilk/egui/issues/5375>
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
`FileLoader` strips the `file://` prefix but does not percent-decode the
path,
so a `file://` URI with an escape such as `%20` fails to resolve on disk
(the
function's own doc noted "percent un-encoding are not handled").
`convert_uri_to_path` now decodes `%XX` escapes (e.g. `%20` -> space)
after
stripping the scheme, using a small inline decoder so no dependency is
added.
Invalid or truncated escapes are left as-is, and UTF-8 multibyte
sequences round
-trip. Added `%20` cases to the existing `check_convert_uri_to_path`
test for
both the Windows and non-Windows paths.
`cargo test`, `clippy`, and `fmt` pass for `egui_extras`.
Closes#8288
---------
Signed-off-by: 林晨 (Leo Cheng) <leo-cheng@vip.qq.com>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
<!--
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!
-->
* Closes <https://github.com/emilk/egui/issues/8546>
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
## Summary
Clipped table cells no longer contribute their overflowing content to a
sizing pass. Refresh non-resizable column widths during sizing so
clipped and truncated labels use the narrower available width when a
window is resized. Preserve minimum sizing for unclipped content and
full content measurements for column auto-sizing.
Fixes#8408.
## Testing
- Added sizing and window-drag regressions for exact, remainder, and
automatic columns and both strip directions, including unclipped and
explicitly truncated labels.
- Inspected headless wgpu renders during resizing; clipped/truncated
text and adjacent buttons remain correctly laid out.
- `cargo test --locked -p egui_extras -p egui --all-features --features
image/png,image/jpeg`
- `cargo clippy --locked -p egui_extras -p egui --all-targets
--all-features -- -D warnings`
- `cargo fmt --all --check`
- `python -X utf8 scripts/lint.py`
- [x] I have followed the instructions in the PR template
Closes#8092.
Related to #8084.
Virtualized tables could shift the parent UI's automatic ID sequence
between sizing and rendering passes.
`StripLayout::skip_space` represented non-visible rows using
`allocate_rect(..., Sense::hover())`. This preserved the scroll extent,
but also registered a hover widget and consumed an automatic widget ID.
When virtual buffers differed between passes, subsequent table widget
IDs changed and triggered warnings such as:
> Widget rect changed id between passes
Multi-pass and data-driven layouts can also legitimately move existing
widgets into vacated rects or intentionally replace all widgets within a
region. These cases could produce the same warning even though the
widget IDs were stable or the replacement was intentional.
This PR:
- uses `expand_to_include_rect` for virtual row buffers, preserving the
scroll extent without registering a widget or consuming an automatic ID;
- assigns deterministic IDs to table header, body, and cell UIs;
- avoids warnings when an existing widget moves into a rect vacated
during the previous pass, while retaining warnings for genuinely new IDs
replacing widgets in place;
- adds `Context::allow_widget_id_changes_in` as a pass-local,
rect-scoped exclusion for regions that intentionally replace their
widget set;
- adds regression coverage for virtual spacer extent, automatic ID
preservation, moved widgets, genuine replacements, and scoped
exclusions.
There are no intended visual changes. The only public API change is
`Context::allow_widget_id_changes_in`, which affects this diagnostic
only; it does not change duplicate-ID checks or widget interaction.
### Testing
Verified locally with Rust 1.95.0:
- `cargo fmt --all -- --check`
- `python3 scripts/lint.py`
- `RUSTFLAGS="-D warnings" RUSTDOCFLAGS="-D warnings" cargo test -p egui
-p egui_extras --all-features --features image/png,image/jpeg --locked`
- `RUSTFLAGS="-D warnings" cargo clippy -p egui -p egui_extras
--all-targets --all-features --locked -- -D warnings`
- `RUSTFLAGS="-D warnings" cargo clippy -p egui -p egui_extras
--all-targets --all-features --release --locked -- -D warnings`
87 unit tests and 193 doc-tests passed; one existing doc-test is
ignored. The test command explicitly enables PNG/JPEG codecs required by
the image-loader fixtures.
Screenshots are not applicable because these changes do not affect
visual output.
---------
Co-authored-by: lucasmerlin <hi@lucasmerlin.me>
Co-authored-by: wfp-codex-bot <wfp-codex-bot@vlans.co>
<!--
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!
-->
* [x] I have followed the instructions in the PR template
SVG supports inlining raster images (PNG/JPEG), `egui-extras` as it
stands does not support this.
`resvg` has a feature for this, it's just a matter of enabling it, this
PR adds an `egui-extras` feature `svg_images` doing exactly that.
---------
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
`egui_extras`' built-in highlighter (used when the `syntect` feature is
off, e.g. by `egui_commonmark` without `better_syntax_highlighting`) now
highlights `json` code blocks: strings, numbers, and the
`true`/`false`/`null` keywords.
This came up in the Rerun Viewer's agent panel, where JSON code blocks
rendered as plain text.
* [x] I have followed the instructions in the PR template
🤖 This PR was written by Claude, an LLM, on behalf of @emilk.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`Context::add_glyph_rasterizer` appended a rasterizer and requested a
repaint on every call. Calling it from a setup path that runs each frame
piled up duplicates and kept the UI repainting forever (we hit this in
rerun's tests, where `apply_style_and_install_loaders` runs every frame
and the harness never settled).
* `GlyphRasterizer::new` now takes a mandatory `key`: adding a
rasterizer whose key is already installed is a no-op.
* `Context`/`Fonts`/`FontsImpl::add_glyph_rasterizer` only reload fonts,
clear caches and request a repaint when something actually changed.
`Fonts::add_glyph_rasterizer` returns whether it did.
* `SvgGlyph::into_rasterizer` is keyed by cluster, the web canvas
rasterizer by a fixed name.
Written by an LLM (Claude) together with @emilk.
* [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>
`Ui::id` was easy to confuse with `Ui::unique_id`. It is the id of the
_scope_ the `Ui` belongs to: stable across frames, shared by sibling
`Ui`s, and the base for widget state ids. `Ui::unique_id` is unique per
`Ui` but unstable.
This renames `Ui::id` to `Ui::scope_id` (old name deprecated) and
rewrites both docstrings to say so.
Follow-up to discussion in:
* https://github.com/emilk/egui/pull/8534#discussion_r3969041538
* [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>
`GlyphRasterizer` now has a `FontPriority`:
* `FontPriority::Highest`: asked about every cluster, before any font.
Use it to override how specific glyphs looks
* `FontPriority::Lowest` (default): a fallback, only asked about
clusters no installed font (or `FontProvider`) has. Same as before.
Several rasterizers can be installed; within a tier they are asked in
order, and the first `Some` wins.
```rust
ctx.add_glyph_rasterizer(
egui::GlyphRasterizer::new(|request| (request.cluster == "…").then(|| my_ellipsis(request)))
.with_priority(egui::FontPriority::Highest),
);
```
API changes (all unreleased): `Context::set_glyph_rasterizer(Option)` →
`add_glyph_rasterizer` / `set_glyph_rasterizers(Vec)`, same on
`epaint::Fonts`.
Follow-up to:
* https://github.com/emilk/egui/pull/8512
* [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>
`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>
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)
Two small documentation typos noticed while reading the docs:
- `crates/egui_extras/README.md`: "adds some features on top top of" ->
"adds some features on top of"
- `README.md`: "check out the [the egui web demo]" -> "check out [the
egui web demo]" (removes the duplicated "the"; link text and target
unchanged)
Documentation only; no code changes.
Instead of opting in to pedantic lints one by one, enable the whole
group and opt out of the noisy ones.
64% of the pedantic lints were already listed individually. This deletes
90 explicit lint lines, enables 51 pedantic lints we never listed, and
picks up new pedantic lints for free. Each opt-out carries its hit
count, so the cost of turning one back on is visible.
`restriction` and `nursery` stay opt-in per lint.
Stacked on top of #8430, which fixes the one real bug the new lints
found.
* [x] I have followed the instructions in the PR template
---------
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
`image.PNG` and `cat.SVG` were not recognized as images.
Adds `egui::load::has_extension(uri, extension)`, which ignores ASCII
case and any `#fragment`, and uses it for the `.svg`, `.gif`, `.webp`
and `.png` checks.
Note: gif/webp URIs like `a#b.gif` no longer match, since the fragment
is now excluded.
* [x] I have followed the instructions in the PR template
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
* Closes https://github.com/emilk/egui/issues/5605
It has been zero by default for a few months now, and I do not wish to
support it. It was always an ugly hack, and it is no longer needed.
This is a bit like my previous pr
(<https://github.com/emilk/egui/pull/8037>), but addresses the final bit
of 64 bit atomic dependent code, the svg loader in the `egui_extras`
crate.
As with the previous pr, this improves egui's compatibility on platforms
without 64 bit atomics.
* Closes <https://github.com/emilk/egui/issues/7692>
* [x] I have followed the instructions in the PR template
Less risk of confusing the two.
Found and fix a couple real bugs in the process!
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
### Problem
`Column::remainder().clip(true)` grows correctly when the panel is made
wider, but does not shrink when the panel is made narrower.
### Root cause
There are two places in `table.rs` where the `max_used_widths` floor is
applied to column widths. One correctly checks `column.clip`, the other
doesn't.
**Post-render** path (already correct, line ~827):
```rust
if !column.clip {
*column_width = column_width.at_least(max_used_widths[i]);
}
```
`TableState::load` **pre-render path** (the bug, line 647):
```rust
.at_least(column.width_range.min.max(*max_used)) // clip flag ignored
```
In `TableState::load`, `.at_least(max_used)` is applied to every column
regardless of `clip`. For a `Column::remainder()`, `max_used`
accumulates the historically widest rendered content. When the panel
shrinks, this floor prevents the column from computing a smaller width,
creating a cycle where it can never shrink.
### Fix
Apply the same `clip` guard that already exists in the post-render path:
```rust
.at_least(if column.clip {
column.width_range.min
} else {
column.width_range.min.max(*max_used)
})
```
When `clip = true`, the floor is just `width_range.min` (0.0 by
default), allowing the remainder column to shrink freely to the actual
remaining space.
### Minimal reproduction
<details>
<summary>Show code</summary>
```rust
use eframe::egui;
use egui_extras::{Column, TableBuilder};
fn main() -> eframe::Result {
eframe::run_ui_native(
"Column::remainder().clip(true) shrink test",
Default::default(),
|ui, _frame| {
egui::Frame::central_panel(ui.style()).show(ui, |ui| {
let mut text = String::from("some content");
egui::ScrollArea::horizontal().show(ui, |ui| {
TableBuilder::new(ui)
.column(Column::auto())
.column(Column::remainder().clip(true))
.header(20.0, |mut header| {
header.col(|ui| { ui.strong("Auto"); });
header.col(|ui| { ui.strong("Remainder + clip"); });
})
.body(|mut body| {
body.row(18.0, |mut row| {
row.col(|ui| { ui.label("label"); });
row.col(|ui| {
ui.add(
egui::TextEdit::singleline(&mut text)
.desired_width(f32::INFINITY),
);
});
});
});
});
});
},
)
}
```
</details>
**Without the fix:** make the window wider (column grows ✓), then
narrower — column does not shrink and a horizontal scrollbar appears ✗
https://github.com/user-attachments/assets/2b586588-9f72-4a15-80f4-afddadb69441
**With the fix:** the column shrinks correctly and no scrollbar appears
✓
https://github.com/user-attachments/assets/f1655641-e135-489c-9f59-2af3faa887ab
* Closes <https://github.com/emilk/egui/issues/4491>
* [x] I have followed the instructions in the PR template
Lets you create an `EhttpLoader` with arbitrary headers like so:
```rust
cc.egui_ctx.add_bytes_loader(std::sync::Arc::new(
egui_extras::loaders::http_loader::EhttpLoader::default().with_headers(&[
("User-Agent", "foo"),
])
));
```
I'm not sure if there are any problems with installing a second
`EhttpLoader` (in addition to the one installed by default when using
`egui_extras::install_image_loaders(&cc.egui_ctx)`. But I wasn't
sure how else to pass in configuration options to
`install_image_loaders`.
Current behavior fails when translating file uris that contain windows
UNC paths. This commit attempts to fix that behavior by looking at the
hostname attribute of the uri and changing behavior if the hostname is
present.
* Closes <https://github.com/emilk/egui/issues/8161>
* [x] I have followed the instructions in the PR template
## Related
* https://github.com/emilk/egui/pull/5851
* https://github.com/emilk/egui/pull/7988
## What
We want to make it easier to understand the lineage of a `Id` (which is
the parent `Id`, and the parent of that, etc?)
As a first step of that, we want to clarify the different between a
globally unique `Id`, and an `IdSalt`
I also introduced the `AsId` and `AsIdSalt` traits, which are
implemented of anything that implements `Hash` and `Debug`. The `Debug`
half of that is unused here, but will later be used in `Debug` builds to
produce a proper tree.
* Part of https://github.com/emilk/egui/issues/8180
Drag-to-scroll is a must-have on touch-screens, since there is no other
way to scroll.
However, when you are not on a touch screens, it is more surprising than
useful.
Enable these new clippy lints and fix all warnings:
* `format_push_string` — use `write!` instead of `s += &format!(…)` to
avoid extra allocations
* `ignored_unit_patterns` — use `()` instead of `_` when matching unit
* `missing_fields_in_debug` — ensure manual `Debug` impls account for
all fields
* `needless_raw_string_hashes` — remove unnecessary `r#` on string
literals
* `ref_option` — prefer `Option<&T>` over `&Option<T>` in function
signatures
This PR fundamentally solves the same problem as
https://github.com/emilk/egui/pull/5827 just implemented with a lot less
ambition and api surface on my end. It contains the bare minimum amount
of changes that I need in order to be able to solve my problem.
My Problem:
I am still suffering from the problem that the TypeIdMap blows up over a
very long time when using my application. (The user generally never
turns off the application, it is intended to be just kept running
forever, some users also never restart their computers) My application
generates a lot of content dynamically so it may for some time display
widgets with a certain set of TypeId's + Id's later hiding them. Some of
the elements that were hidden may turn visible again once an external
event occurs, some may forever be discarded.
I do know myself when which sections of the UI have to be purged because
they will never become visible again, so this PR contains the minimum
amount of necessary functions that allow me to implement this
housekeeping logic on my end.
The existing facilities are insufficient to handle this as the type T
which the TypeId and the hash is derived from are sometimes pub(crate)
privates of widget subcrates or even pub(crate) of egui internals
itself, so its impossible to manually remove those from the TypeIdMap
the only build-in method to remove them is to call "clear" on the
TypeIdMap, however that gets rid of everything, even the elements that
are still shown and should still be in the TypeIdMap.
If the changes in this PR are agreeable to you and you want me to write
unit test for the 4 functions that I have added then tell me and I will
write the tests for you.
If you need anything else changed please tell me.
I ran cargo clippy and cargo fmt, but your check.sh does not work on my
computer.
---------
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
## What
Two new builder methods on `DatePickerButton`:
- **`reverse_years(bool)`** — lists years in descending order (newest
first). Useful when users are more likely to pick recent years.
- **`year_scroll_to(i32)`** — scrolls the year dropdown to a specific
year when it first opens, centred in the list. Defaults to the currently
selected year, so the picker no longer opens at the top of a 110-item
list.
## Why
The year `ComboBox` currently always renders in ascending order and
opens scrolled to the top. For a range spanning e.g. 1925–2035, the
current year is buried near the bottom. Users have to scroll past ~100
entries every time they open the picker.
## Notes
- Both options are purely additive builder methods — no breaking
changes.
- `year_scroll_needed` is a persisted state flag that is set on popup
open and cleared after the first scroll, so the user can freely scroll
the list after that.
- Existing behaviour is unchanged when neither method is called.
Co-authored-by: Simon Deurell <simon@deurell.se>
This is a breaking change.
- Enables using `FrameCache` in cases where the cached value cannot be
cloned.
- Improves use cases where only a reference to the cached value is
needed.
- If the user needs an owned value, they can clone it themselves.
Adding a `get_ref` method instead of changing `get` would avoid the
breaking change, but I didn't want to do so because it is kind of
expected for `get` to return `&V` when querying a collection.
Following this MR https://github.com/emilk/egui/pull/7375
Without Syntect, the urrent theme selector is
`global_theme_preference_buttons`. It should be the dark_theme variable
of the local CodeTheme - same as syntect
Tested with
```sh
cargo run
# and
cargo run --features syntect
```
* [x] I have followed the instructions in the PR template
thanks for this amazing library!