From 7e9b5de25091aac61cd685cecfb3486fd0fc3f5d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 17 Nov 2020 10:57:14 +0100 Subject: [PATCH] Fix: id clash for TextEdit --- egui/src/demos/widgets.rs | 3 +++ egui/src/widgets/text_edit.rs | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/egui/src/demos/widgets.rs b/egui/src/demos/widgets.rs index 723550b3..c311d048 100644 --- a/egui/src/demos/widgets.rs +++ b/egui/src/demos/widgets.rs @@ -48,6 +48,9 @@ impl Widgets { pub fn ui(&mut self, ui: &mut Ui) { ui.add(crate::__egui_github_link_file_line!()); + ui.checkbox(&mut self.button_enabled, "Use Cloud for training"); + ui.text_edit_singleline(&mut self.single_line_text_input); + ui.horizontal(|ui| { ui.style_mut().spacing.item_spacing.x = 0.0; ui.add(Label::new("Text can have ").text_color(srgba(110, 255, 110, 255))); diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index bf50aae6..3b635754 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -217,17 +217,6 @@ impl<'t> Widget for TextEdit<'t> { desired_height_rows, } = self; - let id = id.unwrap_or_else(|| { - if let Some(id_source) = id_source { - ui.make_persistent_id(id_source) - } else { - // Since we are only storing cursor, perfect persistence Id not super important - ui.make_position_id() - } - }); - - let mut state = ui.memory().text_edit.get(&id).cloned().unwrap_or_default(); - let text_style = text_style.unwrap_or_else(|| ui.style().body_text_style); let font = &ui.fonts()[text_style]; let line_spacing = font.row_height(); @@ -245,6 +234,17 @@ impl<'t> Widget for TextEdit<'t> { galley.size.y.max(desired_height), ); let rect = ui.allocate_space(desired_size); + + let id = id.unwrap_or_else(|| { + if let Some(id_source) = id_source { + ui.make_persistent_id(id_source) + } else { + // Since we are only storing cursor, perfect persistence Id not super important + ui.make_position_id() // Must be after allocate_space! + } + }); + let mut state = ui.memory().text_edit.get(&id).cloned().unwrap_or_default(); + let sense = if enabled { Sense::click_and_drag() } else {