Skip to content

Commit 854248c

Browse files
committed
wip: native home-screen
1 parent 51cf38f commit 854248c

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

application/apps/indexer/gui/application/src/host/ui/home/mod.rs

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -88,41 +88,65 @@ pub fn draw_quick_actions(ui: &mut egui::Ui, state: &mut HomeSettings) {
8888
egui::ScrollArea::vertical()
8989
.id_salt("quick_actions_scroll")
9090
.show(ui, |ui| {
91-
for action in &state.quick_actions {
92-
ui.push_id(&action.id, |ui| {
93-
let (rect, response) = ui.allocate_exact_size(item_size, egui::Sense::click());
94-
95-
let visuals = ui.style().interact(&response);
96-
if response.hovered() || response.is_pointer_button_down_on() {
97-
ui.painter()
98-
.rect_filled(rect.shrink(2.0), 6.0, visuals.bg_fill);
99-
}
91+
action_button(ui, item_size, icons::regular::FOLDER, "File(s)", || {
92+
println!("Files clicked");
93+
});
10094

101-
let inner_rect = rect.shrink(6.0);
102-
103-
ui.scope_builder(egui::UiBuilder::new().max_rect(inner_rect), |ui| {
104-
ui.with_layout(
105-
egui::Layout::top_down_justified(egui::Align::Center),
106-
|ui| {
107-
ui.add_space(2.0);
108-
ui.label(egui::RichText::new(&action.icon).size(22.0));
109-
ui.add(
110-
egui::Label::new(egui::RichText::new(&action.label).small())
111-
.wrap_mode(egui::TextWrapMode::Truncate),
112-
);
113-
},
114-
);
115-
});
95+
action_button(
96+
ui,
97+
item_size,
98+
icons::regular::PLUGS_CONNECTED,
99+
"Connections",
100+
|| {
101+
println!("Connections clicked");
102+
},
103+
);
104+
105+
action_button(ui, item_size, icons::regular::TERMINAL, "Terminal", || {
106+
println!("Terminal clicked");
107+
});
108+
});
109+
}
116110

117-
if response.clicked() {
118-
println!("Quick action clicked: {}", action.id);
119-
}
120-
response.on_hover_text(&action.label);
111+
fn action_button(
112+
ui: &mut egui::Ui,
113+
size: egui::Vec2,
114+
icon: &str,
115+
label: &str,
116+
on_click: impl FnOnce(),
117+
) {
118+
ui.push_id(format!("quick_action_{}", label.to_lowercase()), |ui| {
119+
let (rect, response) = ui.allocate_exact_size(size, egui::Sense::click());
121120

122-
ui.add_space(4.0);
123-
});
124-
}
121+
let visuals = ui.style().interact(&response);
122+
123+
if response.hovered() || response.is_pointer_button_down_on() {
124+
ui.painter()
125+
.rect_filled(rect.shrink(2.0), 6.0, visuals.bg_fill);
126+
}
127+
128+
let inner_rect = rect.shrink(6.0);
129+
130+
ui.scope_builder(egui::UiBuilder::new().max_rect(inner_rect), |ui| {
131+
ui.with_layout(
132+
egui::Layout::top_down_justified(egui::Align::Center),
133+
|ui| {
134+
ui.add_space(2.0);
135+
ui.label(egui::RichText::new(icon).size(22.0));
136+
ui.add(
137+
egui::Label::new(egui::RichText::new(label).small())
138+
.wrap_mode(egui::TextWrapMode::Truncate),
139+
);
140+
},
141+
);
125142
});
143+
144+
if response.clicked() {
145+
on_click();
146+
}
147+
148+
ui.add_space(4.0);
149+
});
126150
}
127151

128152
fn draw_recent_files(ui: &mut egui::Ui, state: &mut HomeSettings) {
@@ -269,15 +293,17 @@ fn draw_favorite_folders(
269293
.id_salt(folder.path.to_string_lossy())
270294
.open(expand)
271295
.show(ui, |ui| {
272-
if ui
273-
.add(
274-
Button::new(RichText::new(icons::regular::TRASH).size(12.0))
275-
.small(),
276-
)
277-
.on_hover_text("Remove folder")
278-
.clicked()
279-
{
280-
remove_path = Some(folder.path.clone());
296+
if state.favorite_search.is_empty() {
297+
if ui
298+
.add(
299+
Button::new(RichText::new(icons::regular::TRASH).size(12.0))
300+
.small(),
301+
)
302+
.on_hover_text("Remove folder")
303+
.clicked()
304+
{
305+
remove_path = Some(folder.path.clone());
306+
}
281307
}
282308

283309
for (file_name, size_info) in &folder.files {

application/apps/indexer/gui/application/src/host/ui/home/settings.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{fs, path::PathBuf};
33

44
#[derive(Serialize, Deserialize, Default, Debug)]
55
pub struct HomeSettings {
6-
pub quick_actions: Vec<QuickAction>,
76
pub recent_files: Vec<RecentFile>,
87
pub favorite_folders: Vec<FavoriteFolder>,
98

@@ -37,24 +36,6 @@ impl HomeSettings {
3736
}
3837

3938
pub fn with_test_data(mut self) -> HomeSettings {
40-
self.quick_actions = vec![
41-
QuickAction {
42-
id: "files".to_string(),
43-
label: "File(s)".to_string(),
44-
icon: "📂".to_string(),
45-
},
46-
QuickAction {
47-
id: "connections".to_string(),
48-
label: "Connections".to_string(),
49-
icon: "📡".to_string(),
50-
},
51-
QuickAction {
52-
id: "terminal".to_string(),
53-
label: "Terminal".to_string(),
54-
icon: "💻".to_string(),
55-
},
56-
];
57-
5839
self.recent_files = vec![
5940
RecentFile {
6041
path: PathBuf::from("C:/Users/Example/Documents/file1.json"),
@@ -98,13 +79,6 @@ impl HomeSettings {
9879
}
9980
}
10081

101-
#[derive(Serialize, Deserialize, Debug)]
102-
pub struct QuickAction {
103-
pub id: String,
104-
pub label: String,
105-
pub icon: String,
106-
}
107-
10882
#[derive(Serialize, Deserialize, Debug)]
10983
pub struct RecentFile {
11084
pub path: PathBuf,

0 commit comments

Comments
 (0)