use eframe::egui; use crate::search::SearchState; pub struct SearchPanelState { pub query: String, pub case_sensitive: bool, pub use_regex: bool, pub history: Vec, } pub struct SearchPanelActions { pub execute_search: bool, pub clear_search: bool, pub config_changed: bool, } pub fn render_search_panel( ctx: &egui::Context, state: &mut SearchPanelState, search_state: &SearchState, match_count: usize, ) -> SearchPanelActions { let mut actions = SearchPanelActions { execute_search: false, clear_search: false, config_changed: false, }; egui::TopBottomPanel::bottom("search_panel").show(ctx, |ui| { ui.vertical(|ui| { ui.horizontal(|ui| { ui.label("🔍 Filter:"); let text_edit_width = 200.0; let text_response = ui.add_sized( [text_edit_width, 20.0], egui::TextEdit::singleline(&mut state.query), ); let enter_pressed = text_response.lost_focus() && ui.input(|i| i.key_pressed(egui::Key::Enter)); if !state.history.is_empty() { render_history_dropdown(ui, state); } let case_changed = ui .checkbox(&mut state.case_sensitive, "Case sensitive") .changed(); let regex_changed = ui.checkbox(&mut state.use_regex, "Regex").changed(); if case_changed || regex_changed { actions.config_changed = true; } if ui.button("Search").clicked() || enter_pressed { actions.execute_search = true; actions.config_changed = true; } if !state.query.is_empty() { if ui.button("✖ Clear").clicked() { actions.clear_search = true; } ui.label(format!("({} matches)", match_count)); } }); if search_state.is_searching() { let progress = search_state.get_progress(); ui.horizontal(|ui| { ui.add( egui::ProgressBar::new(progress) .text(format!("Searching... {:.0}%", progress * 100.0)) .animate(true), ); }); } }); }); actions } fn render_history_dropdown(ui: &mut egui::Ui, state: &mut SearchPanelState) { egui::ComboBox::from_id_salt("search_history_dropdown") .selected_text("▼") .width(30.0) .show_ui(ui, |ui| { ui.set_min_width(300.0); for history_item in &state.history.clone() { if ui.selectable_label(false, history_item).clicked() { state.query = history_item.clone(); } } }); }