egui/crates
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
..
ecolor Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00
eframe Add `ViewportCommand::RequestCut`, `RequestCopy` and `RequestPaste` to trigger Clipboard actions (#4035) 2024-04-22 09:06:33 +02:00
egui Add `ViewportCommand::RequestCut`, `RequestCopy` and `RequestPaste` to trigger Clipboard actions (#4035) 2024-04-22 09:06:33 +02:00
egui-wgpu Release 0.27.2 - Fix blurry web rendering 2024-04-02 18:18:43 +02:00
egui-winit Add `ViewportCommand::RequestCut`, `RequestCopy` and `RequestPaste` to trigger Clipboard actions (#4035) 2024-04-22 09:06:33 +02:00
egui_demo_app Rename "Color test" to "Rendering test", and restructure it slightly (#4298) 2024-04-01 13:08:52 +02:00
egui_demo_lib Rename "Color test" to "Rendering test", and restructure it slightly (#4298) 2024-04-01 13:08:52 +02:00
egui_extras Release 0.27.2 - Fix blurry web rendering 2024-04-02 18:18:43 +02:00
egui_glow Add `ViewportCommand::RequestCut`, `RequestCopy` and `RequestPaste` to trigger Clipboard actions (#4035) 2024-04-22 09:06:33 +02:00
egui_plot Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00
egui_web Fix typos (#2866) 2023-04-18 15:52:45 +02:00
emath Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00
epaint Add `emath::OrderedFloat` (moved from `epaint::util::OrderedFloat`) (#4389) 2024-04-21 20:36:32 +02:00