From 04f951776d03cc28e8789cd1199c63c5d4aecfa9 Mon Sep 17 00:00:00 2001 From: Matthew Ryan Dillon Date: Sun, 25 Aug 2024 16:16:55 -0400 Subject: [PATCH] better button events --- src/main.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1801d43..76e5f2b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,6 +70,14 @@ fn process_text( } } +fn button(label: &str) -> egui::Button { + egui::Button::new(label).sense(egui::Sense::click_and_drag()) +} + +fn button_clicked(button: egui::Response) -> bool { + button.clicked() || button.drag_stopped() +} + fn ui_system( mut contexts: EguiContexts, mut input_text: ResMut, @@ -84,23 +92,23 @@ fn ui_system( ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| { ui.with_layout(egui::Layout::left_to_right(egui::Align::LEFT), |ui| { - let sort_button = ui.button("Sort"); - if sort_button.clicked() { + let sort_button = ui.add(button("Sort")); + if button_clicked(sort_button) { needs_sort.value = true; } - let strip_button = ui.button("Remove Blanks"); - if strip_button.clicked() { + let strip_button = ui.add(button("Remove Blanks")); + if button_clicked(strip_button) { needs_strip.value = true; } - let copy_button = ui.button("Copy"); - if copy_button.clicked() { + let copy_button = ui.add(button("Copy")); + if button_clicked(copy_button) { ui.output_mut(|o| o.copied_text = input_text.value.clone()); } - let clear_button = ui.button("Clear"); - if clear_button.clicked() { + let clear_button = ui.add(button("Clear")); + if button_clicked(clear_button) { input_text.value = "".to_string(); } });