Commit Graph

3873 Commits

Author SHA1 Message Date
Nicolas f33ff2c83d
Make `HSVA` derive serde (#7132)
This pull request introduces a change to the `Hsva` struct in the
`crates/ecolor/src/hsva.rs` file to enable serialization and
deserialization when the `serde` feature is enabled.

* Closes <https://github.com/emilk/egui/issues/7131>
* [x] I have followed the instructions in the PR template
2025-06-16 01:40:42 +02:00
ardocrat 742da95bd7
Support for Back button Key on Android (#7073)
When your press a Back button on Android (for example at
`native-activity`), [Winit translates this
key](47b938dbe7/src/platform_impl/android/keycodes.rs (L237C42-L237C53))
as `NamedKey::BrowserBack`. Added convertion to `Key::Escape` at
`egui-winit` module.

---------

Co-authored-by: Advocat <advocat@ogr.local>
2025-06-16 01:28:27 +02:00
Gerhard de Clercq a126be4dc1
Mention VTK 3D integration example (#7086)
This commit adds a reference to an additional 3D integration example
(using the VTK C++ library) to the README.


![Demo](https://github.com/user-attachments/assets/99cbe4e6-0aaf-41c2-9b18-179d58047284)
2025-06-16 01:28:04 +02:00
Lucas Meurer 4c04996a72
Fix missing repaint after `consume_key` (#7134)
Usually input events automatically trigger a repaint. But since
consume_key would remove the event egui would think there were no events
and not trigger a repaint. This fixes it by setting a flag on InputState
on consume_key.

* related: https://github.com/rerun-io/rerun/issues/10165
2025-06-13 14:06:50 +02:00
Lucas Meurer 5bc19f3ca3
Report image alt text as text if widget contains no other text (#7142)
- Same as https://github.com/emilk/egui/pull/7136 but now for atomics
2025-06-13 13:54:07 +02:00
Lucas Meurer 6eb7bb6e08
Add `AtomLayout`, abstracing layouting within widgets (#5830)
Today each widget does its own custom layout, which has some drawbacks:
- not very flexible
- you can add an `Image` to `Button` but it will always be shown on the
left side
  - you can't add a `Image` to a e.g. a `SelectableLabel`
- a lot of duplicated code

This PR introduces `Atoms` and `AtomLayout` which abstracts over "widget
content" and layout within widgets, so it'd be possible to add images /
text / custom rendering (for e.g. the checkbox) to any widget.

A simple custom button implementation is now as easy as this:
```rs
pub struct ALButton<'a> {
    al: AtomicLayout<'a>,
}

impl<'a> ALButton<'a> {
    pub fn new(content: impl IntoAtomics) -> Self {
        Self { al: content.into_atomics() }
    }
}

impl<'a> Widget for ALButton<'a> {
    fn ui(mut self, ui: &mut Ui) -> Response {
        let response = ui.ctx().read_response(ui.next_auto_id());

        let visuals = response.map_or(&ui.style().visuals.widgets.inactive, |response| {
            ui.style().interact(&response)
        });

        self.al.frame = self
            .al
            .frame
            .inner_margin(ui.style().spacing.button_padding)
            .fill(visuals.bg_fill)
            .stroke(visuals.bg_stroke)
            .corner_radius(visuals.corner_radius);

        self.al.show(ui)
    }
}

```

The initial implementation only does very basic layout, just enough to
be able to implement most current egui widgets, so:
- only horizontal layout
- everything is centered
- a single item may grow/shrink based on the available space
- everything can be contained in a Frame


There is a trait `IntoAtoms` that conveniently allows you to construct
`Atoms` from a tuple
```
   ui.button((Image::new("image.png"), "Click me!"))
```
to get a button with image and text.


This PR reimplements three egui widgets based on the new AtomLayout:
 - Button
   - matches the old button pixel-by-pixel
- Button with image is now [properly
aligned](https://github.com/emilk/egui/pull/5830/files#diff-962ce2c68ab50724b01c6b64c683c4067edd9b79fcdcb39a6071021e33ebe772)
in justified layouts
   - selected button style now matches SelecatbleLabel look
- For some reason the DragValue text seems shifted by a pixel almost
everywhere, but I think it's more centered now, yay?
 - Checkbox
- basically pixel-perfect but apparently the check mesh is very slightly
different so I had to update the snapshot
   - somehow needs a bit more space in some snapshot tests?
 - RadioButton
   - pixel-perfect
   - somehow needs a bit more space in some snapshot tests?

I plan on updating TextEdit based on AtomLayout in a separate PR (so
you could use it to add a icon within the textedit frame).
2025-06-13 09:39:52 +02:00
Emil Ernerfeldt f0abce9bb8
`Button` inherits the `alt_text` of the `Image` in it, if any (#7136)
If a `Button` has an `Image` in it (and no text), then the
`Image::alt_text` will be used as the accessibility label for the
button.
2025-06-11 23:00:59 +02:00
Nicolas 9f9153805d
lint: fix lints appearing in rust stable currently (#7118)
* [x] I have followed the instructions in the PR template
2025-06-11 17:38:06 +02:00
Rinde van Lon cfb10a04f5
Improve `ComboBox` doc example (#7116)
Improves the `ComboBox` example with some code that shows how to handle
changes in the `ComboBox`’s selection. The approach is based on the
advice given in https://github.com/emilk/egui/discussions/923 . I hope
this saves future me (and hopefully others) a web search for how to do
this.

* [x] I have followed the instructions in the PR template
2025-06-11 12:01:34 +02:00
Emil Ernerfeldt bdbe655852 Mark HarnessBuilder build functions with #[must_use] 2025-06-07 17:19:12 -07:00
Emil Ernerfeldt b8dfb138b6 Remove outdated link in README 2025-06-07 10:24:41 -07:00
Emil Ernerfeldt 209e818bd8 Improve deprecation message for old `egui::menu` 2025-06-07 10:24:28 -07:00
Emil Ernerfeldt 6e34152fa0
Add `Context::format_modifiers` (#7125)
Convenience
2025-06-07 19:22:16 +02:00
Emil Ernerfeldt 53098fad7b
Support vertical-only scrolling by holding down Alt (#7124)
* Closes https://github.com/emilk/egui/issues/7120

You can now zoom only the X axis by holding down shift, and zoom only
the Y axis by holding down ALT.

In summary

* `Shift`: horizontal
* `Alt`: vertical
* `Ctrl`: zoom (`Cmd` on Mac)

Thus follows:
* `scroll`: pan both axis (at least for trackpads and mice with two-axis
scroll)
* `Shift + scroll`: pan only horizontal axis
* `Alt + scroll`: pan only vertical axis
* `Ctrl + scroll`: zoom all axes
* `Ctrl + Shift + scroll`: zoom only horizontal axis
* `Ctrl + Alt + scroll`: zoom only vertical axis

This is provided the application uses `zoom_delta_2d` for its zooming
needs.

The modifiers are exposed in `InputOptions`, but it is strongly
recommended that you do not change them.

## Testing
Unfortunately we have no nice way of testing this in egui.
But I've tested it in `egui_plot`.
2025-06-07 19:18:13 +02:00
Emil Ernerfeldt 1d5b011793
Add `OperatingSystem::is_mac` (#7122)
* Part of https://github.com/emilk/egui/issues/7120
2025-06-07 18:36:23 +02:00
Emil Ernerfeldt cbd9c60399
Add `Modifiers::matches_any` (#7123)
* Part of https://github.com/emilk/egui/issues/7120
2025-06-07 18:36:16 +02:00
Emil Ernerfeldt 9681644936
Move all input-related options into `InputOptions` (#7121) 2025-06-07 18:25:19 +02:00
Lucas Meurer 6d04140736
Fix update from ci script on linux (#7113)
Apparently MacOS is case insensitive 😬
2025-06-04 10:10:47 +02:00
Emil Ernerfeldt 417fdb1a43 Fix typo in changelog 2025-06-03 07:59:02 -07:00
Guy Marshall 1abccb3f47
Typo in `run_native` doc comment (replace "a an" with "an") (#7094)
<!--
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!
-->
2025-06-03 16:57:43 +02:00
Emil Ernerfeldt 92fea8a18f
Remove things that have been deprecated for over a year (#7099)
Removes all things that were marked `#[deprecated]` more than 12 months
ago
2025-05-28 09:47:15 +02:00
Emil Ernerfeldt 2cf6a3a9a6
Track original SVG size (#7098)
This fixes bugs related to how an `Image` follows the size of an SVG.

We track the "source size" of each image, i.e. the original width/height
of the SVG, which can be different from whatever it was rasterized as.
2025-05-28 08:33:01 +02:00
Emil Ernerfeldt da67465a6c
Add `Response::clicked_with_open_in_background` (#7093)
Useful for buttons that should act as Hyperlinks
2025-05-26 19:44:55 +02:00
Matt Keeter a085d0b3a5
Fix typo in `egpu-wgpu/Cargo.toml` (#7083) 2025-05-25 16:10:39 +02:00
Emil Ernerfeldt 87de733da3
Better define the meaning of `SizeHint` (#7079) 2025-05-23 13:52:36 +02:00
Emil Ernerfeldt ec8b41f7ec
Make `Image::paint_at` pixel-perfect crisp for SVG images (#7078) 2025-05-23 10:15:17 +02:00
Emil Ernerfeldt b8334f365b
Fix sometimes blurry SVGs (#7071)
* Closes https://github.com/emilk/egui/issues/3501

The problem occurs when you want to render the same SVG at different
scales, either at the same time in different parts of your UI, or at two
different times (e.g. the DPI changes).

The solution is to use the `SizeHint` as part of the key.

However, when you have an SVG in a resizable container, that can lead to
hundreds of versions of the same SVG. So new eviction code is added to
handle this case.
2025-05-21 20:01:40 +02:00
Emil Ernerfeldt b05a40745f
Bug fix: make sure `end_pass` is called for all loaders (#7072)
None of the built-in loaders does any cache eviction (yet), but 3rd
party ones might have
2025-05-21 19:52:59 +02:00
Emil Ernerfeldt f57cb27386
Include test windows in `egui_demo_lib` snapshot tests (#7070) 2025-05-21 17:44:27 +02:00
Emil Ernerfeldt 54ae2360ec
Fix incorrect color fringe colors on SVG:s (#7069)
This is a problem that affected the fringes on all SVG:s with
transparency, especially on a light background.

## Before

![image](https://github.com/user-attachments/assets/342823ad-005c-4f82-83a6-d2dcccfd3221)


## After

![image](https://github.com/user-attachments/assets/73398265-d333-461b-8c2b-fce405d95a9c)
2025-05-21 17:18:36 +02:00
Emil Ernerfeldt f23618701f
Update `emoji-icon-font` with fix for fullwidth latin characters (#7067)
* This PR is based on https://github.com/emilk/egui/pull/5877 by
@danielhjacobs

## Original PR description
Replace the current `emoji-icon-font.ttf` with the updated font from
https://github.com/jslegers/emoji-icon-font/pull/19 to address
https://github.com/emilk/egui/issues/1284. The second commit then
removes the now unnecessary hack.

* Closes https://github.com/emilk/egui/issues/1284
* Closes https://github.com/emilk/egui/pull/5877

---------

Co-authored-by: Daniel Jacobs <danielhunterjacobs@gmail.com>
2025-05-21 13:22:23 +02:00
valadaptive 6ccb768000
Bump accesskit to 0.19 (#7040)
Parley's bumped accesskit to 0.19, so we have to as well. It's a bit
concerning that we may end up locked to the version of accesskit that
Parley uses, but oh well.

[This kittest PR will have to be merged
first.](https://github.com/rerun-io/kittest/pull/11)

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-05-19 10:22:10 +02:00
Patrick Marks a15040c011
Fix `visual_bounding_rect` for rotated text (#7050)
TextShape.visual_bounding_rect was not taking the text rotation into
account. I manually tested drawing the new bounding box on top of the
text for various rotations & anchor settings. For example:
<img width="191" alt="image"
src="https://github.com/user-attachments/assets/56528fc7-7e7d-45af-b92a-c1cd307ff205"
/>

The unit test I added will fail without this patch, but perhaps doesn't
add much value.

* [x] I have followed the instructions in the PR template
2025-05-18 19:19:12 +02:00
Piotr Podusowski 12cd35f48c
Disallow `accesskit` on Android NativeActivity, making `hello_android` working again (#6855)
Follow up for https://github.com/emilk/egui/pull/6766

I wasn't sure if `compile_error` is appropriate. It felt right.
2025-05-18 13:17:28 +02:00
Abdellatif EL MIZEB cb4acbc262
Fix typo in deprecation message for `ComboBox::from_id_source` (#7055)
This PR corrects the deprecation note on ComboBox::from_id_source:

Changed:
`#[deprecated = "Renamed id_salt"]`

To:
`#[deprecated = "Renamed from_id_salt"]`
2025-05-18 13:02:58 +02:00
Emil Ernerfeldt 81b7e7f05a
Make the default spinner more high-res (#7044)
Make it nice and smooth when big
2025-05-11 22:15:07 +02:00
TÖRÖK Attila 773232b139
Update to wgpu 25 (#6744)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2025-05-10 13:16:49 +02:00
Hubert Głuchowski e9609ac94e
Fix `leading_space` sometimes being ignored during paragraph splitting (#7031)
Fixes a regression introduced in https://github.com/emilk/egui/pull/5411
(possibly
d74bee536f)
that breaks `leading_space` handling.
I think this is what the condition should be but I haven't touched this
code in a while.
2025-05-08 15:47:13 +02:00
Lucas Meurer 7872b5b363
Fix some links that were accidentally broken (#7036)
#7034 renamed a couple too many links
2025-05-08 13:17:40 +02:00
Lucas Meurer 120d736cfc
Add `ImageLoader::has_pending` and `wait_for_pending_images` (#7030)
With kittest it was difficult to wait for images to be loaded before
taking a snapshot test.
This PR adds `Harness::with_wait_for_pending_images` (true by default)
which will cause `Harness::run` to sleep until all images are loaded (or
`HarnessBuilder::with_max_steps` is exceeded).

It also adds a new ImageLoader::has_pending and
BytesLoader::has_pending, which should be implemented if things are
loaded / decoded asynchronously.

It reverts https://github.com/emilk/egui/pull/6901 which was my previous
attempt to fix this (but this didn't work since only the tested crate is
compiled with cfg(test) and not it's dependencies)
2025-05-08 09:27:52 +02:00
Emil Ernerfeldt 0fd6a805a4
Add `lycheee.toml` to ignore 429 (#7035)
Trying to get CI green
2025-05-08 09:26:36 +02:00
Emil Ernerfeldt d0876a1a60
Rename `master` branch to `main` (#7034)
For consistency with other repositories, i.e. so I can write `git
checkout main` without worrying which repo I'm browsing.
2025-05-08 09:15:42 +02:00
Emil Ernerfeldt 7216d0e386
Use mimalloc for benchmarks (#7029)
`mimalloc` is a _much_ faster allocator, especially important when doing
a lot of small allocations (which egui does).

We use `mimalloc` in Rerun, and I recommend everyone to use it.

## The difference it makes

![image](https://github.com/user-attachments/assets/b22e0025-bc5e-4b3c-94e0-74ce46e86f85)
2025-05-06 17:54:06 +02:00
Lucas Meurer 5bb20f511e
Fix links and text selection in horizontal_wrapped layout (#6905)
* Closes <https://github.com/emilk/egui/issues/6904>
* [x] I have followed the instructions in the PR template

This was broken in https://github.com/emilk/egui/pull/5411. Not sure if
this is the best fix or if `PlacedRow::rect` should be updated, but I
think it makes sense that PlacedRow::rect ignores leading space.
2025-05-06 17:40:18 +02:00
Lucas Meurer 71e0b0859c
Make `WidgetText` smaller and faster (#6903)
* In preparation of #5830, this should reduce the performance impact of
that PR

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-05-06 17:35:56 +02:00
Emil Ernerfeldt ba70106399 Fix enforce_branch_name.yml 2025-05-06 10:25:02 +02:00
Alexander Nadeau 6c922f72a8
Fix text distortion on mobile devices/browsers with `glow` backend (#6893)
<!--
Please read the "Making a PR" section of
[`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/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!
-->

Did not test on platforms other than my phone, but I can't imagine it
causing problems. AFAIK if highp isn't supported then `precision highp
float;` needs to still not cause the program to fail to link/compile or
anything; it should just silently use some other precision.

* Fixes https://github.com/emilk/egui/issues/4268 for me but I only
tested it on a native Android app and I don't know whether backends
other than glow are affected.
* [x] I have followed the instructions in the PR template (but the
change is trivial so I'm just doing it from the master branch)

Before:

![image](https://github.com/user-attachments/assets/9f449749-5a48-4e9c-aef0-7a8ac3912eb6)

After:

![image](https://github.com/user-attachments/assets/544e5977-13e0-411a-bccf-b15a15289e28)
2025-04-30 14:12:08 +02:00
Emil Ernerfeldt f3611e3e5a
Enforce that PRs are not opened from the 'master' branch of a fork (#6899)
## What
Fail all PRs that are opened from the master/main branch of the fork.

## Why
PR:s opened from the `master` branch cannot be collaborated on. That is,
we maintainers cannot push our own commits to it (e.g. to fix smaller
problems with it before merging).

## How
Untested code straight from Claude 3.7 😅
2025-04-30 14:10:59 +02:00
Lucas Meurer 2947821c60
Load images on the ui thread for tests (#6901)
https://github.com/emilk/egui/pull/5394 made it so images would load on
a background thread, which is great. But this makes snapshot tests that
have images via include_image!() flakey since they might or might not
load by the time the snapshot is rendered.
This is no perfect solution, since the underlying problem of "waiting
for something async to happen" still exists and we should add some more
general solution for that.
2025-04-30 12:55:57 +02:00
Lucas Meurer fdaac16e4a
Fix image button panicking with tiny `available_space` (#6900)
* Fixes <https://github.com/emilk/egui/issues/6772>
* [x] I have followed the instructions in the PR template
2025-04-30 10:40:50 +02:00