Commit Graph

3054 Commits

Author SHA1 Message Date
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
Magnus Larsen 7a4ab666b4
Update memoffset to 0.9.0, arboard to 3.3.1, and remove egui_glow's needless dependency on pure_glow's deps (#4036)
<!--
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!
-->

These are the latest versions of memoffset and arboard.

The changes to egui_glow/pure_glow allow downstream crates to not depend
on rwh 0.5, which is only needed for pure_glow (and other projects that
use glutin)

Thanks for your time & work
2024-02-13 10:32:18 +01:00
Emil Ernerfeldt d22ee81ab0 Release 0.26.1 - Bug Fixes 2024-02-11 09:03:09 +01:00
Varphone Wong cd34a47dd6
egui: Fix custom `Window` `Frame`s (#4009)
Fix #4002 


![fixed-#4002](https://github.com/emilk/egui/assets/1274171/cf867d69-87df-46fe-a1e4-ff9a333fe2f2)
2024-02-11 08:56:15 +01:00
Emil Ernerfeldt 12b5d51325 Revert test code in hello_world example 2024-02-10 18:09:41 +01:00
Emil Ernerfeldt 407224746d
Take clip_rect into account when storing widget rects (#4020)
* Bug introduced in https://github.com/emilk/egui/pull/4013
* Closes https://github.com/emilk/egui/issues/4017

Unfortunately this is a breaking change, since it changes the fields of
`Response`, so can't do a patch-release with this.
2024-02-10 17:28:38 +01:00
Emil Ernerfeldt 132d0ec430
Add `Options::debug_paint_interactive_widgets` (#4018)
This paints the rects of all interactive widgets on each layer.


![image](https://github.com/emilk/egui/assets/1148717/3584c4fb-06ce-43d4-bd7c-c5baf927ddf1)
2024-02-10 13:20:01 +01:00
Emil Ernerfeldt 0bf3056bd7
Fix: `Response.interact_pointer_pos` is `Some` on click and drag released (#4014)
* Closes https://github.com/emilk/egui/issues/3999

In 0.26.0 is was accidentally set to `None` on the frame we got a click
or drag release
2024-02-10 11:21:57 +01:00
Emil Ernerfeldt 5bf44f8850
Fix `Response::interact` and `Ui:interact_with_hovered` (#4013)
These broke in 0.26

* #3989
* #4006
2024-02-10 10:48:00 +01:00
Georg Weisert 808dc0103a
Fix `TextEdit` being too short whenever there is horizontal margin (#4005)
The allocated width is reduced by the horizontal margin inside
`show_content` but the margin is already factored into the content_ui's
rect.
This causes both text and frame (not shown here) to be `2.0 * margin.x`
too short.

Before:

![image](https://github.com/emilk/egui/assets/23122431/6a9a0264-3fc0-48b7-b462-82120ed47fcf)

After:

![image-1](https://github.com/emilk/egui/assets/23122431/ffef9edc-d571-4fca-96cf-c2e42e2f0057)
(*The blue rect is the TextEdit's (expected) final size.)

Co-authored-by: Georg Weisert <georg.weisert@freshx.de>
2024-02-10 09:36:24 +01:00
njust 310d85a7fa
egui demo: Fix space reserved for source code link (#3983)
Clip the cell of the source code link to prevent the strip from growing
infinitely if the reserved size for the link is not sufficient.


![image](https://github.com/emilk/egui/assets/2380253/0cf214fc-addc-4212-90fc-d68834c1cfe7)

Closes <https://github.com/emilk/egui/issues/3980>.
2024-02-10 09:17:12 +01:00
Emil Ernerfeldt 800eff6994
Improve panic message in egui-wgpu when failing to create buffers (#3986)
Example:

> thread 'main' panicked at 'Failed to create staging buffer for vertex
data. Vertex count: 10 011 232. Required vertex buffer size:
200 224 640. Actual size 349 450 240 and capacity: 349 450 240 (bytes)
2024-02-10 09:15:30 +01:00
Emil Ernerfeldt 410957870b
Update to document-features 0.2.8 (#4003)
Solves a build issue: https://github.com/rerun-io/rerun/issues/5113
2024-02-10 09:13:25 +01:00
YgorSouza 1bc70b20b1
Make `on_disabled_hover_ui` respect `tooltip_delay` (#4012)
* Closes <https://github.com/emilk/egui/issues/3997>
2024-02-10 09:07:21 +01:00
Oscar Gustafsson 15370bbea0
Add F21 to F35 key bindings (#4004)
<!--
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/3990>

`winit` supports up to F35, so thought it was better to just add them
all.
2024-02-08 10:57:32 +01:00
Magnus Larsen 21f08afcbb
egui_glow: Only disable sRGB framebuffer on supported platforms (#3994)
This solves a GL_INVALID_ENUM error common on Windows (occurs on my
Windows 10 machine with a GTX 1070 Ti).

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

ARB_framebuffer_SRGB is entirely unsupported on WebGL, hence why latest
egui (master branch) doesn't try to disable SRGB framebuffers on wasm32
and this PR's code doesn't even check for ARB_framebuffer_sRGB on
wasm32.

*  For <servo/servo#30782>
2024-02-08 08:54:14 +01:00
Varphone Wong 377f86efb5
egui: Fixed window title bar incorrect handling spacing (#3995)
Currently, the window title bar does not correctly handle the
`item_spacing` and `window_margin`.

* Video snapshot on changing the `item_spacing` and `window_margin`
(master)


[egui-demo-app-incorrect.webm](https://github.com/emilk/egui/assets/1274171/a4e32d43-69b5-44be-a4c3-97b0533147ca)

* Video snapshot on changing the `item_spacing` and `window_margin`
(feature/fix-window-title-bar)


[egui-demo-app-fixed.webm](https://github.com/emilk/egui/assets/1274171/42bbc210-a1f3-4e0a-ab71-d068e58e0e35)
2024-02-07 08:52:46 +01:00