Commit Graph

3672 Commits

Author SHA1 Message Date
TÖRÖK Attila a5d7cf5bd7
Upgrade to wgpu 24 (#5610) 2025-01-16 17:00:29 +01:00
Alix Bott 366900c550
implement Debug for RichText (#5596)
<!--
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!
-->

* Derive Debug for RichText
* [x] I have followed the instructions in the PR template
2025-01-14 08:44:39 +01:00
Emil Ernerfeldt 164f56f554
Fix some clippy issues found by 1.84.0 (#5603) 2025-01-13 08:29:13 +01:00
Andreas Reich 1339639706
Fix Windows clippy issues (#5593)
These have been a lil bit annoying when running `cargo clippy
--all-features --all-targets` on windows
2025-01-11 18:05:57 +01:00
Andreas Reich f0d7c74e83
`response` module is now public, allowing access to `egui::response::Flags` (#5592) 2025-01-08 15:45:46 +01:00
Andreas Reich 443df84a22
Extend `WgpuSetup`, `egui_kittest` now prefers software rasterizers for testing (#5506) 2025-01-08 14:24:58 +01:00
lucasmerlin 7186f72cbe
Add a test for comboboxes (#5574)
* [x] I have followed the instructions in the PR template
2025-01-07 13:26:57 +01:00
Andrew Farkas 329c8f2fc1
Fix panic due to non-total ordering in `Area::compare_order()` (#5569)
[Area::compare_order()](ee4ab08c8a/crates/egui/src/memory/mod.rs (L1174-L1183))
is not a total ordering. If three layers A, B, and C have the same
`order` field but only A and B are present in `order_map`, then `A==C`
and `B==C` but `A!=C`. This can cause a panic in the stdlib sort
function, and does in [my
app](https://github.com/HactarCE/Hyperspeedcube/tree/v2.0) although it's
very difficult to reproduce.

* [x] I have self-reviewed this PR and run `./scripts/check.sh`
* [x] I have followed the instructions in the PR template
2025-01-07 08:37:23 +01:00
Aely 7cb8187ac8
Support RGB WebP images (#5586)
Current WebP loader assumes all WebP images to be RGBA, which is the
case if the image is animated (that's what `image` crate assumes at
least). Static images can instead choose to exclude its alpha channel,
though it seems to be more of a default choice to include it, even if
it's not being utilized. Currently, loading a static RGB WebP image will
cause a panic when `ColorImage::from_rgba_unmultiplied` gets called in
the loader
```
thread 'main' panicked at /home/aely/.cargo/git/checkouts/egui-226fc7cdd51201c1/f87219d/crates/epaint/src/image.rs:97:9:
assertion `left == right` failed
  left: 29184
 right: 21888
```
2025-01-07 08:35:58 +01:00
lucasmerlin 52060c0c41
Change `Harness::run` to run until no more repaints are requested (#5580)
Previously, `Harness::run` just called `Harness::step` 3 times. If that
wasn't enough, tests would often call run multiple times so all
animations would finish properly.

Also, I introduced `HarnessBuilder::with_step_dt` to customize with how
big of a dt each frame is called. I set the default to 1.0 / 6.0 (~6fps)
so we don't waste cpu in tests waiting on animations.

`HarnessBuilder::max_steps` allows us to control how many steps
`Harness::run` should run before panicing.
The default is 6, so we run for up to 1.0 logical seconds (six frames at
6 fps), which should be enough to finish most animations.

Turns out a lot of snapshots where rendered before fully shown and had a
light opacity, those are now fixed.

* [x] I have followed the instructions in the PR template
2025-01-07 08:33:44 +01:00
Pol Welter 35860418ac
Use bitfield instead of bools in `Response` and `Sense` (#5556)
<!--
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!
-->

Closes <https://github.com/emilk/egui/issues/3862>.

Factoring the `bool` members of `Response` into a bitfield, the size of
`Response` is now 96 bytes (down from 104).

I gave `Sense` the same treatment, however this has no effects on
`Response` due to padding. I've decided not to pursue `PointerState`, as
it is quite large (_many_ members that are sized and aligned to
multiples of 8 bytes), so I don't expect any noticeable benefit from
making handful of `bool`s slightly leaner.

In any case, the changes to `Sense` are already quite a bit more
intrusive than those to `Response`.
The previous implementation overloaded the names of the attributes
`click` and `drag` with similarly named methods that _construct_ `Sense`
with the corresponding flag set. Now, that the attributes can no longer
be accessed directly, I had to introduce methods with new names
(`senses_click()`, `senses_drag()` and `is_focusable()`). I don't think
this is the cleanest solution: the old methods are essentially redundant
now that the named constants like `Sense::CLICK` exist. I did however
not want to needlessly break backwards compatibility.
I am happy to revert it (or go further 🙂) if there are concerns.
2025-01-06 19:29:53 +01:00
Markus Ineichen 0fac8eadfc
Avoid allocations for loader cache lookup (#5584)
[ x ] I have ~~followed~~ _read_ the instructions in the PR template

Unfortunately i had several issues:
- Some snapshot-tests didn't run successfully on osx. diff shows errors
around fonts or missing menu items)
- cargo clippy doesn't run successfully (egui_kittest cannot find `wgpu`
and `image`)
- ./scripts/check.sh had other issues on my system (env: python: No such
file or directory), even if python3 can be called via python in my shell
 
Is there a system independent, standard way to run these tools (e.g. via
Docker?)
I submit the pr anyway, because there changes are very simple and
shouldn't cause issues.
2025-01-06 10:03:33 +01:00
Lander Brandt 9073516e30
Serialize window maximized state in `WindowSettings` (#5554)
A user of my Windows application reported a papercut where the
application restores its size on next load, but does not restore its
maximized state. This PR fixes that.

To test, I patched https://github.com/emilk/eframe_template to use my
local code since I knew that template saves/restores window data.
Testing methodology was to simply `cargo run`, maximize the application,
then close the application. `cargo run` again and the application should
start maximized.

Closes #1517.

* [x] I have followed the instructions in the PR template
* * This is mostly true, I had difficulties running `./scripts/check.sh`
for some reason. Possibly a bad Python version?
2025-01-06 09:19:17 +01:00
Emil Ernerfeldt 6607cd95f9
⚠️ `Frame` now includes stroke width as part of padding (#5575)
* Part of https://github.com/emilk/egui/issues/4019

`Frame` now includes the width of the stroke as part of its size. From
the new docs:

### `Frame` docs
The total (outer) size of a frame is `content_size + inner_margin +
2*stroke.width + outer_margin`.

Everything within the stroke is filled with the fill color (if any).

```text
+-----------------^-------------------------------------- -+
|                 | outer_margin                           |
|    +------------v----^------------------------------+    |
|    |                 | stroke width                 |    |
|    |    +------------v---^---------------------+    |    |
|    |    |                | inner_margin        |    |    |
|    |    |    +-----------v----------------+    |    |    |
|    |    |    |             ^              |    |    |    |
|    |    |    |             |              |    |    |    |
|    |    |    |<------ content_size ------>|    |    |    |
|    |    |    |             |              |    |    |    |
|    |    |    |             v              |    |    |    |
|    |    |    +------- content_rect -------+    |    |    |
|    |    |                                      |    |    |
|    |    +-------------fill_rect ---------------+    |    |
|    |                                                |    |
|    +----------------- widget_rect ------------------+    |
|                                                          |
+---------------------- outer_rect ------------------------+
```

The four rectangles, from inside to outside, are:
* `content_rect`: the rectangle that is made available to the inner
[`Ui`] or widget.
* `fill_rect`: the rectangle that is filled with the fill color (inside
the stroke, if any).
* `widget_rect`: is the interactive part of the widget (what sense
clicks etc).
* `outer_rect`: what is allocated in the outer [`Ui`], and is what is
returned by [`Response::rect`].

### Notes
This required rewriting a lot of the layout code for `egui::Window`,
which was a massive pain. But now the window margin and stroke width is
properly accounted for everywhere.
2025-01-04 10:29:22 +01:00
Emil Ernerfeldt 938d8b0d2e
egui_kittest: write `.old.png` files when updating images (#5578)
After running `UPDATE_SNAPSHOTS=1 cargo test --all-features` I want to
compare before/after images before committing them. Now I can!
2025-01-03 16:23:31 +01:00
Emil Ernerfeldt 5cbf337f18 check.sh: enable all features when running `cargo test` 2025-01-03 14:55:51 +01:00
Emil Ernerfeldt 7519ec7099 Fix: round animating collapsing header height to GUI 2025-01-03 14:54:57 +01:00
Emil Ernerfeldt 4784136fee
Better rounding of rectangles with thin outlines (#5571)
Better positioning of rectangle outline when the stroke width is less
than one pixel
2025-01-02 23:50:40 +01:00
lucasmerlin 46b58e5bcc
Add `Harness::new_eframe` and `TestRenderer` trait (#5539)
Co-authored-by: Andreas Reich <r_andreas2@web.de>
2025-01-02 17:48:39 +01:00
Emil Ernerfeldt ee4ab08c8a
Shrink size of `Shadow` by using `i8/u8` instead of `f32` (#5568)
* Part of https://github.com/emilk/egui/issues/4019
2025-01-02 16:22:44 +01:00
Emil Ernerfeldt d58d13781d
Store `Margin` using `i8` to reduce its size (#5567)
Adds `Marginf` to fill the previous niche.

This is all in a pursuit to shrink the sizes of often-used structs, to
improve performance (less cache misses, less memcpy:s, etc).

* On the path towards https://github.com/emilk/egui/issues/4019
2025-01-02 16:05:52 +01:00
Emil Ernerfeldt aeea70d9e7
Add `epaint::Brush` for controlling `RectShape` texturing (#5565)
Also wraps `Shape::Mesh` in an `Arc`.

No new features, but decreases size of `Shape` from 72 bytes to 64.
2025-01-02 15:34:28 +01:00
Emil Ernerfeldt 72ac2113dd Fix stroke of custom_window_frame example 2025-01-02 15:32:43 +01:00
Emil Ernerfeldt 64f077588c Improve kittest snapshot output: print absolute path to diff file 2025-01-02 14:56:27 +01:00
Emil Ernerfeldt cf7150c6a3
Refactor: put each shape into its own file (#5564)
Much easier to navigate the code
2025-01-02 14:55:49 +01:00
Emil Ernerfeldt 249f8bcb93
Use `u8` in `Rounding`, and introduce `Roundingf` (#5563)
* Part of https://github.com/emilk/egui/issues/4019

As part of the work on adding a custom `Border` to everything, I want to
make sure that the size of `RectShape`, `Frame` and the future `Border`
is kept small (for performance reasons).

This PR changes the storage of the corner radius of rectangles from four
`f32` (one for each corner) into four `u8`. This mean the corner radius
can only be an integer in the range 0-255 (in ui points). This should be
enough for most people.

If you want to manipulate rounding using `f32`, there is a new
`Roundingf` to fill that niche.
2025-01-02 14:29:50 +01:00
YgorSouza 3ffe1ed774
Re-enable IME support on Linux (#5198)
Reverts #5188 and adds a different fix to restore IME on Linux without
breaking the backspace and arrow keys.

* Closes https://github.com/emilk/egui/issues/5544
* Closes https://github.com/emilk/egui/pull/5198
* [x] I have followed the instructions in the PR template
2024-12-31 13:37:05 +01:00
lucasmerlin e32ca218e8
Add `WidgetType::Image` and `Image::alt_text` (#5534)
This adds `WidgetType::Image` and correctly sets it in the Image widget.
This allows us to query for images in kittest tests and tells accesskit
that a node is an image.
It also adds `Image::alt_text` to set a text that will be shown if the
image fails to load and will be read via screen readers. This also
allows us to query images by label in kittest.


* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-12-30 12:53:46 +01:00
lucasmerlin 86ea3f8a5c
Fix cargo test --all-features breaking rendering due to unity vertexes (#5542)
* Closes #5297 
* [x] I have followed the instructions in the PR template

It's not great but I wasn't able to come up with a better solution.
2024-12-30 12:39:17 +01:00
Emil Ernerfeldt bf6ed3adfc
Add `Context::copy_image` (#5533)
* Closes https://github.com/emilk/egui/issues/5424

This adds support for copying images to the system clipboard on native
and on web using `Context::copy_image`.
2024-12-29 18:03:32 +01:00
Emil Ernerfeldt e2c7e9e733
Add `OutputCommand` for copying text and opening URL:s (#5532)
Add `OutputCommand` for copying text and opening URL:s

* Part of https://github.com/emilk/egui/issues/5424
* Adds `egui::OutputComm
* Part of https://github.com/emilk/egui/issues/5424and`
* Adds `PlatformOutput::commands`
* Deprecates `PlatformOutput::open_url`
* Deprecates `PlatformOutput::copied_text`
2024-12-29 11:59:51 +01:00
Aely 1e0f3a5e2d
Animated WebP support (#5470)
Adds support for animated WebP images. Used the already existing GIF
implementation as a template for most of it.

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-12-29 11:46:08 +01:00
Emil Ernerfeldt 01a7e31b13 Update test snapshot 2024-12-29 11:27:01 +01:00
Tom Maffia 13676ea35f
Fix minor typo 2024-12-29 11:25:51 +01:00
Emil Ernerfeldt 2356ae8819 Remove colons from widget gallery 2024-12-28 23:26:26 +01:00
Emil Ernerfeldt fa95351675
Slight improvements to the demo (#5527) 2024-12-28 22:11:41 +01:00
Emil Ernerfeldt 820d42802a
Fix build of egui.rs (#5528) 2024-12-28 21:52:37 +01:00
Emil Ernerfeldt f37a8f91ca Better output when building demo 2024-12-28 21:44:56 +01:00
Ryan Bluth 8131b7b898
Make image extension lowercase before checking if it is supported (#5501)
<!--
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!
-->

* Images with capitalized extensions do not load because the list of
extensions they are checked against is lowercase. The image extension is
now converted to lowercase before comparing
* [x ] I have followed the instructions in the PR template
2024-12-28 16:01:30 +01:00
Emil Ernerfeldt c37125f835
Tweak window resize handles (#5524)
This makes it easier to hit the corners.
Previously the corner response-area was covered by the response-areas of
the edges.

* Related to https://github.com/emilk/egui/pull/5523
2024-12-27 15:50:34 +01:00
Emil Ernerfeldt 4d945f78ba
Fix widgets sometimes being incorrectly marked as hovered (#5523)
An interactive widget should only be marked hovered if a click/drag
would start an interaction with it.

egui 0.30 introduced a feature where a thin interactive widget could be
hit even if it was partially behind a larger interactive widget.
Unfortunately, this introduced a bug where the top widget would still be
marked as hovered, even though a click would go through to the thin
widget below.

This bug was most notacible when trying to reisize a window by dragging
its corner, which often would result in dragging one of its sides
instead.

This PR fixes this bug.
2024-12-27 14:47:18 +01:00
Emil Ernerfeldt d20f93e9bf
Make all lines and rectangles crisp (#5518)
* Merge this first: https://github.com/emilk/egui/pull/5517

This aligns all rectangles and (horizontal or vertical) line segments to
the physical pixel grid in the `epaint::Tessellator`, making these
shapes appear crisp everywhere.

* Closes https://github.com/emilk/egui/issues/5164
* Closes https://github.com/emilk/egui/issues/3667

This undoes a lot of the explicit, egui-side aligning added in:
* https://github.com/emilk/egui/pull/4943

The new approach has several benefits over the old one:

* It is done automatically by epaint, so it is applied to everything (no
longer opt-in)
* It is applied after any layer transforms (so it always works)
* It makes line segments crisper on high-DPI screens
* All filled rectangles now has sides that end on pixel boundaries
2024-12-26 21:02:27 +01:00
Emil Ernerfeldt dfcc679d5a
Round widget coordinates to even multiple of 1/32 (#5517)
* Closes https://github.com/emilk/egui/pull/5197
* Closes https://github.com/emilk/egui/issues/5163

This should help prevent rounding errors in layout code.

@lucasmerlin you may wanna test this with `egui_flex`
2024-12-26 20:54:24 +01:00
Emil Ernerfeldt f30f5e9578
Update to winit 0.30.7 (#5516)
Fixes wrong cursor on Mac, among other things:

https://github.com/rust-windowing/winit/releases/tag/v0.30.6
2024-12-26 12:06:24 +01:00
Jochen Görtler 7f711668b4
Provide better `debug_assert`s for ray intersections (#5504)
<!--
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!
-->

Title. This would have helped me debug bugs quicker.

* [x] I have followed the instructions in the PR template
2024-12-19 13:39:14 +01:00
Onè 27a5803dd3
docs: remove "a" (#5499)
Was a duplicate article in the sentence. Already has "the"

<!--
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!
-->

* Closes <https://github.com/emilk/egui/issues/THE_RELEVANT_ISSUE>
* [ ] I have followed the instructions in the PR template
2024-12-17 18:29:41 +01:00
lucasmerlin 8c4d8b2da8
Use correct minimum version of `profiling` crate (#5494)
We need profiling::function_scope which was introduced in 1.0.16, so
this is the minimum required version
* Closes <https://github.com/emilk/egui/issues/5491>
* [x] I have followed the instructions in the PR template
2024-12-17 09:37:15 +01:00
Emil Ernerfeldt cfc341fabd
Revert "Revert "forward x11 and wayland features to glutin" (#5391)" (#5490)
* https://github.com/emilk/egui/pull/5391
* https://github.com/emilk/egui/pull/5488
* https://github.com/emilk/egui/pull/5490
2024-12-17 09:36:03 +01:00
Emil Ernerfeldt adfc0bebfc
Revert "forward x11 and wayland features to glutin" (#5391) (#5488)
* Reverts https://github.com/emilk/egui/pull/5391

Because it causes head-ache:
https://github.com/emilk/eframe_template/actions/runs/12357896151/job/34487194281
2024-12-16 19:25:21 +01:00
Emil Ernerfeldt d864655018 Reorder crate publish steps 2024-12-16 18:10:01 +01:00