Commit Graph

334 Commits

Author SHA1 Message Date
Salman Abuhaimed 34db001db1
Force canvas/text input focus on touch for iOS web browsers (#4848) 2024-07-23 18:16:51 +02:00
Jan Procházka 0d89e31e3e
Use canvas directly (#4780) 2024-07-15 18:59:15 +02:00
rustbasic 20359a870f
eframe: Improve `glow` context switching (#4814)
Improved `change_gl_context()`

**Before:** 
Create a new `not_current_glcontext`. 

**After:**
If `not_current_glcontext` exists, apply it. Otherwise, create it. 

This will make the program smoother when dragging, etc.
2024-07-11 11:43:21 +02:00
Jonas Wagner b283b8a560
Introduce dithering to reduce banding (#4497)
This PR introduces dithering in the egui_glow and egui_wgpu backends to
reduce banding artifacts.

It's based on the approach mentioned in #4493 with the small difference
that the amount of noise is scaled down slightly to avoid dithering
colors that can be represented exactly. This keeps flat surfaces clean.

Exaggerated dithering to show what is happening:
![Screenshot from 2024-05-14
19-09-48](https://github.com/emilk/egui/assets/293536/75782b83-9023-4cb2-99f7-a24e15fdefcc)

Subtle dithering as commited.
![Screenshot from 2024-05-14
19-13-40](https://github.com/emilk/egui/assets/293536/eb904698-a6ec-494a-952b-447e9a49bfda)

Closes #4493
2024-07-08 09:57:11 +02:00
rustbasic cd1e4c573a
Remove dead code (`EpiIntegration::frame_start`) (#4790)
`frame_start` appears to be deprecated now.
( Am I wrong? )

It would be a good idea to add `#[allow(dead_code)]` or remove
`frame_start`.
2024-07-07 08:52:14 +02:00
Emil Ernerfeldt abab06867c Release 0.28.1 - Tooltip tweaks 2024-07-05 12:09:21 +02:00
lucasmerlin 9a4c46289e
Check if the mouse / touch event is above the canvas via element_from_point (#4775)
* Closes #4752 

To test, start the web demo and follow the repro steps from #4752
2024-07-05 08:18:53 +02:00
Emil Ernerfeldt 234274d46f Release 0.28.0 - Sizing pass, and better eframe web 2024-07-03 14:54:08 +02:00
Emil Ernerfeldt af404fec63
Persist `Area` positions again (#4749)
* Reverts https://github.com/emilk/egui/pull/4577

We again persist area positions, but not sizes.
2024-07-01 17:33:03 +02:00
Emil Ernerfeldt 7b61e426d7 eframe web: map `log::debug` to `console.debug`; not `console.trace` 2024-07-01 16:25:48 +02:00
Emil Ernerfeldt f3a0ac1d1b eframe web fix: `save()` on "blur" event 2024-07-01 16:16:56 +02:00
Emil Ernerfeldt 051b90bfc7 eframe web: Position the IME input position in the middle of the cursor 2024-07-01 16:08:20 +02:00
Emil Ernerfeldt d271718065
Fix focus problems on web (#4745)
* Closes https://github.com/emilk/egui/issues/4743
* Related to https://github.com/emilk/egui/issues/4569
2024-07-01 10:38:54 +02:00
Emil Ernerfeldt d10b3c1f4e
eframe web: Fix stuck keys after pressing ctrl+C, cmd+A, etc (#4731)
* Closes https://github.com/emilk/egui/issues/4724
2024-06-28 18:12:50 +02:00
Emil Ernerfeldt 2180f16cba
eframe web: Fix drag-and-drop file preview/hover (#4732)
* Closes https://github.com/emilk/egui/issues/4726
2024-06-28 18:07:53 +02:00
Emil Ernerfeldt 0c059ac113
Only repaint on cursor movements of area, or if dragging outside (#4730)
* Closes https://github.com/emilk/egui/issues/4723

Also fix some small bugs in the touch input on web
2024-06-28 17:40:48 +02:00
Emil Ernerfeldt 3b9f964aed
eframe web: ignore keyboard events unless canvas has focus (#4718)
* Fixes https://github.com/rerun-io/rerun/issues/6638
* Related? https://github.com/emilk/egui/issues/4563

This improves how an eframe canvas works inside of a larger web page,
and how it works when there are multiple eframe apps in the same page.

`eframe` will set `tabindex="0"` on the canvas automatically, making it
focusable.
It will also set `outline: none` on the CSS, so the focused canvas won't
have an ugly outline.


## Breaking changes
You may wanna add this to your `index.html` to give the canvas focus on
startup:
```js
document.getElementById("the_canvas_id").focus();
```

## Test setup
```sh
./scripts/build_demo_web.sh
./scripts/start_server.sh
open http://localhost:8888/multiple_apps.html
```
Then open the "Input Event History" and "Text Edit" windows

## Tested
* Chromium
	* [x] drag-and-drop of files
	* Test both when a `TextEdit` is focused and when it is not:
	  * [x] `Event::Key`
	  * [x] `Event::Text`
	  * [x] copy-cut-paste
	  * [x] Wheel scroll
	* [x] `Event::PointerGone`
	* [x] Mouse drag
	* [x] Mouse click
	* [x] Mouse right-click
	* [x] Defocus all eframe canvas, and then start typing text
* [x] Firefox (all of the above)
* [x] Desktop Safari (all of the above)
* [x] Mobile Safari


## Future work (pre-existing issues)
* https://github.com/emilk/egui/issues/4723
* https://github.com/emilk/egui/issues/4724
* https://github.com/emilk/egui/issues/4725
* https://github.com/emilk/egui/issues/4726
2024-06-28 15:01:06 +02:00
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 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 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 10571e9da5
`eframe::Result` is now short for `eframe::Result<()>` (#4706) 2024-06-25 13:31:42 +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
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
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
Jan Procházka 3d632cd333
Move first `request_animation_frame` into resize observer (#4628)
This PR ensures the first animation frame happens _after_ the resize
observer has had a chance to do its job.

* Closes https://github.com/emilk/egui/issues/4622

The first commit contains some `log` calls to observe the changed
behavior:

Before:
```
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [300.0 150.0]
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```

After:
```
[eframe::web::events] eframe/src/web/events.rs:633: ResizeObserver canvas=[300.0 150.0] to=(1920, 993)
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
[eframe::web::app_runner] eframe/src/web/app_runner.rs:191: LOGIC [1920.0 993.0]
```
2024-06-06 10:30:32 +02:00
Emil Ernerfeldt 321d2441c1
Make pinch-to-zoom more responsive on web (#4621)
It's 2x faster than before, more closely matching how pinch-to-zoom
feels natively on Mac
2024-06-05 18:32:04 +02:00
Emil Ernerfeldt 4837dc68b3
Fix pinch-to-zoom on web by using the "artificial" modifier keys (#4619)
* Introduced in https://github.com/emilk/egui/pull/4524
* Closes https://github.com/emilk/egui/issues/4615
2024-06-05 18:05:48 +02:00
Emil Ernerfeldt 913cef3361
Enforce eframe errors are `Send` and `Sync` (#4574)
* Follow-up to https://github.com/emilk/egui/pull/4565
2024-05-29 13:13:00 +02:00
Jan Procházka 514ee0c433
Improve web text agent (#4561)
- Closes https://github.com/emilk/egui/issues/4060 - no longer aligned
to top
- Closes https://github.com/emilk/egui/issues/4479 - `canvas.style` is
not set anywhere anymore
- Closes https://github.com/emilk/egui/issues/2231 - same as #4060
- Closes https://github.com/emilk/egui/issues/3618 - there is now one
`<input>` per `eframe` app, and it's removed transitively by
`WebRunner::destroy -> AppRunner::drop -> TextAgent::drop`

This PR improves the text agent to make fewer assumptions about how
`egui` is embedded into the page:
- Text agent no longer sets the canvas position
- There is now a text agent for each instance of `WebRunner`
- The input element is now moved to the correct position, so the OS can
display the IME window in the correct place. Before it would typically
be outside of the viewport

The best way to test this is to build & server the web demo locally:
```
scripts/build_demo_web.sh && scripts/start_server.sh
```

Then open the EasyMark editor, and try using IME to input some emojis:
http://localhost:8888/#EasyMarkEditor

To open the emoji keyboard use:
- <kbd>win + .</kbd> on Windows
- <kbd>ctrl + cmd + space</kbd> on Mac

Tested on:
- [x] Windows
- [x] Linux
- [x] MacOS
- [x] Android
- [x] iOS

## Migration guide

The canvas no longer controls its own size/position on the page. This
means that those properties can now be controlled entirely via HTML and
CSS, and multiple separate `eframe` apps can coexist better on a single
page.

To match the old behavior, set the `canvas` width and height to 100% of
the `body` element:

```html
<html>
  <body>
    <canvas></canvas>
  </body>
</html>
```

```css
/* remove default margins and use full viewport */
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
}

canvas {
  /* match parent element size */
  width: 100%;
  height: 100%;
}
```

Note that there is no need to set `position: absolute`/`left: 50%;
transform: translateX(-50%)`/etc., and setting those properties may
poorly affect the sharpness of `egui`-rendered text.

Because `eframe` no longer updates the canvas style in any way, it also
means that on mobile, the canvas no longer collapses upwards to make
space for a mobile keyboard. This should be solved in other ways:
https://github.com/emilk/egui/issues/4572
2024-05-29 12:54:33 +02:00
Emil Ernerfeldt 942fe4ab31
Support returning errors when creating the app (#4565)
The closure passed to `eframe::run_native` now returns a `Result`,
allowing you to return an error during app creation, which will be
returned to the caller of `run_native`.

This means you need to wrap your `Box::new(MyApp::new(…))` in an
`Ok(…)`.

* Closes https://github.com/emilk/egui/issues/4474
2024-05-28 21:59:19 +02:00
Jan Procházka d131b2b580
Fix: Don't `.forget()` RAF closure (#4551)
The closure is now stored in `WebRunner` and dropped in the next
`request_animation_frame` instead of being "leaked" via `forget`

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-05-27 21:55:23 +02:00
Jan Procházka 759c8fd2c9
Use ResizeObserver instead of `resize` event (#4536)
Currently, if the size of the canvas element changes independently of
the size of the browser window (e.g. due to its parent element
shrinking), then no repaints are scheduled.

This PR replaces the `resize` event with a `ResizeObserver`, which
ensures that _any_ resize of the canvas element (including those caused
by browser window resizes) trigger a repaint. The repaint is done
synchronously as part of the resize event, to reduce any potential
flickering.

The result seems to pass the rendering tests on most platform+browser
combinations. We tested:
- Chrome, Firefox, Safari on macOS
- Chrome, Firefox on Linux (ubuntu and arch, both running wayland)
- Chrome, Firefox on Windows

Firefox still has some antialiasing issues on Linux platforms, but this
antialiasing also happens on `master`, so this PR is not a regression
there.

The code setting `canvas.style.width` and `canvas.style.height` at the
start of `AppRunner::logic` was also removed - the canvas _display_ size
is now fully controlled by CSS, e.g. by setting `canvas { width: 100%;
height: 100%; }`.

The approach used here is described in
https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html

Note: The only remaining place where egui updates the style of the
canvas it is rendering to is some of the IME/mobile input handling code.
Fixing that is out of scope for this PR, and will be done in a followup
PR.
2024-05-27 21:41:28 +02:00
lucasmerlin 8553e738e0
eframe: Add `NativeOptions::persistence_path` (#4423)
This allows customizing the persistence path in NativeOptions.
Previously, persistence wouldn't work with android because
directories-next doesn't support android so eframe would just fail to
find a place where it could store its config.

* Closes #4098 (android users can now specify a path that works with
android, by e.g. using app_dirs2, which supports android)
2024-05-27 18:57:39 +02:00
Oscar Gustafsson cd45d18615
Do no use the ahash reimport (#4504)
<!--
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!
-->

Related to #3482 

Not sure what the "best practice" is, to me it seems like one should
import from "the original location" if possible, but now it should at
least be possible to not re-export ahash without any breakage in the
egui code base (but possibly in projects using egui, so one should
probably deprecate it if one would like to go that path). It also seems
like epaint re-exports ahash.
2024-05-27 16:24:50 +02:00
Emil Ernerfeldt 48045e57da
Remove `Event::Scroll` and handle it in egui (#4524)
For integrations: just emit `egui::Event::MouseWheel` (like before).
egui will interpret that as zoom or pan.

On the way towards https://github.com/emilk/egui/issues/4401
2024-05-22 21:35:15 +02:00
Emil Ernerfeldt c8578c9a6b
Fix: still track mouse when dragging outside web canvas (#4522)
* Closes https://github.com/emilk/egui/issues/3157

If the mouse leaves the canvas when dragging a slider, the slider will
still move.

---

To support this, I had to revert https://github.com/emilk/egui/pull/4419
Despite that, I fail to reproduce the two issues it claimed to solve:

* https://github.com/emilk/egui/issues/4406 may have been solved in
another way by this PR
* https://github.com/emilk/egui/issues/4418 I cannot reproduce on Mac.
If it is still a problem, I think it should be solved by triggering a
`PointerEvent::Released` when focus is lost (i.e. on alt-tab), and not
on `PointerGone`
2024-05-22 11:48:34 +02:00
Oscar Gustafsson c1eb3f884d
Move dependencies to workspace (#4495)
<!--
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!
-->

Inspired by:

44d65f41ac/Cargo.toml (L65)

I took the liberty of removing that comment since I *think* that I got
all "relevant" ones (showing up more than once, sort of).
2024-05-14 11:02:49 +02:00
Emil Ernerfeldt 44d65f41ac
Update `image` crate to 0.25 (#4160)
To not produce duplicating deps in Rerun
(https://github.com/rerun-io/rerun/pull/5280) I suggest we wait with
merging this until these crates have updated to `image` 0.25:
* [x] [`arboard`](https://crates.io/crates/arboard)
* [x] [`gltf`](https://crates.io/crates/gltf)
2024-05-13 13:35:15 +02:00
Emil Ernerfeldt 059218d954
eframe: Remove dependency on `thiserror` (#4483)
Less dependencies => faster compile times

* Part of https://github.com/emilk/egui/issues/4481
2024-05-11 20:17:06 +02:00
Avery Radmacher e06b225dab
Fix: Window position creeps between executions on scaled monitors (#4443)
<!--
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!
-->

* Closes <https://github.com/emilk/egui/issues/4442>
* Refactors active monitor detection so it can be called from multiple
locations.

Compare this gif to the one on the issue report.

![egui_window_position_no_creep](https://github.com/emilk/egui/assets/45777186/8e05d4fb-266e-48b9-9223-b65f16500a99)

### Investigation notes

- [`WindowSettings.inner_position_pixels` and
`WindowSettings.outer_position_pixels`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L8-L12)
are stored in physical/pixel coordinates.
- `ViewportBuilder::with_position` expects to be passed a position in
_logical_ coordinates.
- Prior to this PR, the position was being passed from `WindowSettings`
to `with_position` [without any
scaling](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L61-L68).
This was the root cause of the issue.
- The fix is to first convert the position to logical coordinates,
respecting the scaling factor of the active monitor. This requires us to
first determine the active monitor, so I factored out some of the logic
in
[`clamp_pos_to_monitor`](https://github.com/emilk/egui/blob/master/crates/egui-winit/src/window_settings.rs#L130)
to find the active monitor.
2024-05-11 16:48:12 +02:00
rustbasic 27a22f991d
Fix : In Windows, the 'egui_demo_app' screen does not appear. (#4410)
* Related #4337 
* Closes #4409 

Fix : In Windows, the 'egui_demo_app' screen does not appear After the
#4337 update.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-05-11 00:41:02 +02:00
Emil Ernerfeldt ded8dbd45b
Fix some clippy warning from Rust 1.78.0 (#4444) 2024-05-02 17:04:25 +02:00
Emil Ernerfeldt 2f508d6a61
Replace cargo-cranky with workspace lints (#4413)
Replace `cargo-cranky` (which has served us well) with workspace lints
2024-04-25 17:24:50 +02:00
Emil Ernerfeldt cee790681d
Update to Rust 1.76 (#4411)
Motivation: I want to replace `cargo-cranky` with workspace lints, first
available in Rust 1.74.
However, `cargo doc` would hange on `wgpu` and `wgpu-core` on 1.74 and
1.75… so now we're on 1.76.
I think this is fine - when 1.78 is released next week we're still two
versions behind the bleeding edge.

…and the branch name is just wrong 🤦
2024-04-25 15:51:01 +02:00
Mads Marquart 14194f5d3a
eframe: Use `objc2` and its framework crates (#4395)
These are a replacement to the `objc` and `cocoa` crates.

This PR prevents:
- An extra copy when creating `NSData`
- A memory leak when creating `NSImage`
- A memory leak when creating `NSString`

And is generally a readability improvement.

Note that we define `NSApp` manually for now, the implementation in
`objc2-app-kit` is currently suboptimal and wouldn't allow you to check
whether the NSApplication has been created or not.

Related: https://github.com/emilk/egui/issues/4219, this should nicely
coincide with the Winit `0.30` release.

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-23 17:35:12 +02:00
lopo ff8cfc2aa0
Allow users to create viewports larger than monitor on Windows & macOS (#4337)
Added clamp_size_to_monitor_size field on ViewportBuilder, which means
whether clamp the window's size to monitor's size. (default to `true`)

* Closes https://github.com/emilk/egui/issues/3389

### simple example

```rust
pub struct MyApp {}

impl MyApp {
    pub fn new() -> MyApp {
        MyApp {}
    }
}

impl eframe::App for MyApp {
    fn update(&mut self, ctx: &Context, frame: &mut eframe::Frame) {
        egui::CentralPanel::default()
            .frame(Frame::none().fill(Color32::DARK_GRAY))
            .show(ctx, |ui| {
                if ctx.input(|i| i.key_pressed(Key::Escape)) {
                    ctx.send_viewport_cmd(ViewportCommand::Close);
                }
            });
    }
}

pub fn main() {
    let option = eframe::NativeOptions {
        viewport: ViewportBuilder::default()
            .with_position([10.0, 10.0])
            .with_inner_size([3000.0, 2000.0])
            .with_clamp_size_to_monitor_size(false),
        ..Default::default()
    };

    eframe::run_native(
        "a large window app",
        option,
        Box::new(|ctx| Box::new(MyApp::new())),
    ).unwrap();
}
```

It works on my windows (with 3 monitors), but I don't have a test
environment for macos

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-22 12:44:21 +02:00
rustbasic 436c671331
Improve IME support with new `Event::Ime` (#4358)
* Closes #4354 

Fix: can't repeat input chinese words

AND

For Windows :
ImeEnable
ImeDisable

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-22 12:43:07 +02:00
bu5hm4nn a2f1ca31a0
Add `ViewportCommand::RequestCut`, `RequestCopy` and `RequestPaste` to trigger Clipboard actions (#4035)
### Motivation
We want to offer our users a context menu with `Cut`, `Copy` and `Paste`
actions. `Paste` is not possible out of the box.

### Changes
This PR adds `ViewportCommand::RequestCut`,
`ViewportCommand::RequestCopy` and `ViewportCommand::RequestPaste`. They
are routed and handled after the example of
`ViewportCommand::Screenshot` and result in the same code being executed
as when the user uses `CTRL+V` style keyboard commands.

### Reasoning
In our last release we used an instance of
`egui_winit:📋:Clipboard` in order to get the `Paste`
functionality.

However Linux users on Wayland complained about broken clipboard
interaction (https://github.com/mikedilger/gossip/issues/617). After a
while of digging I could not find the issue although I have found
references to problems with multiple clipboards per handle before
(https://gitlab.gnome.org/GNOME/mutter/-/issues/1250) but I compared
mutter with weston and the problem occured on both.

So to solve this I set out to extend egui to access the clipboard
instance already present in egui_winit. Since there was no trivial way
to reach the instance of `egui_winit::State` I felt the best approach
was to follow the logic of the new `ViewportCommand::Screenshot`.

### Variations
It could make sense to make the introduced `enum ActionRequested` a part
of crates/egui/src/viewport.rs and to then wrap them into one single
`ViewportCommand::ActionRequest(ActionRequested)`.

### Example
```Rust
let mut text = String::new();
let response = ui.text_edit_singleline(&mut text);
if ui.button("Paste").clicked() {
    response.request_focus();
    ui.ctx().send_viewport_cmd(ViewportCommand::RequestPaste);
}
```

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
2024-04-22 09:06:33 +02:00
Emil Ernerfeldt 15b0ef3259 Release 0.27.2 - Fix blurry web rendering 2024-04-02 18:18:43 +02:00