Commit Graph

2961 Commits

Author SHA1 Message Date
Emil Ernerfeldt 21253d844e
Postpone call to get_current_texture (#3914)
This should help slightly with CPU/GPU parallelism when vsync is on.

I also return the time spent on vsync, which can help users figure out
how much CPU wall-time was used on non-vsync stuff
2024-01-29 18:06:21 +01:00
Emil Ernerfeldt 1d1b07c6b2
Turn off text wrapping by default in combo-box popups (#3912)
This trips up a lot of users
2024-01-29 16:09:54 +01:00
YgorSouza 13b59fb0d4
Fix typos (#3899) 2024-01-29 11:16:10 +01:00
Emil Ernerfeldt abd028bad3
Add drag-and-drop APIs with payloads storage (#3887)
* Closes https://github.com/emilk/egui/issues/3882

This adds several methods to make drag-and-drop more ergonomic in egui.

In particular, egui can now keep track of _what_ is being dragged for
you (the _payload_).

Low-level:
* `egui::DragAndDrop` hold the payload during a drag

Mid-level:
* `Response::dnd_set_drag_payload` sets it for drag-sources
* `Response::dnd_hover_payload` and `Response::dnd_release_payload`
reads it for drop-targets

High-level:
* `ui.dnd_drag_source`: make a widget draggable
* `ui.dnd_drop_zone`: a container where things can be dropped

The drag-and-drop demo is now a lot simpler:


https://github.com/emilk/egui/blob/emilk/drag-and-drop/crates/egui_demo_lib/src/demo/drag_and_drop.rs

---------

Co-authored-by: Antoine Beyeler <abeyeler@ab-ware.com>
2024-01-29 11:14:18 +01:00
Andreas Reich 40ed503ebd
Re-try adapter creation if creation with WebGPU enabled fails and WebGL was enabled. (#3895)
* Filed this in relation to the changes here
https://github.com/gfx-rs/wgpu/issues/5142
* Fixes https://github.com/rerun-io/rerun/issues/4915

Draft until fully confirmed this works on Linux Chrome
2024-01-29 11:04:05 +01:00
Emil Ernerfeldt 5d0bc2bf7d
egui_plot: customizable spacing of grid and axis label spacing (#3896)
This lets users specify the spacing of the grid lines and the axis
labels, as well as when these start to fade out.

New:
* `AxisHints::new_x/new_y` (replaces `::default()`)
* `AxisHints::label_spacing`
* `Plot::grid_spacing`
2024-01-26 13:36:49 +01:00
Emil Ernerfeldt 6b0782c96b
Improve `Frame` API to allow picking color until after adding content (#3889)
Previously the `Frame` API only supported picking colors once, and then
adding widgets.

But what if you want to add widgets first, and THEN pick the colors for
the frame? Now you can!


```rs
let frame = Frame::default().inner_margin(4.0).begin(ui);
{
    frame.content_ui.label("Inside the frame");
    frame.content_ui.label("This too");
}
let response = frame.allocate_space(ui);
if response.hovered() {
    frame.frame.stroke = Stroke::new(2.0, Color32::WHITE);
}
frame.paint(ui);
```
2024-01-25 19:59:12 +01:00
Emil Ernerfeldt a815923717
Improve `Response.dragged`, `drag_started` and `clicked` (#3888)
If a widgets sense both clicks and drags, we don't know wether or not a
mouse press on it will be a short click or a long drag.

With this PR, `response.dragged` and `response.drag_started` isn't true
until we know it is a drag and not a click.
If the widget ONLY senses drags, then we know as soon as someone presses
on it that it is a drag.
If it is sensitive to both clicks and drags, we don't know until the
mouse moves a bit, or stays pressed down long enough.

This PR also ensures that `response.clicked` and is only true for
widgets that senses clicks.
2024-01-25 17:28:53 +01:00
Emil Ernerfeldt d190df7d25
Register callbacks with `Context::on_begin_frame` and `on_end_frame`. (#3886)
This can be useful for creating simple plugins for egui.

The state can be stored in the egui data store, or by the user.

An example plugin for painting debug text on screen is provided.
2024-01-25 12:33:42 +01:00
rustbasic e3cfcf7d2e
eframe: don't call `App::update` on minimized windows (#3877)
* Closes #3321
2024-01-25 10:15:38 +01:00
Emil Ernerfeldt 5388e65623
Smooth scrolling (#3884)
This adds smooth scrolling in egui. This makes scrolling in a
`ScrollArea` using a notched mouse wheel a lot nicer.

`InputState::scroll_delta` has been replaced by
`InputState::raw_scroll_delta` and `InputState::smooth_scroll_delta`.
2024-01-24 16:40:20 +01:00
Garoven 200051d5d8
Fix Android crash on resume with Glow backend (#3867)
Addition for <https://github.com/emilk/egui/pull/3847>
In previous one i only fixed crash occurring with Wgpu backend. This
fixes crash with Glow backend as well.
I only tested this change with android so most things i changed are
behind ```#[cfg(target_os = "android")]```.

Both fixes are dirty thought. As
<https://github.com/emilk/egui/pull/3172> says that "The root viewport
is the original viewport, and cannot be closed without closing the
application.". So they break rules i guess? But i can't think about
better solution for now.

Closes <https://github.com/emilk/egui/issues/3861>.
2024-01-24 15:50:21 +01:00
Emil Ernerfeldt 5e7fa46451 Fix text selection crashes
Closes https://github.com/emilk/egui/issues/3881
2024-01-24 15:47:44 +01:00
Emil Ernerfeldt 41aad74552
Cross-widget text select (#3870)
* Closes https://github.com/emilk/egui/issues/3816


![cross-widget-text-selection](https://github.com/emilk/egui/assets/1148717/5582b9d2-8b04-47b7-9637-f48e44064a70)

Turn off with `style.interaction.multi_widget_text_select`.

There is an API for this in `LabelSelectionState`, but it's pretty
bare-bones.

This became really hairy implementation-wise, but it works decently
well.

# Limitations
* Drag-select to scroll doesn't work
* A selection disappears if you scroll past one of its end-points
* Only the text of labels and links are selectable
 
## TODO
* [x] An option to turn it off
* [x] An API for querying about the selected text, and to deselect it.
* [x] Scrolling past selection behaves weird
* [x] Shift-click to select a range
2024-01-24 15:45:22 +01:00
Bruno bcf032a08f
Allow read access to shapes added to painter this frame (#3866)
Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-01-24 13:32:10 +01:00
Emil Ernerfeldt 3a8e2348a5
`egui-wgpu`: turn off the default features of `wgpu` (#3875)
This makes all `wgpu` features opt-in for `egui-wgpu` users.

For `eframe`, I opted to enable some `wgpu` features so users can still
use `eframe` without having to also opt-in to extra ewgpu features
(eframe is batteries-included).
2024-01-24 09:43:40 +01:00
Emil Ernerfeldt 4d1a736016
Add `WgpuConfiguration::desired_maximum_frame_latency` (#3874)
Setting `desired_maximum_frame_latency` to a low value should
theoretically lead to lower latency in winit apps using `egui-wgpu`
(e.g. in `eframe` with `wgpu` backend).

* Replaces https://github.com/emilk/egui/pull/3714
* See also https://github.com/gfx-rs/wgpu/pull/4899

----

It seems like `desired_maximum_frame_latency` has no effect on my Mac. I
lowered my monitor refresh-rate to 30Hz to test, and can see no
difference between `desired_maximum_frame_latency` of `0` or `3`.

Before when experimenting with changing the global `DESIRED_NUM_FRAMES`
in `wgpu` I saw a huge difference, so I wonder what has changed.

I verified that `set_maximum_drawable_count` is being called with either
`1` or `2`, but I perceive no difference between the two.
2024-01-24 09:36:17 +01:00
Antoine Beyeler 11c89125f7
Add some drag-and-drop-related APIs in `Response` and `Memory` (#3876)
This PR adds the following APIs, which I found to be missing while
working on https://github.com/rerun-io/rerun/pull/4879:

- `Response::decidedly_dragged()`: tests if the corresponding widget is
being decidedly dragged
- `Memory::dragged_id()`: returns the ID of the dragged widget, if any
2024-01-24 09:32:38 +01:00
Brian Janssen 2c837d25a2
`egui_winit`: Allow getting the `clipboard` and `allow_ime` state (#3724)
The `egui_winit::State` contains both the `clipboard` and `allow_ime`,
but these are both private fields. In our implementation we use
`egui_winit` to do most of the lifting, but it would come really in
handy if we could access these values.

Instead of making the fields `pub` we opted for separate get/set
functions, that way calling side can't freely replace any of the values
fully and it's more in line with the style of the rest of the codebase.

---------

Co-authored-by: Marijn Suijten <marijn@traverseresearch.nl>
Co-authored-by: Marijn Suijten <marijns95@gmail.com>
2024-01-23 12:49:28 +01:00
Emil Ernerfeldt 2f9a4ca6e8
Make `egui_plot::PlotMemory` public (#3871)
This allows users to e.g. read/write the plot bounds/transform before
and after showing a `Plot`.
2024-01-23 09:47:47 +01:00
Emil Ernerfeldt aa67d3180b
Add `Context::debug_text` (#3864)
This is a very easy way to show some text under the mouse pointer:

```rs
ctx.debug_text("foo");
```
2024-01-22 17:04:58 +01:00
Emil Ernerfeldt 31cc31a67b
Add `Align2::anchor_size` (#3863) 2024-01-22 16:47:50 +01:00
Emil Ernerfeldt 9fb83d3541 Use a selectable label for syntax-highlighted text in egui_extras 2024-01-22 14:47:58 +01:00
Emil Ernerfeldt ca6ce2dd92
Always set `response.hovered` to false when dragging another widget (#3860)
* Closes https://github.com/emilk/egui/issues/3841

⚠️ Breaking change!

This defines `response.hovered()` to never be true if any other widget
is being dragged.

If you want to detect if a widget is being hovered while another widget
is being dragged, use the new `response.contains_pointer` instead. This
is necessaert for things like drag-and-drop targets.

Overall, this removes special-casing of non-interactive widgets.
2024-01-22 14:37:53 +01:00
One c735a0b26c
Link to example of File Dialogs (#3835)
<!--
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 your PR, but my time is limited!
-->
Created as per https://github.com/emilk/egui/discussions/3783

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-01-22 12:13:38 +01:00
Garoven e46b0018b9
Fix Android crash on resume (#3847)
<!--
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 your PR, but my time is limited!
-->

Added Viewport reinitialization and Window recreation for Android on
resume event.

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


https://github.com/emilk/egui/assets/95014675/7bc51ea5-3f63-4422-b5a0-ce8291612982
2024-01-22 12:13:28 +01:00
Emil Ernerfeldt 2d725d157f
Add `Response::contains_pointer` (#3859)
* Part of https://github.com/emilk/egui/issues/3841
2024-01-22 11:17:03 +01:00
One 894a53488a
Fix typo (#3800)
Fixes small typo in comment
2024-01-22 11:15:37 +01:00
Emil Ernerfeldt ff39fd6195
Fix: dragging to above/below a `TextEdit` or `Label` will select text to begin/end (#3858)
This also adds a `Galley::begin` method to match `Galley::end` (both
returning cursor positions).

* Part of https://github.com/emilk/egui/issues/3816
2024-01-22 10:49:42 +01:00
Emil Ernerfeldt d319489479 Fix deadlock during text selection 2024-01-19 15:48:45 +01:00
Emil Ernerfeldt f034f6db9f
Refactor: move text selection logic to own module (#3843)
This is a follow-up to https://github.com/emilk/egui/issues/3804 and a
pre-requisite for https://github.com/emilk/egui/issues/3816
2024-01-19 15:38:53 +01:00
Emil Ernerfeldt 3936418f0b
Fix: handle `IconData::default()` without crashing (#3842)
* Closes https://github.com/emilk/egui/issues/3839
2024-01-19 14:24:26 +01:00
Emil Ernerfeldt 76ec982958 Lower some logging from debug -> trace 2024-01-19 13:44:04 +01:00
Emil Ernerfeldt f7ec8f210d
Use runtime knowledge of OS for OS-specific text editing (#3840)
How text editing behaves depends on what OS we are running on.

`target_os` is a compile-time check, but `ctx.os()` is a runtime check,
that works also on web.
2024-01-19 13:37:10 +01:00
Emil Ernerfeldt b766a48fa7
Update wgpu to 0.19 (#3824)
* Closes https://github.com/emilk/egui/issues/3675

---------

Co-authored-by: Andreas Reich <r_andreas2@web.de>
Co-authored-by: Mingun <Alexander_Sergey@mail.ru>
2024-01-19 10:14:13 +01:00
rustbasic 7733d1d87c
Bug Fix : `Response::is_pointer_button_down_on` is now false the frame the button is released (#3833)
* Closes #3809
* Closes #3669
* Closes #3791

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-01-17 16:33:11 +01:00
Emil Ernerfeldt f01d337fa8
Update to ehttp 0.4 (#3834) 2024-01-17 15:39:28 +01:00
rustbasic 7bde0252c1
Keep `ViewportInfo::maximized` and `minimized` up-to-date on Windows (#3831)
This works fine on Windows.
2024-01-17 13:01:33 +01:00
Nathan Adams 221a77dd5b
egui-winit: Don't consume clipboard shortcuts (#3812)
<!--
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 your PR, but my time is limited!
-->

This breaking change seems to have snuck in during #3649. Previously it
would never consume these, today it consumes them unconditionally, and
with this change it'll ~~only consume them if egui wants text input~~
never consume them.

This is a blocker for updating our application, sadly :(
2024-01-17 12:13:11 +01:00
Emil Ernerfeldt 42013cd6c2
Fix `stable_dt` (#3832)
This broke in https://github.com/emilk/egui/pull/3172

Since 0.24.1, `stable_dt` has been fixed at 1/60s, which is a little bit
_too_ stable.

The code issue was the logic for asking "Is this the result of an
immeditate repaint?" was completely broken (always returning false).

* Closes https://github.com/emilk/egui/issues/3830
2024-01-17 12:10:51 +01:00
Romet Tagobert 9e924ec5f0
Fix unwraps in SVG scaling (#3826)
Added error messages when scaling to invalid sizes instead of panicking
through unwrap, returning to previous behavior.

Closes <https://github.com/emilk/egui/issues/3825>.
2024-01-16 09:57:48 +01:00
lucasmerlin 4c8b95f365
Fix clickable widgets blocking scrolling on touch screens (#3815)
Currently, when you try dragging a ScrollArea and start over a button,
the button blocks the ScrollArea from receiving the drag event.

This PR updates layer_rects_this_frame and layer_rects_prev_frame to
include the Sense and will use it to check if the previous layer has a
sense that would be a conflict.

<details><summary>Videos</summary>
<p>
(In both videos I'm clicking and dragging)

Before: 


https://github.com/emilk/egui/assets/8009393/83cc5a8a-2283-46d6-9337-164e1289f701

After (I modified the WidgetGallery to be scrollable, as you can see you
can now scroll over buttons and dragging the slider still blocks the
scroll):


https://github.com/emilk/egui/assets/8009393/be634cf8-3af2-4520-ba1c-bb8bfcc82997

Scrolling in the sidebar also works now:


https://github.com/emilk/egui/assets/8009393/d4309bec-22e1-4fb4-a425-7b029237849b


</p>
</details>

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-01-15 10:08:41 +01:00
Emil Ernerfeldt ce6876e5bd
Add keys `?`, `/`, `|` (#3820)
* Part of #3653 

Also move `enum Key` to own file
2024-01-15 10:08:22 +01:00
hinto-janai c3bc4e26b0
`ComboBox`: add builder method for height (#3001)
Matches the already existing `ComboBox::width()`.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-01-15 10:07:42 +01:00
Emil Ernerfeldt 5d2e192927
Selectable text in Labels (#3814)
* Closes https://github.com/emilk/egui/issues/3804

Add ability to select the text in labels with mouse-drag, double-click,
and keyboard (once clicked).
Hit Cmd+C to copy the text. If everything of a label with elided text is
selected, the copy command will copy the full non-elided text. IME and
accesskit _should_ work, but is untested.

You can control wether or not text in labels is selected globally in
`style.interaction.selectable_labels` or on a per-label basis in
`Label::selectable`. The default is ON.

This also cleans up the `TextEdit` code somewhat, fixing a couple
smaller bugs along the way.

This does _not_ implement selecting text across multiple widgets. Text
selection is only supported within a single `Label`, `TextEdit`, `Link`
or `Hyperlink`.


![label-text-selection](https://github.com/emilk/egui/assets/1148717/c161e819-50da-4b97-9686-042e6abf3564)


## TODO
* [x] Test
2024-01-14 15:17:55 +01:00
Tarek Sabet 301c72ba22
fixed typos in README.md (#3789)
This just fixes two small typos in the readme.
2024-01-09 11:12:09 +01:00
Emil Ernerfeldt 401de05630
Use `Self` everywhere (#3787)
This turns on the clippy lint
[`clippy::use_self`](https://rust-lang.github.io/rust-clippy/v0.0.212/index.html#use_self)
and fixes it everywhere.
2024-01-08 17:41:21 +01:00
Emil Ernerfeldt 12ad9e7b36 Release 0.25.0 - Better keyboard input 2024-01-08 12:25:43 +01:00
Emil Ernerfeldt 5f55e8ea40 Tweak "About" panel in the demo slightly 2024-01-08 12:20:16 +01:00
Emil Ernerfeldt 4ccd1fc82b Improve docstring 2024-01-08 12:19:53 +01:00