Commit Graph

3955 Commits

Author SHA1 Message Date
RndUsr123 68d456ac0b
Fixes sense issues in TextEdit when vertical alignment is used (#7436)
<!--
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!
-->

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

I'm running a rustup-less rust install on Windows, so I don't have
`clippy` nor `fmt` and can't run the .sh script.
It's very little code and I manually tested this, so hopefully that's
ok...

Let me know if the comment in `state.rs` needs to be updated or the
`text_offset` name isn't clear enough.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-08-12 12:27:55 +02:00
YgorSouza 53d8c48b4f
Fix panic on Stroke style editor widget (#7443)
The infinite limit caused arithmetic issues when rendering the preview
with very large values, which led to a panic. The new limit should still
be higher than anyone would reasonably want to set a stroke width to,
but not high enough to trigger a panic.

* Closes <https://github.com/emilk/egui/issues/7348>
* [x] I have followed the instructions in the PR template
2025-08-12 09:13:50 +02:00
YgorSouza fb5fe645be
Make the `hex_color` macro `const` (#7444)
* Closes <https://github.com/emilk/egui/issues/5160>
* [x] I have followed the instructions in the PR template
2025-08-12 09:12:44 +02:00
Emil Ernerfeldt 6fae65a3fa
Add `emath::fast_midpoint` (#7435) 2025-08-08 12:04:51 +02:00
Emil Ernerfeldt 3024c39eaf
Enable and fix some more clippy lints (#7426)
One can never have too many lints
2025-08-08 09:57:53 +02:00
Lucas Meurer e8e99a0bb6
Fix manual `Popup` not closing (#7383)
Fixes manually created popups (via `Popup::new`) not closing, since
widget_clicked_elsewhere was always false.

This example would never close:

```rs
    let mut open = true;

    eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
        egui::CentralPanel::default().show(ctx, |ui| {
            let response = egui::Popup::new(
                Id::new("popup"),
                ctx.clone(),
                PopupAnchor::Position(Pos2::new(10.0, 10.0)),
                LayerId::new(Order::Foreground, Id::new("popup")),
            )
            .open(open)
            .show(|ui| {
                ui.label("This is a popup!");
                ui.label("You can put anything in here.");
            });

            if let Some(response) = response {
                if response.response.should_close() {
                    open = false;
                }
            }
        });
    })
```

I also noticed that the Color submenu in the popups example had a double
arrow (must have been broken in the atoms PR):

<img width="248" height="110" alt="Screenshot 2025-08-07 at 13 42 28"
src="https://github.com/user-attachments/assets/a4e0c267-ae71-4b2c-a1f0-f53f9662d026"
/>

Also fixed this in the PR.
2025-08-07 14:18:04 +02:00
Emil Ernerfeldt 36a4981f29
Enable `clippy::iter_over_hash_type` lint (#7421)
This helped discover a few things that _might_ have been buggy.
2025-08-06 13:55:53 +02:00
Emil Ernerfeldt d42ea3800f
Update to winit 0.30.12 (#7420) 2025-08-06 13:53:59 +02:00
satnam72 72fcbb8610
Use `Frame::NONE` in docstring (#7396)
- Replaced deprecated `egui::Frame::none()` with `egui::Frame::NONE`

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

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

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-08-06 13:27:51 +02:00
Emil Ernerfeldt c8e6f6bfe5 Remove deprecated clippy lint 2025-08-06 11:45:02 +02:00
Lucas Meurer 2c6611d0c6
Enable wgpu default features in eframe / egui_wgpu default features (#7344) 2025-08-05 21:21:00 +02:00
Emil Ernerfeldt ef039aa566
Enable more clippy lints (#7418)
More is more!
2025-08-05 19:47:26 +02:00
Icekey e9afd3c52d
Add `UiBuilder::global_scope` and `UiBuilder::id` (#7372)
I added a new flag to the UiBuilder so that it is possible to move child
widgets around the ui tree without losing state information.
Currently there is no way to create child widgets with the same id at
different locations in the ui tree since ids change in relation the the
parent id. With the new flag a unique global scope can be created which
always results in the same ids even at different locations.
You still need to ensure that the widgets only get rendered once in
frame.

This feature can be used to fix a issue i am having with the
https://github.com/lucasmerlin/hello_egui crate.


* Closes https://github.com/lucasmerlin/hello_egui/issues/75
* [X] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-08-05 19:26:52 +02:00
Lucas Meurer 3aee525755
Add `ComboBox::popup_style` (#7360)
* Closes #7349  
* [x] I have followed the instructions in the PR template
2025-08-05 14:55:24 +02:00
Michael Grupp a1e5501db8
Improve `debug_assert` when calling `add_space()` in `Grid` layout (#7399)
Makes it clearer to understand than the lower-level
`advance_cursor` assert for an user who accidentally does this.
2025-08-05 14:43:02 +02:00
Vanadiae 8333615072
Fix memory leak when `forget_image` is called while loading (#7380)
This is the same issue that was fixed for the http bytes loader in
239ade9a59

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

----------------

Funnily, [this
comment](https://github.com/emilk/egui/issues/3747#issuecomment-1872192997)
describes exactly how I encountered this issue:

> That assert is wrong if something calls forget between the start of
the request and the end of it.

I'm displaying lots of images in a scrolling grid (20 or so visible at a
time). It seems like image textures are never freed up automatically so
it stacks up a lot meaning I have to unload the image textures manually
with `egui::Context::forget_image()` in each `eframe::App::update()`
call for the images that are no longer shown when scrolling.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-08-05 14:41:32 +02:00
Hubert Głuchowski 31eb4d498b
Fix multi-line `TextShape` rotation (#7404)
* Closes <https://github.com/emilk/egui/issues/7397>
* [X] I have followed the instructions in the PR template
I do admit I got a peak NixOS `RequestDeviceError` and deemed it
entirely not worth it to think about that.

https://github.com/emilk/egui/pull/5411 broke rotation of multi-line
`TextShape`s because `PlacedRow::pos` was no longer being rotated, so
let's rotate it.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Lucas Meurer <hi@lucasmerlin.me>
2025-08-05 13:11:45 +02:00
Emil Ernerfeldt b9a5081490
Fix glyph rendering: clamp coverage to [0, 1] (#7415)
* Closes  #7366
* Closes https://github.com/emilk/egui/pull/7388
2025-08-05 13:03:39 +02:00
Alexander c38d38e89d
Align `Color32` to 4 bytes (#7318)
<!--
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!
-->

It could be useful when you want to preprocess an image using SIMD
instructions without extra copying to convert it to a texture.

Possibly we might add it as a feature.

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

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-08-05 12:04:30 +02:00
Tamo 7fb13d85ec
Request a redraw when the url change through the `popstate` event listener (#7403)
<!--
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!
-->

Hey, I added an event listener on the [`popstate`
event](https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event).
That fixed my issue


https://github.com/user-attachments/assets/a621dac9-b7c3-426a-968b-dc73c5702eea

* Closes https://github.com/emilk/egui/issues/7402
* [x] I have followed the instructions in the PR template
2025-08-05 11:31:05 +02:00
Emil Ernerfeldt fdcaff8465 Improve RELEASES.md 2025-07-10 17:06:31 +02:00
Emil Ernerfeldt fabd4aa7a5
Release 0.32.0 - Atoms, popups, and better SVG support (#7329) 2025-07-10 16:58:39 +02:00
Lucas Meurer a9124af00d
Update kittest to 0.2 (#7332) 2025-07-10 16:38:52 +02:00
Lucas Meurer c0325e9be2
Add more docs to menu (#7331)
Improves the docs a bit
2025-07-10 15:35:04 +02:00
Lucas Meurer 14c2e5d3d5
Set intrinsic size for Label (#7328)
Sets intrinsic size for labels
2025-07-10 10:48:14 +02:00
Emil Ernerfeldt 9478a6223b
Rename `egui::containers::menu::Bar` to `egui::MenuBar` (#7327)
The old name is still there, just deprecated.
2025-07-10 10:33:48 +02:00
Emil Ernerfeldt 8d2f39fc08
Improve release checklist (#7322)
* See https://github.com/emilk/egui/issues/7321
2025-07-09 19:36:38 +02:00
Lucas Meurer 087e56abae
Fix wrong galley split behavior when text ends with new line (#7320)
* Fixes a bug introduced by #7316 

The last `\n` was ignored for texts ending with `\n` in the galley split
logic.
2025-07-09 18:18:06 +02:00
Lucas Meurer 9fd0ad36e0
Implement `BitOr` and `BitOrAssign` for `Rect` (#7319) 2025-07-09 15:29:51 +02:00
Lucas Meurer 207e71c2ae
Exclude `\n` when splitting `Galley`s (#7316)
* Follow up to #7146 

Previously when galleys were splitted, each exept the last had an extra
empty row that had to be removed when they were concated. This changes
it to remove the `\n` from the layout jobs when splitting.
2025-07-09 14:53:19 +02:00
Emil Ernerfeldt a7f14ca176
Deprecate `Memory::popup` API in favor of new `Popup` API (#7317)
* Closes  #7037
* Closes #7297

This deprecates all popup-related function in `Memory`, replacing them
with the new `egui::Popup`.

The new API is nicer in all ways, so we should encourage people to use
it.
2025-07-09 12:55:06 +02:00
Emil Ernerfeldt fbe0aadf63
Add `Popup::from_toggle_button_response` (#7315)
Adds a convenience constructor for `Popup`
2025-07-09 10:12:47 +02:00
Lucas Meurer 508c60b2e2
Add `Galley::intrinsic_size` and use it in `AtomLayout` (#7146)
- part of https://github.com/emilk/egui/issues/5762
- also allows me to simplify sizing logic in egui_flex
2025-07-09 08:19:04 +02:00
Emil Ernerfeldt f46926aaf1
Improve texture filtering by doing it in gamma space (#7311)
* Closes https://github.com/emilk/egui/pull/5839

This makes some transparent images look a lot nicer when blended:


![image](https://github.com/user-attachments/assets/7f370aaf-886a-423c-8391-c378849b63ca)

Cursive text will also look nicer.

This unfortunately changes the contract of what
`register_native_texture` expects

---------

Co-authored-by: Adrian Blumer <blumer.adrian@gmail.com>
2025-07-07 17:46:27 +02:00
Emil Ernerfeldt dd1052108e
Add snapshot test for image blending (#7309)
This adds a test that can be used to see the improvements made by this
PR (if any):
* https://github.com/emilk/egui/pull/5839
2025-07-07 13:58:22 +02:00
Emil Ernerfeldt 09596a5e7b
egui_kittest: more ergonomic functions taking `Impl Into<String>` (#7307) 2025-07-07 13:50:53 +02:00
Emil Ernerfeldt b11b77e85f
Save a few CPU cycles with earlier early-out from `Popup::show` (#7306) 2025-07-07 12:07:13 +02:00
Emil Ernerfeldt 933d305159 Improve doc-string for `Image::alt_text` 2025-07-07 12:06:59 +02:00
Emil Ernerfeldt 93d562221b
Change `Rect::area` to return zero for negative rectangles (#7305)
Previously a single-negative rectangle (where `min.x > max.x` XOR `min.y
> max.y`) would return a negative area, while a doubly-negative
rectangle (`min.x > max.x` AND `min.y > max.y`) would return a positive
area. Now both return zero instead.
2025-07-07 12:03:03 +02:00
Emil Ernerfeldt 3622a03a46 Mark `Popup` with `#[must_use]` 2025-07-07 12:02:51 +02:00
Emil Ernerfeldt 6d80707422
Fix tooltips sometimes changing position each frame (#7304)
There was a bug in how we decide where to place a `Tooltip` (or other
`Popup`), which could lead to tooltips jumping around every frame,
especially if it changed size slightly.

The new code is simpler and bug-free.
2025-07-07 12:02:01 +02:00
Emil Ernerfeldt a811b975c2 Better deprecation of SelectableLabel 2025-07-07 09:33:08 +02:00
valadaptive 7ac137bfc1
Make the font atlas use a color image (#7298)
* [x] I have followed the instructions in the PR template

Splitting this out from the Parley work as requested. This removes
`FontImage` and makes the font atlas use a `ColorImage`. It converts
alpha to coverage at glyph-drawing time, not at delta-upload time.

This doesn't do much now, but will allow for color emoji rendering once
we start using Parley.

I've changed things around so that we pass in `text_alpha_to_coverage`
to the `Fonts` the same way we do with `pixels_per_point` and
`max_texture_side`, reusing the existing code to check if the setting
differs and recreating the font atlas if so. I'm not quite sure why this
wasn't done in the first place.

I've left `ImageData` as an enum for now, in case we want to add support
for more texture pixel formats in the future (which I personally think
would be worthwhile). If you'd like, I can just remove that enum
entirely.
2025-07-04 13:15:48 +02:00
Emil Ernerfeldt d94386de3d
Fix `debug_assert` triggered by `menu`/`intersect_ray` (#7299) 2025-07-04 09:55:03 +02:00
Lucas Meurer 47a2bb10b0
Remove `SelectableLabel` (#7277)
* part of https://github.com/emilk/egui/issues/7264
* removes SelectableLabel (Use `Button::selectable` instead)
* updates `Ui::selectable_value/label` with IntoAtoms support

Had to make some changes to `Button` since the SelecatbleLabel had no
frame unless selected.
2025-07-03 16:34:47 +02:00
Lucas Meurer 2b62c68598
Add `egui::Sides` `shrink_left` / `shrink_right` (#7295)
This allows contents (on one of the sides) in egui::Sides to shrink. 

* related https://github.com/rerun-io/rerun/issues/10494
2025-07-03 14:31:35 +02:00
Nicolas 77df407f50
`egui_kittest`: add `failed_pixel_count_threshold` (#7092)
I thought about this - so we have two options here:
1. adding it to `SnapshotOptions` 
2. adding it to every function which I do not like as this would be a
huge breaking change

## Summary

This pull request introduces a new feature to the `SnapshotOptions`
struct in the `egui_kittest` crate, allowing users to specify a
permissible percentage of pixel differences (`diff_percentage`) before a
snapshot comparison is considered a failure. This feature provides more
flexibility in handling minor visual discrepancies during snapshot
testing.

### Additions to `SnapshotOptions`:

* Added a new field `diff_percentage` of type `Option<f64>` to the
`SnapshotOptions` struct. This field allows users to define a tolerance
for pixel differences, with a default value of `None` (interpreted as 0%
tolerance).
* Updated the `Default` implementation of `SnapshotOptions` to
initialize `diff_percentage` to `None`.

### Integration into snapshot comparison logic:

* Updated the `try_image_snapshot_options` function to handle the new
`diff_percentage` field. If a `diff_percentage` is specified, the
function calculates the percentage of differing pixels and allows the
snapshot to pass if the difference is within the specified tolerance.
[[1]](diffhunk://#diff-6f481b5866b82a4fe126b7df2e6c9669040c79d1d200d76b87f376de5dec5065R204)
[[2]](diffhunk://#diff-6f481b5866b82a4fe126b7df2e6c9669040c79d1d200d76b87f376de5dec5065R294-R301)

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

---------

Co-authored-by: lucasmerlin <hi@lucasmerlin.me>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-07-03 14:23:15 +02:00
Emil Ernerfeldt ba577602a4
Fix crash when using infinite widgets (#7296)
* Closes https://github.com/emilk/egui/issues/7100
2025-07-03 13:40:02 +02:00
Blackberry Float db3543d034
Update area struct to allow force resizing (#7114)
This is a really small PR so I am skipping the issue (based on
contributing.md). This change adds an optional field and thus non
breaking for the API.

I ran into an issue during my development of an alerts manager widget
([see PR](https://github.com/blackberryfloat/egui_widget_ext/pull/2))
where I needed a scrollable overlay that did not block clicking areas of
a parent widget when my alerts did not take up the entire parent. To
achieve this I detect the sizing pass via the invisible flag and only
render the alerts content and then on the next pass I add the scroll bar
in around the alert content. Whenever the alert content changed though I
would need to create a new Area with a new id to get proper sizing. That
is a memory leak so I wanted to reset the size state to trigger a sizing
pass. Memory is rightfully protected enough that the path to remove
memory was dropped and I just added a hook to set a resize flag.

I am sure there are better ways but this is what made sense to me.
Looking forward to thoughts.

~~Logistics wise, I have proposed it as a patch because I was based off
0.31.1 for testing. I was also thinking it could be released quickly. I
am happy to cherry pick onto main after. If that is not allowed I can
rebase to main and pull against that.~~ (rebased on main)

---------

Co-authored-by: Wesley Murray <murraywj97@gmail.com>
2025-07-03 13:14:07 +02:00
Lucas Meurer 6d312cc4c7
Add support for scrolling via accesskit / kittest (#7286)
I need to scroll in a snapshot test in my app, and kittest had no
utilities for this. Event::MouseWheel is error prone. This adds support
for some accesskit scroll actions, and uses this in kittest to add
helpers to scroll to a node / scroll the scroll area surrounding a node.

The accesskit code says down/up/left/right `Scrolls by approximately one
screen in a specific direction.`. Unfortunately it's difficult to get
the size of a "screen" (I guess that would be the size of the containing
scroll area)where I implemented the scrolling, so for now I've hardcoded
it to 100px. I think scrolling a fixed amount is still better than not
scrolling at all.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2025-07-03 12:02:05 +02:00