Commit Graph

3070 Commits

Author SHA1 Message Date
Antoine Beyeler 3258cd2a7f
Fix two `ScrollArea` bugs: leaking scroll target and broken animation to target offset (#4174)
This PR fixes two issues related to `ScrollArea`.

1) When a `ScrollArea` would have `drag_to_scroll` set to `false` (e.g.
because some custom logic is at play or some other reason), it would not
animate to the `target_offset`, effectively making
`Response::scroll_to_me()` ineffective.
2) Single-direction `ScrollArea`s would leak the `scroll_target`'s other
direction. In certain specific circumstances (e.g. an horizontal area
nested in a vertical one, or inversely), this _could_ work as intended,
but in many other cases it could cause unwanted effects. With this PR,
both `scroll_target` directions are consumed by nearest enclosing
`ScrollArea`, regardless of the actually enabled scroll axes.
2024-03-17 17:12:41 +01:00
Emil Ernerfeldt bf7ffb982a
Fix bug parsing url query with escaped & or = (#4172)
I have tested this manually:

<img width="727" alt="Screenshot 2024-03-14 at 19 38 34"
src="https://github.com/emilk/egui/assets/1148717/fa1f6da4-d9e3-4f08-9812-1d61479dfd52">
2024-03-15 06:43:27 +01:00
Jan Procházka c5eaba43cd
Fix crash on `request_animation_frame` when destroying web runner (#4169)
Previously, any frames in flight (`requestAnimationFrame`) on web were
not being cancelled (`cancelAnimationFrame`) when `WebRunner::destroy`
was called. If a user called `destroy`, then immediately removed the
canvas from the DOM, eframe could panic with a "failed to find (canvas)
element by id" error message.

This PR changes two things:
- The canvas element is directly referenced everywhere it's needed
instead of being looked up by `canvas_id`[^1]
- The RAF handle is stored in `WebRunner` and `cancelAnimationFrame` is
called on it inside of `WebRunner::destroy`[^2]

[^1]: The WebGL/WGPU backends were already holding onto the canvas (and
associated GPU context), so the change is just converting all the
`get_element_by_id` lookups to retrieve the canvas from the web runner
handle.

[^2]: There is only ever one frame in flight, so we store it directly as
a scalar field.
2024-03-14 10:26:34 +01:00
Emil Ernerfeldt 00e8ce6d7e Reduce log-level of processing ViewportCommands 2024-03-14 10:18:07 +01:00
lomekragow 47fbce665a
Add `get_proc_address` in CreationContext (#4145)
<!--
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 cranky`.
* 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/4144>
2024-03-13 13:07:27 +01:00
Emil Ernerfeldt 0afbefc884
Improve logic for when submenus are kept open (#4166)
* Closes https://github.com/emilk/egui/issues/2853
* Closes https://github.com/emilk/egui/issues/4101
* Reverts parts of https://github.com/emilk/egui/pull/3055
2024-03-13 12:32:54 +01:00
rustbasic f019032033
TextEdit: fix crash when hitting SHIFT + TAB around non-ASCII text (#3984)
* Closes #3846 
* Closes #3878

Dear emilk.

Leaving aside other function,
I think this is all you need to fix to patch the panic that occurs when
Shift + TAB.

Thank you, emilk.
2024-03-12 11:21:33 +01:00
Vincent Alsteen c87bcc4bcc
Remove unnecessary allocation in `RepaintCause::new` (#4146)
Hi!

I'm using egui for the UI of a VST3/Clap plugin, and this kind of
environment is rather picky on performance. I use
[assert_no_alloc](https://crates.io/crates/assert_no_alloc) to make sure
the audio thread is never allocating. The audio thread may request a
repaint of the GUI tho, and this is where a saw that it may allocate
when tracing the repaint reason.

Turns out it's not necessary, `Location::caller` is `'static`, so using
a `&'static str` instead of a `String` in `RepaintCause::file` will just
work, so this PR just does that.
2024-03-12 11:15:13 +01:00
ming08108 efc0a6385c
Update kb modifiers from web mouse events (#4156)
Update modifier state from web mouse events. This allows modifiers to be
correctly updated when the window is not in focus but the mouse is still
moving over the window.
2024-03-12 11:14:40 +01:00
CrazyCraftix 4a330de53d
Fix scaling of rounded corners for rect shape (#4152) (#4161)
When scaling an `egui::Shape` of variant `Rect` using the new
`transform` function, corner rounding isn't taken into account.

The fix is to multiply the rounding by the scaling factor.

* Closes <https://github.com/emilk/egui/issues/4152>
2024-03-12 11:14:24 +01:00
Emil Ernerfeldt d0a6bbf2b8
Fix style of disabled widgets (#4163)
* Broke in https://github.com/emilk/egui/pull/4026/files

The `Response::sense` for `enabled: false` widgets was wrong, leading to
the wrong widget style.
2024-03-12 11:14:12 +01:00
Varphone Wong 827fdefd83
eframe: Added `App::raw_input_hook` allows for the manipulation or filtering of raw input events (#4008)
# What's New

* eframe: Added `App::raw_input_hook` allows for the manipulation or
filtering of raw input events
   A filter applied to raw input before [`Self::update`]
This allows for the manipulation or filtering of input events before
they are processed by egui.
This can be used to exclude specific keyboard shortcuts, mouse events,
etc.
Additionally, it can be used to add custom keyboard or mouse events
generated by a virtual keyboard.
* examples: Added an example to demonstrates how to implement a custom
virtual keyboard.


[eframe-custom-keypad.webm](https://github.com/emilk/egui/assets/1274171/a9dc8e34-2c35-4172-b7ef-41010b794fb8)
2024-03-12 11:06:08 +01:00
Emil Ernerfeldt 00a399b2f7
A `Window` can now be resizable in only one direction (#4155)
For instance: `Window::new(…).resizable([true, false])` is a window that
is only resizable in the horizontal direction.

This PR also removes a hack added in
https://github.com/emilk/egui/pull/3039 which is no longer needed since
https://github.com/emilk/egui/pull/4026
2024-03-11 09:29:48 +01:00
Varphone Wong a93c6cd5d2
`egui`: Fixed the incorrect display of the Window frame with a wide border or large rounding (#4032)
Currently, the Window frame is displayed incorrectly when using a wide
border or large rounding.

* Closes #3806
* Closes #4024 
* Closes #4025 

* Screencast of egui demo app (emilk:master)


[window-frame-bug.webm](https://github.com/emilk/egui/assets/1274171/391f67fa-ae6f-445a-8c64-1bb575770127)

* Screencast of egui demo app (varphone:hotfix/window-custom-frame)


[window-frame-fixed.webm](https://github.com/emilk/egui/assets/1274171/1953124e-9f7a-4c2d-9024-5d2eece6b87c)
2024-03-08 10:32:23 +01:00
Varphone Wong 1f414c059d
`egui_extras`: Fixed handling of `file://` protocol for images (#4107)
* Remove the leading slash from the path if the target OS is Windows.

This is because Windows paths are not supposed to start with a slash.
For example, `file:///C:/path/to/file` is a valid URI, but
`/C:/path/to/file` is not a valid path.

* Use the input URI consistently as the cache key.

Currently, the cache key is inconsistently set as either the path or the
URI, while the forget key is always the URI. This inconsistency should
be resolved.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-03-08 10:24:34 +01:00
Varphone Wong 4d776fd84e
`epaint`: Added `Shape::{scale,translate}` wrappers (#4090)
The `Shape::translate` method has been replaced with `Shape::transform`,
which introduces breaking changes that could negatively impact existing
users.

This patch adds a `Shape::translate` wrapper to prevent these breaking
changes.
2024-03-08 10:07:31 +01:00
rustbasic 385daeb354
Fix IME bug where currently typed characters got copied
* Closes #3730 

Fix IME: Currently typed characters get copied when switching TextEdit
fields
2024-03-08 10:00:28 +01:00
Arnold Loubriat 76411b5d74
Add accessibility to `ProgressBar` and `Spinner` (#4139)
- Introduces `WidgetType::ProgressIndicator` and maps it to the
corresponding AccessKit role.
- A `Spinner` is now exposed as a widget indicating a progress for which
a completion state is not known.
- On the other hand, a `ProgressBar` reports a completion state and can
possibly be labeled. Note that a label is not used if not explicitly
asked by the user, as it would be redundant information. Assistive
technologies prefer the numerical value so they can, for instance, emit
beeps of which the frequency rise as the completion state increase. I
had to call `floor` on the progression as it seems all the ATs I tested
would round the value, hence reporting something different than what is
displayed on the label.
2024-03-08 09:54:21 +01:00
Antoine Beyeler a1d5145c16
Hide hover UI when showing the context menu (#4138)
This PR hides the hover UI for a given widget whenever a corresponding
context menu is opened.

Fixes:
- https://github.com/rerun-io/rerun/issues/5310
2024-03-06 16:30:20 +01:00
Cameron Taggart ca1f453c47
add webgpu feature by default for wgpu feature of eframe (#4124)
Fix #4123. Looks like it was caused by #3875.
2024-03-04 20:20:03 +01:00
Emil Ernerfeldt 18eeb01f57
Quickly animate scroll when calling `ui.scroll_to_cursor` etc (#4119)
Uses ease-in-ease-out interpolation, with a time between 0.1s and 0.3s,
depending on the distance needed to scroll.


![smooth-scroll-to-target](https://github.com/emilk/egui/assets/1148717/c5c8556d-476b-4597-842b-aa0e5927fbb9)
2024-03-04 20:00:13 +01:00
Emil Ernerfeldt e29022efc4
`Area::new` now takes an `Id` by argument (#4115)
This makes it more explicit that you are responsible for assigning a
globally unique `Id`.
2024-02-29 15:34:16 +01:00
Emil Ernerfeldt 86d7f296ae
Give each menu `Area` an id distinct from the id of what was clicked (#4114)
* Closes https://github.com/emilk/egui/issues/4113

Previously the `Id` of the menu `Area` was using the same id as the
thing that was clicked (i.e. the button opening menu), which lead to id
clashes
2024-02-29 14:18:06 +01:00
Georg Weisert e8af6f38fc
Serde feature: Add serde derives to input related structs (#4100)
We plan to store input data for creating automated tests, hence the need
for more serde derives on input related structs.

---------

Co-authored-by: Georg Weisert <georg.weisert@freshx.de>
2024-02-26 13:33:43 +01:00
Emil Ernerfeldt 5cf99c6308 Add some profile scopes to handle_platform_output 2024-02-21 16:25:28 +01:00
0Qwel 23e8312fc0
Convenience const fn for Margin, Rounding and Shadow (#4080)
I often write constants at the top of my widget files, as a "config". I
kept writing stuff like that :
```rust
const DEFAULT_INNER_MARGIN: Margin = Margin { left: 17., right: 17., top: 7., bottom: 7. };
```
So I prefixed constructors for `Margin`, `Rounding` and `Shadow` const.
No code was changed.

I also added a `Shadow::new()` for similar reasons.
2024-02-21 16:20:26 +01:00
Mike Tsao cdb7d153dc
`ui.dnd_drop_zone()` now returns `InnerResponse`. (#4079)
* Closes <https://github.com/emilk/egui/issues/4059>

```bash
$ ./scripts/check.sh 
[...]
+ echo 'All checks passed.'
```
2024-02-21 16:20:14 +01:00
Giantblargg b8048572e8
Add API for raw mouse motion (#4063)
Raw mouse movement is unaccelerated and unclamped by screen boundaries,
and does not relate to any position on the screen.
It is useful in certain situations such as draggable values and 3D
cameras, where screen position does not matter.


https://github.com/emilk/egui/assets/1700581/1400e6a6-0573-41b9-99a1-a9cd305aa1a3

Added `Event::MouseMoved` for integrations to supply raw mouse movement.
Added `Response:drag_motion` to get the raw mouse movement, but will
fall back to delta in case the integration does not supply it.

Nothing should be breaking, but third-party integrations that can send
`Event::MouseMoved` should be updated to do so.

Based on #1614 but updated to the current version, and with better
fallback behaviour.

* Closes #1611
* Supersedes #1614
2024-02-20 18:00:39 +01:00
Antoine Beyeler 74891cac2f
egui_plot: fix panic when the base step size is set to 0 (#4078)
This can happen e.g. when the user forces some axis range to (0.0, 0.0)
like in rerun-io/rerun#5239
2024-02-20 16:26:47 +01:00
wangxiaochuTHU ca8eeb8621
Add `ColorImage::from_gray_iter` (#3536)
Add an alternative method for creating a [`ColorImage`] that accepts
`Iterator` as the argument. It can be useful when `&[u8]` is not
available but the iterator is.

<!--
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.
* 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 cranky`.
* 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 you PR, but my time is limited!
-->

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-02-20 15:29:23 +01:00
Emil Ernerfeldt 4fc0c49a6b
Fix interaction with widgets inside selectable rows of `Table` (#4077)
* Closes https://github.com/emilk/egui/issues/4047
2024-02-20 14:50:13 +01:00
Emil Ernerfeldt 9096abdeec
Support interacting with the background of a `Ui` (#4074)
Add `Ui::interact_bg` which interacts with the ui _behind_ any of its
children.
2024-02-20 14:39:26 +01:00
Emil Ernerfeldt a33ae64785
Fix: assign a different id to each table cell, avoiding id clashes (#4076)
Each cell in a table now has a `Ui` with a unique `Id` based on the row
and column.

This avoids Id-clashes, e.g. when putting a `CollapsingHeader` in a
table cell.
2024-02-20 13:35:19 +01:00
vincent-sparks 68b3ef7f6b
Fix: images with background color now respects rounding (#4029)
Co-authored-by: Vincent Sparks <vincent@spacestation.blue>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-02-18 13:25:11 +01:00
Emil Ernerfeldt ca8c8792c2
New widget interaction logic (#4026)
* Closes https://github.com/emilk/egui/issues/3936
* Closes https://github.com/emilk/egui/issues/3923
* Closes https://github.com/emilk/egui/pull/4058

The interaction code is now done at the start of the frame, using stored
`WidgetRect`s from the previous frame.

The intention is that the new interaction code should be more accurate,
making it easier to hit widgets, and better respecting the rules of
overlapping widgets.

There is a new `style::Interaction::interact_radius` controlling how far
away from a widget the cursor can be and still hit it. This helps big
fat fingers hit small widgets on touch screens.

This PR adds a new `Context::read_response` which lets you read the
`Response` of a `Widget` _before_ you create the widget. This can be
used for styling, or for reading the result of an interaction early (to
prevent frame-delay) for a widget you add late (so it is on top of other
widgets).

# ⚠️ BREAKING CHANGES
`Memory::dragged_id`, `Memory::set_dragged_id` etc have been moved to
`Context`.
The semantics for `Context::dragged_id` is slightly different: a widget
is not considered dragged until egui it is sure this is not a
click-in-progress. For a widget that is only sensitive to drags, that is
right away, but for widgets sensitive to both clicks and drags it is not
until the mouse has moved a certain distance.

# TODO
* [x] Fix panel resizing
* [x] Fix scroll hover weirdness
* [x] Fix Resize widget
* [x] Fix drag-and-drop
* [x] Test all of egui_demo_app
* [x] Change `is_dragging` API
* [x] Consistent naming of start/stop or begin/end drag
* [x] Test `egui_tiles`
* [x] Test Rerun
* [x] Document
* [x] Document breaking changes in PR description
* [x] Test one final time

# Saving for a later PR
* [ ] Fix https://github.com/emilk/egui/issues/4047
* [ ] Specify what the response order for e.g. `ui.horizontal` is

I think both these can be fixed if each `Ui` registers themselves as a
`WidgetRect`, with the possibility to interact with it later, as if the
interaction was under all widgets on top of it.
2024-02-17 15:48:23 +01:00
Emil Ernerfeldt 2eaaf5fd6e Fix drag-and-drop preview following #3906 2024-02-17 15:15:36 +01:00
Francis Chua 069d7a634d
Add layer transforms, interaction in layer (#3906)
⚠️ Removes `Context::translate_layer`, replacing it with a sticky
`set_transform_layer`

Adds the capability to scale layers.
Allows interaction with scaled and transformed widgets inside
transformed layers.

I've also added a demo of how to have zooming and panning in a window
(see the video below).

This probably closes #1811. Having a panning and zooming container would
just be creating a new
`Area` with a new id, and applying zooming and panning with
`ctx.transform_layer`.

I've run the github workflow scripts in my repository, so hopefully the
formatting and `cargo cranky` is satisfied.

I'm not sure if all call sites where transforms would be relevant have
been handled. This might also be missing are transforming clipping
rects, but I'm not sure where / how to accomplish that. In the demo, the
clipping rect is transformed to match, which seems to work.


https://github.com/emilk/egui/assets/70821802/77e7e743-cdfe-402f-86e3-7744b3ee7b0f

---------

Co-authored-by: tweoss <fchua@puffer5.stanford.edu>
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-02-17 11:02:56 +01:00
Emil Ernerfeldt f7fc3b0154 Change GLFW integration recommendation to egui_gl_glfw 2024-02-16 12:53:17 +01:00
Antoine Beyeler d468d43dad
Add `Response::paint_debug_info()` to make it easy to visualize a widget's id and state (#4056)
This PR adds a new `paint_debug_info()` debug method to `Response` in
order to draw the response's `Rect`, it's id, and some of its state
(active, hovered) via a color code:


![Export-1708083028898](https://github.com/emilk/egui/assets/49431240/ce050448-3f11-4bb1-8959-417d106a89ac)
2024-02-16 12:45:30 +01:00
Emil Ernerfeldt a0473c5a0a Update `iana-time-zone` 2024-02-16 11:11:18 +01:00
Emil Ernerfeldt 6fbf7fe566
Update `ehttp` to 0.5 (#4055) 2024-02-16 10:57:54 +01:00
YgorSouza 2feb1440be
Add `Ui::set_opacity` (#3965)
Closes <https://github.com/emilk/egui/issues/3473>.
2024-02-16 10:39:30 +01:00
YgorSouza 34e8af87d4
Plot widget - allow disabling scroll for x and y separately (#4051)
To be consistent with the zoom and drag options that were added earlier.
2024-02-16 09:23:08 +01:00
Dunfan Lu 62e80c7729
`egui_plot`: Add `sense` option to `Plot` (#4052)
This PR adds a `sense` option to `Plot`.
2024-02-16 09:19:03 +01:00
Emil Ernerfeldt 61b53ae937 Improve error message when using wrong pixels_per_point in tessellate
Closes https://github.com/emilk/egui/issues/4048
2024-02-16 09:15:22 +01:00
Emil Ernerfeldt 3672b150ed Release 0.26.2 - Response.interact/context_menu fix 2024-02-14 10:49:57 +01:00
Antoine Beyeler 0e1bcc2c1c
Avoid interacting twice when not required (#4041)
This PR short-circuits `Response::interact()` when the `Response` has
already been sufficiently "sensed" already. In some circumstance, this
can avoid unnecessarily registering another widget rect that may mask
some other widget.

One such instance is Rerun's `ListItem`. Calling `context_menu()` on its
response would call `interact` and, in turn, mask its sub-widget
(collapsing triangle, show/hide buttons, etc.).
2024-02-14 09:07:33 +01:00
Emil Ernerfeldt d99fabaef5
Add another check to Windows CI (#4038)
To see if we can catch the problem in
https://github.com/emilk/egui/pull/4037
2024-02-13 12:35:49 +01:00
Varphone Wong 1970e2ccb1
`eframe`: Add `winuser` feature to `winapi` to fix unresolved import (#4037)
After merging PR #4036, build errors occurred in eframe-related
applications:

```log
error[E0432]: unresolved import `winapi::um::winuser`
   --> crates\eframe\src\native\app_icon.rs:83:9
    |
83  |     use winapi::um::winuser;
    |         ^^^^^^^^^^^^^^^^^^^ no `winuser` in `um`
    |
note: found an item that was configured out
   --> C:\Users\Varphone\.cargo\registry\src\index.crates.io-6f17d22bba15001f\winapi-0.3.9\src\um\mod.rs:290:37
    |
290 | #[cfg(feature = "winuser")] pub mod winuser;
    |                                     ^^^^^^^
    = note: the item is gated behind the `winuser` feature

For more information about this error, try `rustc --explain E0432`.
error: could not compile `eframe` (lib) due to previous error
warning: build failed, waiting for other jobs to finish...
```
2024-02-13 12:27:58 +01:00
bu5hm4nn 4875b01de3
`TextEdit`: Change `margin` property to `egui::Margin` type (#3993)
Despite their being an actual `egui::Margin` struct, Textedit has a
`margin()` builder function that supports only `Vec2` types and thereby
only symmetric margins. This PR changes the function to accept
`egui::Margin` type instead making it more congruent with overall egui
logic as well as supporting asymmetric margins.

P.S: I tried to run all checks but I had to modify `./rust-toolchain` to
1.67.0 to get the checks to run on macOS.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-02-13 10:44:55 +01:00