From 1ae2d2803a8b48eb5396c9eb0b4c69a5fe6bfed9 Mon Sep 17 00:00:00 2001
From: Doonv <58695417+doonv@users.noreply.github.com>
Date: Mon, 27 May 2024 17:43:48 +0300
Subject: [PATCH] Make `TextEdit::return_key` optional (#4543)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
I wanted to disable the return key functionality on my `TextEdit`, so
that the `TextEdit` doesn't get unfocused whenever the user submits a
command onto my developer console (which is also bound to ↵
Enter).
---
crates/egui/src/widgets/text_edit/builder.rs | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/crates/egui/src/widgets/text_edit/builder.rs b/crates/egui/src/widgets/text_edit/builder.rs
index 440916f31b2e..b61b0f813f60 100644
--- a/crates/egui/src/widgets/text_edit/builder.rs
+++ b/crates/egui/src/widgets/text_edit/builder.rs
@@ -78,7 +78,7 @@ pub struct TextEdit<'t> {
align: Align2,
clip_text: bool,
char_limit: usize,
- return_key: KeyboardShortcut,
+ return_key: Option,
}
impl<'t> WidgetWithState for TextEdit<'t> {
@@ -135,7 +135,7 @@ impl<'t> TextEdit<'t> {
align: Align2::LEFT_TOP,
clip_text: false,
char_limit: usize::MAX,
- return_key: KeyboardShortcut::new(Modifiers::NONE, Key::Enter),
+ return_key: Some(KeyboardShortcut::new(Modifiers::NONE, Key::Enter)),
}
}
@@ -353,9 +353,11 @@ impl<'t> TextEdit<'t> {
///
/// This combination will cause a newline on multiline,
/// whereas on singleline it will cause the widget to lose focus.
+ ///
+ /// This combination is optional and can be disabled by passing [`None`] into this function.
#[inline]
- pub fn return_key(mut self, return_key: KeyboardShortcut) -> Self {
- self.return_key = return_key;
+ pub fn return_key(mut self, return_key: impl Into