Refactor draw_files and draw_tree_node to improve maintainability and readability (#108)

- Extracted search field rendering to `draw_files_search_field`
- Extracted list rendering to `draw_files_list`
- Split `draw_tree_node` file and directory branch logic to `draw_tree_node_file` and `draw_tree_node_dir`

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
Tarasov Aleksandr
2026-05-17 17:07:32 +03:00
committed by GitHub
parent 0439cf815e
commit 78960cdc10
+33 -7
View File
@@ -774,8 +774,7 @@ impl SoundpadGui {
}); });
} }
fn draw_files(&mut self, ui: &mut Ui, area_size: Vec2) { fn draw_files_search_field(&mut self, ui: &mut Ui) {
ui.vertical(|ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
let search_field_response = ui.add_sized( let search_field_response = ui.add_sized(
[ui.available_width(), 22.0], [ui.available_width(), 22.0],
@@ -790,9 +789,9 @@ impl SoundpadGui {
self.app_state.search_field_id = Some(search_field_response.id); self.app_state.search_field_id = Some(search_field_response.id);
}); });
}
ui.separator(); fn draw_files_list(&mut self, ui: &mut Ui, area_size: Vec2) {
ScrollArea::vertical().id_salt(1).show(ui, |ui| { ScrollArea::vertical().id_salt(1).show(ui, |ui| {
ui.set_min_width(area_size.x); ui.set_min_width(area_size.x);
ui.set_min_height(area_size.y); ui.set_min_height(area_size.y);
@@ -825,17 +824,23 @@ impl SoundpadGui {
} }
}); });
}); });
}
fn draw_files(&mut self, ui: &mut Ui, area_size: Vec2) {
ui.vertical(|ui| {
self.draw_files_search_field(ui);
ui.separator();
self.draw_files_list(ui, area_size);
}); });
} }
fn draw_tree_node( fn draw_tree_node_dir(
ui: &mut Ui, ui: &mut Ui,
path: std::path::PathBuf, path: std::path::PathBuf,
app_state: &mut AppState, app_state: &mut AppState,
audio_player_state: &AudioPlayerState, audio_player_state: &AudioPlayerState,
actions: &mut Vec<FileAction>, actions: &mut Vec<FileAction>,
) { ) {
if path.is_dir() {
let dir_name = path let dir_name = path
.file_name() .file_name()
.unwrap_or_default() .unwrap_or_default()
@@ -896,7 +901,15 @@ impl SoundpadGui {
Self::draw_tree_node(ui, child, app_state, audio_player_state, actions); Self::draw_tree_node(ui, child, app_state, audio_player_state, actions);
} }
}); });
} else { }
fn draw_tree_node_file(
ui: &mut Ui,
path: std::path::PathBuf,
app_state: &mut AppState,
audio_player_state: &AudioPlayerState,
actions: &mut Vec<FileAction>,
) {
let file_name = path let file_name = path
.file_name() .file_name()
.unwrap_or_default() .unwrap_or_default()
@@ -1017,6 +1030,19 @@ impl SoundpadGui {
}); });
}); });
} }
fn draw_tree_node(
ui: &mut Ui,
path: std::path::PathBuf,
app_state: &mut AppState,
audio_player_state: &AudioPlayerState,
actions: &mut Vec<FileAction>,
) {
if path.is_dir() {
Self::draw_tree_node_dir(ui, path, app_state, audio_player_state, actions);
} else {
Self::draw_tree_node_file(ui, path, app_state, audio_player_state, actions);
}
} }
fn draw_footer(&mut self, ui: &mut Ui) { fn draw_footer(&mut self, ui: &mut Ui) {