From 2c837d25a223b51500661a29c9b76b8fb2598454 Mon Sep 17 00:00:00 2001 From: Brian Janssen Date: Tue, 23 Jan 2024 12:49:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=8B=20`egui=5Fwinit`:=20Allow=20getting?= =?UTF-8?q?=20the=20`clipboard`=20and=20`allow=5Fime`=20state=20(#3724)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Co-authored-by: Marijn Suijten --- crates/egui-winit/src/lib.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 102bc261..11260647 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -174,6 +174,26 @@ impl State { self.egui_input.max_texture_side = Some(max_texture_side); } + /// Fetches text from the clipboard and returns it. + pub fn clipboard_text(&mut self) -> Option { + self.clipboard.get() + } + + /// Places the text onto the clipboard. + pub fn set_clipboard_text(&mut self, text: String) { + self.clipboard.set(text); + } + + /// Returns [`false`] or the last value that [`Window::set_ime_allowed()`] was called with, used for debouncing. + pub fn allow_ime(&self) -> bool { + self.allow_ime + } + + /// Set the last value that [`Window::set_ime_allowed()`] was called with. + pub fn set_allow_ime(&mut self, allow: bool) { + self.allow_ime = allow; + } + #[inline] pub fn egui_ctx(&self) -> &egui::Context { &self.egui_ctx