Commit Graph

597 Commits

Author SHA1 Message Date
Marijn Suijten 5b591d26f6
Add `Key::Cut`, `Key::Copy`, `Key::Paste` (#3725)
The comment added in commit 8a0bc97e ("[egui_glium] Fix paste") seems to
assume that `winit` "should have translated" common "paste" keyboard
combos to a `Cut`/`Copy`/`Paste` "KeyCode", but completely glossed over
the fact that this `KeyCode` (now also `NamedKey`) maps to a special key
dedicated to this purpose found on some keyboards and OSes. Make sure
that this key is still handled in addition to the combo that is
detected.

---

Note that this PR does not compile as it is (and I have hence not tested
this nor even ran into this limitation), just noticed this inconsistency
while failing to understand a code comment. We'd have to decide if the
variants should be added to `egui::Key` or if these helper functions
need to take `winit` keys (`ScanCode` or `NamedKey`) directly?

I should have an old keyboard with a physical paste key in a drawer
somewhere. And on Android there are special copy/paste events that can
be sent by a virtual keyboard or the debug shell, so that this can be
properly tested before it is merged.
(Except that the current `clipboard` implementation is not supported on
Android)
2023-12-25 19:02:02 +01:00
Arnold Loubriat c3a9355279
Fix: Let `accesskit` process window events (#3733)
<!--
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!
-->

Since accesskit_winit version 0.15.0, it is necessary to call
`Adapter::process_events` to let AccessKit fire up window focus events
on Unix and macOS. Furthermore this has always been needed on Unix (X11
only) to let AccessKit know about the window bounds, which is needed to
perform hit-testing on nodes.
2023-12-25 19:01:05 +01:00
Emil Ernerfeldt 0a6ea15f6c
impl `Clone` for `Fonts` (#3737)
Closes https://github.com/emilk/egui/issues/3731
2023-12-25 19:00:54 +01:00
Oscar Gustafsson fc18d6f8f4
Add support for dashed lines with offset (#3720)
<!--
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!
-->

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

This can naturally be obtained by starting the drawing a bit "later",
but providing support for this directly will simplify interleaved
drawing of dashed lines.

An even more general approach would be to allow passing an even-length
vector of lengths and gaps, in addition to offset. Primarily thinking if
it is better to go even further if a new dashed-line-method is
introduced. The second commit introduce this (I can naturally squash
these!).
2023-12-23 16:17:04 +01:00
Wybe Westra 76025f2c15
Fix: `Grid` now follows `style.visuals.striped` setting if not explicitly overwritten (#3723)
The docs of
[`Visuals.striped`](https://docs.rs/egui/latest/egui/style/struct.Visuals.html#structfield.striped)
mention that they control the default striping of Grid. However, this
seems to be broken.

This pr makes the Grid follow the striped setting if it doesn't yet have
a row coloring set.
2023-12-23 15:58:48 +01:00
Antoine Beyeler 365a8d2240
Fix `Window` positioning bug when bad `pivot` is stored in app data (#3721)
This PR fixes an issue where a bad pivot stored in app state would
override the pivot actually set from code. The root code of this issue
if the `Window`'s `State` containing `pivot` in the first place, as
`pivot` is not part of a state to be tracked. It makes the `State`
structure more ergonomic though, so this PR leaves the `pivot` field but
always overrides it with the value provided by user code.

#### Repro of the original issue

This issue can be reproduced using the `re_ui_example` app from the
Rerun repo, at this commit:
fb5add0047.
By using this `app.ron` file, the bug will appear:

```
{
    "egui": "(
      areas:{
            ((0)):(
                areas:{
                    (13430889033718688666):(pivot_pos:(x:565.5,y:328.0),pivot:((Min,Min)),size:(x:364.0,y:75.5),interactable:true),
                },
            )
        }
    )",
}
```

The modal is entered based on it's top-left corner even though the code
actually specifies a center-center pivot:

<img width="1312" alt="image"
src="https://github.com/emilk/egui/assets/49431240/6df1a8bb-d1ea-4e15-866c-5f14138dda0e">

With this PR, the centring is correct even with the "poisoned"
`app.ron`:

<img width="1312" alt="image"
src="https://github.com/emilk/egui/assets/49431240/7f50b2d4-9245-48f3-91de-c747bbc8c40e">
2023-12-23 15:53:40 +01:00
Emil Ernerfeldt ffcc3f066c Typos and doc improvements 2023-12-22 17:33:01 +01:00
Emil Ernerfeldt 0561fcaba9
Replace a special `Color32::PLACEHOLDER` with widget fallback color (#3727)
This introduces a special `Color32::PLACEHOLDER` which, during text
painting, will be replaced with `TextShape::fallback_color`.

The fallback color is mandatory to set in all text painting. Usually
this comes from the current visual style.

This lets users color only parts of a `WidgetText` (using e.g. a
`LayoutJob` or a `Galley`), where the uncolored parts (using
`Color32::PLACEHOLDER`) will be replaced by a default widget color (e.g.
blue for a hyperlink).

For instance, you can color the `⚠️`-emoji red in a piece of text red
and leave the rest of the text uncolored. The color of the rest of the
text will then depend on wether or not you put that text in a label, a
button, or a hyperlink.

Overall this simplifies a lot of complexity in the code but comes with a
few breaking changes:

* `TextShape::new`, `Shape::galley`, and `Painter::galley` now take a
fallback color by argument
* `Shape::galley_with_color` has been deprecated (use `Shape::galley`
instead)
* `Painter::galley_with_color` has been deprecated (use
`Painter::galley` instead)
* `WidgetTextGalley` is gone (use `Arc<Galley>` instead)
* `WidgetTextJob` is gone (use `LayoutJob` instead)
* `RichText::into_text_job` has been replaced with
`RichText::into_layout_job`
* `WidgetText::into_text_job` has been replaced with
`WidgetText::into_layout_job`
2023-12-22 15:09:10 +01:00
Emil Ernerfeldt e36b981118
Add @Bromeon and @EmbersArc as CODEOWNERS for egui_plot (#3711)
Please take a look @Bromeon and @EmbersArc!

You have both contributed substantially to `egui_plot` (more than I
have).
This is me inviting you to co-maintain the `egui_plot` crate.
If you accept, you'll get a notification when someone opens a PR
touching `egui_plot`, and you can review and merge it as you see fit.
You can also merge your own egui_plot PRs without waiting on me to
review them.
2023-12-21 09:08:16 +01:00
PingPongun 963be247f2
Update resvg dependency of egui_extras (#3719)
Update `resvg` from v0.28 to v0.37. 
Remove related, unnecessary entries from `deny.toml`.

⚠ In example `images` ferris is scaled differently, but I guess that now
it scales in expected way (takes all available space; before this PR it
takes up to space that, was available at first render- it does not
upscale).

This PR is minimal adaptation to new `resvg` api and small related
simplification, however it should be considered to update loaders
(currently if svg image initially was small and was scaled up it will be
blurred, see https://github.com/emilk/egui/issues/3501). As svg image
now scales over render size, problem will be more often seen now.

(currently `SvgLoader` theoretically should rerender for different sizes
(but I guess it will result in memory leak in that case), but refreshing
is stopped earlier in `DefaultTextureLoader`).

I have initial version of loaders update, that will fix issue with svg
scaling (and also enable e.g. reloading image if file has been changed),
I will submit these changes in separate PR once this one is merged.

Closes <https://github.com/emilk/egui/issues/3652>.
2023-12-20 08:09:03 +01:00
Antoine Beyeler add1695624
Fix plot auto-bounds unset by default (#3722)
These PR recently cleaned up the code around auto-bounds, but introduced
an involuntary change whereby auto-bounds would not be enabled by
default. All plots would default to being not properly centred as a
result.

- #3587
- #3586

This PR changes the default back to enabled. It also deprecates
`auto_bounds_x()` and `auto_bounds_y()`, which could only enable
auto-bounds (which is not very useful as auto-bounds were, and now are
again, enabled by default). A new `auto_bounds()` API can now be sued to
disable auto-bounds if needed.

Fixes #3712 
Fixes https://github.com/rerun-io/rerun/issues/4503
2023-12-19 17:58:59 +01:00
Emil Ernerfeldt 9253cafedd
`eframe`: If both `glow` and `wgpu` features are enabled, default to `wgpu` (#3717)
By default, only the `glow` feature is enabled, so if the user added
`wgpu` to the feature list they probably wanted to use `wgpu`.
2023-12-19 09:51:05 +01:00
Emil Ernerfeldt 4a2cafee7c Add a TODO 2023-12-18 17:28:47 +01:00
Emil Ernerfeldt 25903d0a02 Add `TexturePoll::texture_id` 2023-12-18 17:28:47 +01:00
Emil Ernerfeldt 4060d02f27 Add a bunch of `#[inline]` 2023-12-18 17:28:47 +01:00
crispy-strawberry a726e656a4
Very small typo fix (#3693)
<!--
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!
-->

Small spelling error - changed `Addintional` to `Additional`
2023-12-18 15:43:09 +01:00
Emil Ernerfeldt 449678e617
Update to glow 0.13 (#3715) 2023-12-18 15:15:20 +01:00
Fredrik Fornwall 8e5959d55d
Update to winit 0.29 (#3649)
* Closes https://github.com/emilk/egui/issues/3542
* Closes https://github.com/emilk/egui/issues/2977
* Closes https://github.com/emilk/egui/issues/3303

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2023-12-18 14:53:14 +01:00
Emil Ernerfeldt 8503a85113
Bug fix: framebuffer clear when using glow with multi-viewports (#3713)
I broke this in https://github.com/emilk/egui/pull/3665

For some reason, when using multiple viewports, the first "clear"
doesn't take.

I don't have time to investigate further, so I am adding a hack here
which:

* For single-viewport apps, the clear is done before `App::update` so
user can paint there
* For multi-viewport apps, the clear is done after `App::update`, so
that it works

This means painting in `App::update` won't work with multi-viewports.

Ideally, users should use paint callbacks instead of painting directly
in `App::update` anyways.
2023-12-18 12:47:23 +01:00
zeozeozeo 3361d399fb
derive serde Serialize and Deserialize on `KeyboardShortcut` (#3694)
<!--
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 is a very simple change so you don't have to do this:
https://github.com/zeozeozeo/egui-keybind/blob/master/src/bind.rs#L149-L172
2023-12-18 09:48:16 +01:00
Emil Ernerfeldt c8dd3dd01a
Update dependencies (#3700)
Also disable `regex` `env_logger` feature in examples to improve compile
times.
2023-12-12 12:59:40 +01:00
Emil Ernerfeldt 8d4de866d4
Remove deprecated functions (#3692) 2023-12-08 11:02:57 +01:00
Emil Ernerfeldt b1721a3ce7
Release `egui_extras` 0.24.2 - Fix `Table` scrolling bug (#3691)
Includes:
* https://github.com/emilk/egui/pull/3690

---------

Co-authored-by: Antoine Beyeler <49431240+abey79@users.noreply.github.com>
2023-12-08 10:32:06 +01:00
Antoine Beyeler d8a795598f
Fix `egui_extras::Table` scrolling bug (#3690)
`egui_extras::Table` now uses the clip rectangle to decide which rows to
draw when using `TableBody::rows()`.

- Closes #3682
- Closes #3670
2023-12-08 09:08:27 +01:00
Brian Janssen 4e75f4313e
Fix typos in viewports docs (`then` vs `than`) (#3681)
I looked through the new viewport docs and noticed these small typos.
This PR fixes them.
2023-12-05 16:38:21 +01:00
Emil Ernerfeldt a4e389431d
Simplify `egui_winit::State` (#3678)
By storing a clone of the egui context in it, we can be sure to always
use the correct `pixels_per_point`
2023-12-05 11:45:25 +01:00
Emil Ernerfeldt 80d7143b15
Log all available wgpu adapters during startup (#3671)
Useful when debugging, e.g. if the default choice is one of many, and
perhaps the other ones would be better.

**EDIT**: Oh, `enumerate_adapters` doesn't work on web… will fix.
2023-12-04 15:59:13 +01:00
Sebastian Urban 36c6b6304d
Make glow Send + Sync again. (#3646)
* Reverts #3598
* Closes #3645
2023-12-04 15:58:05 +01:00
Emil Ernerfeldt 84a6d6f2ab Fix code example in `egui_demo_lib` 2023-11-30 17:53:34 +01:00
Emil Ernerfeldt d17613c242 Release 0.24.1 - Bug fixes 2023-11-30 17:46:25 +01:00
Emil Ernerfeldt 4b1523ad51
eframe glow backend: Clear render target before calling `App::update` (#3665)
* Closes https://github.com/emilk/egui/issues/3659
2023-11-30 16:37:16 +01:00
Emil Ernerfeldt bd9bc252aa
Fix buggy text withviewports on monitors with different scales (#3666)
* Closes https://github.com/emilk/egui/issues/3664

Bonus: optimize color conversions and font atlas upload, especially in
debug builds.
2023-11-30 15:56:05 +01:00
Emil Ernerfeldt 61a7b90d5b
Improve multi-viewports across monitors with different scales (#3663)
It required some ugly code in `egui-winit` in order to fix this without
breaking sem-ver (I want this to land in a 0.24.1 patch release). I'll
clean up in time for 0.25.

There is still a font rendering bug when using immediate viewports
across multiple viewports, but that's harder to fix.
2023-11-30 12:08:53 +01:00
Vaqxai 37244e3632
egui_extras: Add more years for datepicker (#3599)
Birthdates really needed this

Kinda closes
[<https://github.com/emilk/egui/issues/3597>](https://github.com/emilk/egui/issues/3597).
2023-11-28 14:50:19 +01:00
Emil Ernerfeldt a1f3c71b7f
Remove dependency on `tts` (#3651)
We were using [`tts`](https://github.com/ndarilek/tts-rs) for the
web-only screen reader. This was overkill, to say the least. It is now
replaced with ten lines of `web-sys` calls.
2023-11-28 10:46:18 +01:00
Emil Ernerfeldt 8494cf854c
Update to wasm-bindgen 0.2.89 (#3644)
0.2.88 was recently yanked
2023-11-27 18:33:07 +01:00
Emil Ernerfeldt e6815ae1ea
Fix windowing problems when using the `x11` feature on Linux (#3643)
This was caused by a hack added by @konkitoman in
https://github.com/emilk/egui/pull/3172

The solution was reported by @ItsEthra in
https://github.com/emilk/egui/issues/3628#issuecomment-1827943346

* Closes https://github.com/emilk/egui/issues/3620
* Closes https://github.com/emilk/egui/issues/3628
2023-11-27 18:16:02 +01:00
zeozeozeo 4dc964ab4b
eframe: Fix window flashing white on launch (#3631)
This is a bug that can occur on Windows, previously it was fixed by only
showing the window after the first frame was rendered, but the bug
appeared again with egui 0.24.0. This commit fixes this bug by making
the window invisible on startup.

## Before


![window-flash](https://github.com/emilk/egui/assets/108888572/31a675af-8c30-46b1-a1af-653491cf67da)

## After


![no-window-flash](https://github.com/emilk/egui/assets/108888572/e7bfc429-033e-4842-8591-b9229143a60b)

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

Closes https://github.com/emilk/egui/issues/3625.
2023-11-27 10:35:37 +01:00
Emil Ernerfeldt 43e7b16bb1
eframe: Fix clicks in web (#3640)
Closes https://github.com/emilk/egui/issues/3633

Bug introduced in #3623 (after 0.24.0 was cut)
2023-11-27 08:37:02 +01:00
Aaron Hill fbccd3a1a2
Don't treat 'WindowEvent::CloseRequested' as consumed in egui-winit (#3627)
This appears to have been 'consumed' by the viewport changes at one
point (by updating `viewport_info`), but this is no longer the case. We
should avoid marking this as 'consumed', so that applications know to
continue processing this event after passing it to egui.

<!--
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!
-->
2023-11-26 23:37:03 +01:00
libertyteeth 6715ed5cea
Update viewport.rs, fix comment typo: "vieweport" -> "viewport" (#3638)
No code changes.  Just fixing a typo in a comment.

Closes #3637.
2023-11-26 23:33:54 +01:00
Emil Ernerfeldt 23732be0e5
eframe web: Don't throw away frames on click/copy/cut (#3623)
* Follow-up to https://github.com/emilk/egui/pull/3621 and
https://github.com/emilk/egui/pull/3513

To work around a Safari limitation, we run the app logic in the event
handler of copy, cut, and mouse up and down.

Previously the output of that frame was discarded, but in this PR it is
now saved to be used in the next requestAnimationFrame.

The result is noticeable more distinct clicks on buttons (one more frame
of highlight)

Bonus: also fix auto-save of a sleeping web app
2023-11-24 10:08:43 +01:00
Emil Ernerfeldt 0d24a3a73b
Fix click-to-copy on Safari (#3621)
* Closes https://github.com/lampsitter/egui_commonmark/issues/21

Follow-up to https://github.com/emilk/egui/pull/3513

Safari only allows access to the clipboard as response to user action,
so we need to take an extra logic step right in the event handler.
2023-11-24 09:06:15 +01:00
Emil Ernerfeldt bd087ffb8d Release 0.24.0 - Multi-viewport 2023-11-23 15:56:46 +01:00
Emil Ernerfeldt 56a74a5247 mute warning 2023-11-23 15:52:50 +01:00
Emil Ernerfeldt e7604c0230 Update changelogs 2023-11-23 15:46:04 +01:00
Emil Ernerfeldt dd794f253a Don't persist zoom_with_keyboard 2023-11-23 15:45:41 +01:00
Emil Ernerfeldt 185e18ad4f Improve some docs 2023-11-23 15:45:32 +01:00
Emil Ernerfeldt 6a8b51adb5 Improve demo backend panel 2023-11-23 15:45:19 +01:00
Emil Ernerfeldt 96bc34a66d Use workspace definitions of edition,license,rust-version,version 2023-11-23 15:45:11 +01:00