mirror of
https://github.com/arabianq/pipewire-soundpad.git
synced 2026-04-27 22:11:22 +00:00
refactor(gui): refactor draw_hotkeys to improve code health (#86)
- Break down the monolithic `draw_hotkeys` method into smaller, focused component functions: `draw_hotkeys_header`, `draw_hotkeys_search`, `draw_hotkeys_table`, and `handle_hotkey_action`. - Improve readability and maintainability of the `src/gui/draw.rs` file while preserving identical behavior. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
11de96db58
commit
e4b0b10393
+24
-10
@@ -137,7 +137,22 @@ impl SoundpadGui {
|
||||
ui.vertical(|ui| {
|
||||
ui.spacing_mut().item_spacing.y = 5.0;
|
||||
|
||||
// --- Header ---
|
||||
self.draw_hotkeys_header(ui);
|
||||
ui.separator();
|
||||
|
||||
self.draw_hotkeys_search(ui);
|
||||
ui.separator();
|
||||
ui.add_space(5.0);
|
||||
|
||||
let action = self.draw_hotkeys_table(ui);
|
||||
|
||||
if let Some(action) = action {
|
||||
self.handle_hotkey_action(action);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_hotkeys_header(&mut self, ui: &mut Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
let back_button = Button::new(ICON_ARROW_BACK).frame(false);
|
||||
if ui.add(back_button).clicked() {
|
||||
@@ -148,10 +163,9 @@ impl SoundpadGui {
|
||||
ui.label(RichText::new("Hotkeys").color(Color32::WHITE).monospace());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
// --- Search and Add Command ---
|
||||
fn draw_hotkeys_search(&mut self, ui: &mut Ui) {
|
||||
ui.horizontal(|ui| {
|
||||
ui.menu_button(format!("{} Add Command", ICON_ADD.codepoint), |ui| {
|
||||
let mut selected_cmd = None;
|
||||
@@ -190,10 +204,9 @@ impl SoundpadGui {
|
||||
.desired_width(f32::INFINITY),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
ui.add_space(5.0);
|
||||
|
||||
fn draw_hotkeys_table(&mut self, ui: &mut Ui) -> Option<HotkeyAction> {
|
||||
let conflicts = self.app_state.hotkey_config.find_conflicts();
|
||||
let conflict_slots: std::collections::HashSet<&str> =
|
||||
conflicts.into_iter().flat_map(|(a, b)| [a, b]).collect();
|
||||
@@ -380,7 +393,10 @@ impl SoundpadGui {
|
||||
}
|
||||
});
|
||||
|
||||
if let Some(action) = action {
|
||||
action
|
||||
}
|
||||
|
||||
fn handle_hotkey_action(&mut self, action: HotkeyAction) {
|
||||
match action {
|
||||
HotkeyAction::Remove(slot) => {
|
||||
make_request_async(Request::clear_hotkey(&slot));
|
||||
@@ -399,8 +415,6 @@ impl SoundpadGui {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn draw_header(&mut self, ui: &mut Ui) {
|
||||
ui.vertical_centered_justified(|ui| {
|
||||
|
||||
Reference in New Issue
Block a user