Commit Graph

3312 Commits

Author SHA1 Message Date
Emil Ernerfeldt 254dfc1ebc
Fix broken mouse coordinates when there's padding on the canvas element (#4729)
* Closes https://github.com/emilk/egui/issues/4725

Also fixes touch input being wrong if the web page is scrolled.
2024-06-28 13:02:36 +02:00
Emil Ernerfeldt a6937f79f3 Improve `multiple_apps.html` example/demo/test 2024-06-28 08:44:17 +02:00
Emil Ernerfeldt e62bd7037a Improve warning when failing to copy on web 2024-06-28 08:40:58 +02:00
Emil Ernerfeldt 814eddd094 Add warning if `window.navigator.clipboard` is null 2024-06-28 08:39:49 +02:00
Emil Ernerfeldt f50e64632e Change web demo local port to 8765 to avoid colliding with Jupyter 2024-06-28 08:37:21 +02:00
Emil Ernerfeldt a0f4fafb88
Refactor web event handling: break up into smaller functions (#4717)
No change in functionality, just making the code easier to read and
change.

* Part of fixing https://github.com/rerun-io/rerun/issues/6638
2024-06-27 15:26:52 +02:00
Emil Ernerfeldt ce0e200503 Sort feature flags in egui_extras 2024-06-27 14:29:59 +02:00
Emil Ernerfeldt 97b6d8cb1c Fix vertical spacing in changelog generation 2024-06-27 14:29:49 +02:00
Emil Ernerfeldt a489374ca6 Improve CSS comment 2024-06-27 11:17:49 +02:00
Emil Ernerfeldt 7121a49e4e
`generate_changelog.py`: divide into "fixed/added/changed" sections (#4712)
Make each release a little bit easier to do
2024-06-27 09:54:01 +02:00
Umatriz 5051e945e4
Add `PopupCloseBehavior` (#4636)
This PR adds `PopupCloseBehavior` to improve state of the
<https://github.com/emilk/egui/issues/4607>

`PopupCloseBehavior` determines when popup will be closed.
- `CloseOnClick` popup will be closed if the click happens anywhere even
in the popup's body
- `CloseOnClickAway` popup will be closed if the click happens somewhere
else but in the popup's body.

It also adds a test in the demo app which contains several popups
examples.

---

My ideas about <https://github.com/emilk/egui/issues/4607> is to make
every tooltip and popup a menu. So it will provide more control over
popups and tooltips (you will be able to close a popup by calling
something similar to the `ui.close_menu` if you need to). You won't need
to manually handle it's opening. And also will allow to have multiple
popups opened. That means you can have a popup inside a popup. And it
will also lead to the easier creation of the popups. (should we create a
tracking issue to track changes because to me it seems like a huge
amount of changes to be done?)

---

- Improvements on <https://github.com/emilk/egui/issues/4607>
2024-06-27 09:42:57 +02:00
YgorSouza ab861574f4
Cancel DragValue edit if Escape is pressed (#4713)
Since Escape takes focus away from the text field, it makes more sense
for it to cancel the change rather than confirm it.

This only matters if `update_while_editing` is set to false, of course.
2024-06-27 09:18:25 +02:00
Emil Ernerfeldt a1a0d4a12a Tweak two demos 2024-06-26 21:18:28 +02:00
Emil Ernerfeldt fd85557463
Close context menus with Escape (#4711)
Pressing escape should close any menu or popup
2024-06-26 21:04:29 +02:00
n4n5 1036e18440
plot zoom out max (#4695)
* Closes <https://github.com/emilk/egui/issues/3462>


#3462 panics when when hit the bound like `f64::MAX` 

This PR "blocks" zoom if to big


Linked to
- comment in
https://github.com/emilk/egui/pull/4637#issuecomment-2154848767
- #3462
2024-06-26 16:34:34 +02:00
Emil Ernerfeldt fee6719f99
Bug fix: report latest area size in `Area::show` response (#4710)
Fixes a problem where menu popups would sometimes move after the first
frame (glitch)
2024-06-26 16:19:11 +02:00
Emil Ernerfeldt 93d458bb68 Clarify PR template wording 2024-06-26 09:00:23 +02:00
Emil Ernerfeldt 42b9491364 Fix docstring 2024-06-26 09:00:11 +02:00
Colin Cai d30f79db60
Fix: Menu popups and tooltips don't respect layer transforms (#4708)
The menu buttons, combo box menus, and tooltips don't take layer
transforms into account when placing their popups, resulting in popups
being placed in the wrong location.

This PR makes the popups take layer transforms into account,
transforming the positions before displaying them on screen. I
implemented this fix for menu buttons, combo boxes, and tooltips; let me
know if there's anything I missed.
Scaling of the popups is purposefully ignored for now. Personally, I
think popup scaling isn't necessary but if it is required I can
implement it (also it would require doing more invasive things to the
code and I want to keep this as simple as possible.)

Before the fix: (with a modified version of the "Pan Zoom" web demo)
<video
src=https://github.com/emilk/egui/assets/104604363/a2d79757-c410-4815-8159-b64d6bd668ee>

After:
<video
src=https://github.com/emilk/egui/assets/104604363/48f8b1d1-d30f-44bf-961f-f10b85964a92>

The frame delay seems to be unavoidable unless we can move the popups
_after_ the layer transform is set (or apply the transforms to the popup
during painting). I think this would be better implemented once the
menu/popup/tooltip unification is done (#4669).
2024-06-26 08:11:31 +02:00
Emil Ernerfeldt 10571e9da5
`eframe::Result` is now short for `eframe::Result<()>` (#4706) 2024-06-25 13:31:42 +02:00
Emil Ernerfeldt 07735a6465
Fix: respect existing text layout wrap settings in Label (#4704)
* Broke in github.com/emilk/egui/pull/4556
* Closes https://github.com/emilk/egui/issues/4701
2024-06-25 10:15:04 +02:00
Emil Ernerfeldt 5a6d68c5f6 Fix "looking for maintainer" link 2024-06-25 09:31:56 +02:00
Emil Ernerfeldt db811847c0 Add "Looking for maintainer" to `egui_plot` docs and README.md
Linking to https://github.com/rerun-io/rerun/issues/6629
2024-06-25 09:26:44 +02:00
Emil Ernerfeldt db8db50bf3
Improve backtraces when hovering widgets with modifiers pressed (#4696)
A useful debug-feature in egui is pressing down all modifiers keys and
hovering any widget to see its backtrace (only in `dev` builds).
Unfortunately this is incompatible with `panic="abort"`, something I
just now discovered.

So I removed `panic="abort"` from `Cargo.toml` for `dev` builds. If the
backtrace returns empty-handed, I also suggests this as a fix to the
user. Finally, I cleaned up the backtraces a bit, making them slightly
shorter and more readable.
2024-06-23 17:03:42 +02:00
YgorSouza b1dc059ef3
Allow setting a layer as a sublayer of another (#4690)
When the layers are reordered at the end of the frame, the sublayers are
placed directly above their respective parents. This allows having Areas
inside Windows, e.g., for the pan-zoom container.

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

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-06-23 12:43:46 +02:00
zkldi 8cef6fc872
doc(emath): Add `top_left` as an alias for `left_top`, etc. (#4689)
# What

Adds `#[doc(alias = "top_left")]` as an alias for `left_top`, and so on
for `right_top`, `right_bottom`, `left_bottom`.

# Why

Extremely minor doc-only change, but I keep going to type "top left" to
look for the top left of a rectangle.
I'm unsure whether this is just a british-english thing or an
english-in-general thing, but `top left corner` is far more common than
`left top corner`.
These doc aliases don't conflict with anything, and mean that
rust-analyzer will suggest the correct function when I search for the
wrong thing.

This improves ergonomics and discoverability in my opinion, even if not
by much.
2024-06-23 11:50:35 +02:00
Matt Keeter d7ccf4d341
Add `Key::Quote` (#4683)
* Part of https://github.com/emilk/egui/issues/3653

<!--
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 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 was surprising to me that this key wasn't sending `Event::Key` events
(only `Event::Text`), so I added a `Key` for it.

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-06-23 11:36:32 +02:00
Emil Ernerfeldt 44f49713eb
Add an input event history tracker to the egui demo lib (#4693)
This is great for testing how e.g. keyboard events are seen by egui:


![image](https://github.com/emilk/egui/assets/1148717/b2187060-6533-439c-9f43-fc49b8213c28)


* Relevant: https://github.com/emilk/egui/issues/3653
2024-06-23 11:34:38 +02:00
Emil Ernerfeldt fb4c6cc619
Put all `egui_demo_lib` tests into their own files in their own folder (#4691) 2024-06-23 10:53:04 +02:00
YgorSouza 2c00cb3991
Fix hello_world_par example on Linux (#4684)
This example does not use the default features from eframe in order to
avoid accesskit, which panics when run from multiple threads, so it must
manually enable the other default features in order to compile correctly
on Linux.

* Closes <https://github.com/emilk/egui/issues/4682>
2024-06-21 10:09:30 +02:00
Colin Cai cd3e9ea5b6
Fix: `Response::hover_pos` returns incorrect positions with layer transforms (#4679)
<!--
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 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!
-->

When layer transforms are present, the `Response::hover_pos` function in
egui returns `transform * pos` instead of `transform.inverse() * pos`.
This is incorrect and isn't consistent with [how egui calculates other
interaction
positions](https://github.com/emilk/egui/blob/master/crates/egui/src/context.rs#L1193).

See:
https://github.com/emilk/egui/blob/master/crates/egui/src/response.rs#L471

This PR fixes this bug, changing `transform` to `transform.inverse()`.
Nothing fancy here, just a one-line change. `scripts/check.sh` runs
successfully.


Below are videos of before and after with a modified version of the web
demo. I added another entry after
https://github.com/emilk/egui/blob/master/crates/egui_demo_lib/src/demo/pan_zoom.rs#L108
with a debug rectangle drawn at the return value of `hover_pos`:
```rust
(
    egui::Pos2::new(120.0, 120.0),
    Box::new(|ui, _state| {
        let response =
            ui.allocate_response(egui::Vec2::splat(128.0), egui::Sense::hover());
        ui.painter().rect_filled(
            egui::Rect::from_center_size(
                response.hover_pos().unwrap_or_default(),
                egui::Vec2::splat(8.0),
            ),
            egui::Rounding::ZERO,
            egui::Color32::DEBUG_COLOR,
        );
        response
    }),
),
```

Without the fix:

https://github.com/emilk/egui/assets/104604363/241cfcab-88ab-459b-8f4d-3367da3aa392

With the fix:

https://github.com/emilk/egui/assets/104604363/e52a7263-44c7-42c1-be46-1ecadc025625
2024-06-20 10:43:51 +02:00
Emil Ernerfeldt 8ac1d613fc
Abort drags when pressing escape key (#4678)
This is useful to undo a drag-and-drop, for instance
2024-06-19 17:00:10 +02:00
rustbasic d9c5fb04ae
Fix dragging of `custom_window_frame` example on Windows (#4656)
* Related #4592 
* Closes #4647 

Fix dragging of custom_window_frame on Windows (re-edited)
2024-06-19 16:19:41 +02:00
JustFrederik 52a8e11764
Gif support (#4620)
* Previous PR: #3951 
* Closes #4489

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-06-19 14:05:05 +02:00
Emil Ernerfeldt 902b4d960d Add `Rect::from_pos` 2024-06-19 11:27:33 +02:00
Emil Ernerfeldt 159f8360fa
Fix doclinks in egui-wgpu docs (#4677) 2024-06-19 11:26:26 +02:00
Emil Ernerfeldt d23742cdb1
Make sure contents of a panel don't overflow (#4676)
* Closes https://github.com/emilk/egui/issues/4475
2024-06-19 10:41:01 +02:00
Emil Ernerfeldt 598dd53059
Fix buggy interaction with widgets outside of clip rect (#4675)
This fixes a bug which sometimes would make it possible to interact with
widgets that were outside the parent clip_rect.

Interaction with a widget is done with the `interact_rect`, which is the
intersection of the widget rect and the parent clip rect. If these
rectangles are disjoint (the widget is outside the parent clip rect),
this results in a _negative rectangle_ (a rectangle with a negative
width and/or height). The distance tests for negative rectangles were
broken, causing the bug.

* This is part of solving https://github.com/emilk/egui/issues/4475
* It is also likely this would have solved
https://github.com/emilk/egui/issues/4349 (which now has another fix for
it)


### Breaking changes
`Rect::distance_to_pos`, `distance_sq_to_pos`, `signed_distance_to_pos`
now all return `f32::INFINITY` if the rectangle is negative.
2024-06-19 10:21:54 +02:00
Emil Ernerfeldt 00ac5b2015 Add clippy lint `match_bool` 2024-06-18 23:45:25 +02:00
Joe Sorensen dd52291af4
Make `Debug` format of `Vec2/Pos2/Rot2` respect user precision (#4671)
* closes #4665

pretty self explanatory, i opted for 3 instead of 2 since i think that's
what display does
2024-06-18 23:03:23 +02:00
n4n5 44d7aab53d
egui_plot: use `f64` for translate (#4637)
<!--
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 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!
-->

Can fix translating with high zoom out
https://github.com/emilk/egui/issues/3462



* Maybe related to https://github.com/emilk/egui/issues/3656
2024-06-18 22:55:08 +02:00
Owen Diehl 413843dd7c
Make sure to call `raw_input_hook` on web (#4646)
## What's new
* Extends @varphone's excellent `raw_input_hook` idea from
https://github.com/emilk/egui/pull/4008 to `web/app_runner`.

## Details
Debugging this locally after my app's `raw_input_hook` wasn't being
called, I realized it's not in the code path of eframe's web runner,
only the native integration. Below is a toy example running on the web.


https://github.com/emilk/egui/assets/8173478/d470b7e6-d393-4ead-9745-3aafc72ae6bc
2024-06-18 22:37:04 +02:00
Aaron Manning f844873c08
Fix dead link to mycomarkup in easy_mark sample (#4643)
This is a very minor fix, but I noticed the link in the default text was
dead, so I found a link to the same project which works.
2024-06-18 22:36:56 +02:00
YgorSouza 3f53f1738b
Remove special case for 0 in DragValue default formatter (#4639)
* Closes <https://github.com/emilk/egui/issues/4610>
2024-06-18 22:36:42 +02:00
Nathan Adams 87021d3fbd
`egui_extras`: Make `serde` an optional feature (#4641)
<!--
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 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!
-->

All the other crates in egui have serde as an optional dependency -
which is great! But sadly egui_extras unconditionally includes it, which
adds a bunch of code to stuff that may not care for it. This PR gates
serde support behind a new `serde` feature.

This is a breaking change; if that's undesirable then we can add it as a
default feature instead, though that wouldn't match any of the other
crates.
2024-06-18 22:27:48 +02:00
crumblingstatue 49cb62b1ba
Replace `directories-next` dependency with `directories` (#4661)
`directories-next` was created because `directories` was not maintained
at the time. However, `directories` has gotten active maintainership
since, and it has received more updates than `directories-next`.

`directories` also has more recent downloads than its `next`
counterpart, so it might make sense to switch to it, to avoid
unnecessary duplicate dependencies, where a project depends transitively
on both `directories` and `directories-next`.

The main question is whether we depend on any specific behavior from
`directories-next`.
2024-06-18 22:17:21 +02:00
YgorSouza ee3b04ea17
Fix typos (#4640) 2024-06-18 22:10:59 +02:00
Andrew Farkas 3cdb667cd6
Fix typo in docs of `Ui::shrink_height_to_current()` (#4672)
<!--
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 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!
-->
2024-06-18 21:57:19 +02:00
Emil Ernerfeldt 814ad0783c
Update to wgpu 0.20 (#4560)
* this PR reverts https://github.com/emilk/egui/pull/4559
* and re-applies https://github.com/emilk/egui/pull/4433

Before we merge, we're waiting for a wgpu 0.20.1 patch-release of

* https://github.com/gfx-rs/wgpu/pull/5681

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
2024-06-13 15:00:23 +02:00
Emil Ernerfeldt ca36f3df63
Make sure tooltips are interactable (#4649)
…so you can't hover things underneath them.

* Better version of https://github.com/emilk/egui/pull/4648
2024-06-10 14:05:06 +02:00