Skip to content

Commit b783fbe

Browse files
committed
ASking to the user for eds file
1 parent 0d49a93 commit b783fbe

1 file changed

Lines changed: 54 additions & 2 deletions

File tree

src/main.rs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
use eframe::{egui, NativeOptions};
44
use std::process::Command;
5-
5+
use std::path::PathBuf;
66

77
enum AppView {
88
SelectInterface,
99
SelectNodeId,
10+
SelectEDSFile,
1011
Main
1112
}
1213
struct MyApp {
@@ -15,6 +16,7 @@ struct MyApp {
1516
selected_can_interface: Option<String>,
1617
selected_node_id: Option<u8>,
1718
node_id_str : String,
19+
eds_file_path : Option<PathBuf>,
1820
}
1921

2022

@@ -26,6 +28,7 @@ impl Default for MyApp {
2628
selected_can_interface: None,
2729
selected_node_id: None,
2830
node_id_str: String::new(),
31+
eds_file_path: None,
2932
}
3033
}
3134
}
@@ -37,6 +40,7 @@ impl eframe::App for MyApp {
3740
match self.current_view {
3841
AppView::SelectInterface => self.draw_interface_view(ui),
3942
AppView::SelectNodeId => self.draw_node_id_view(ui),
43+
AppView::SelectEDSFile => self.draw_eds_file_view(ui),
4044
AppView::Main => self.draw_main_view(ui)
4145
}
4246
});
@@ -129,7 +133,55 @@ impl MyApp {
129133
}
130134

131135
let is_start_enabled = self.selected_node_id.is_some();
132-
if ui.add_enabled(is_start_enabled, egui::Button::new("Start")).clicked() {
136+
if ui.add_enabled(is_start_enabled, egui::Button::new("Next →")).clicked() {
137+
self.current_view = AppView::SelectEDSFile;
138+
}
139+
});
140+
});
141+
});
142+
}
143+
144+
/// Draws the UI for selecting an EDS file using a centered window.
145+
fn draw_eds_file_view(&mut self, ui: &mut egui::Ui) {
146+
egui::Window::new("EDS File Selection")
147+
.title_bar(false)
148+
.resizable(false)
149+
.collapsible(false)
150+
.anchor(egui::Align2::CENTER_CENTER, egui::vec2(0.0, 0.0))
151+
.show(ui.ctx(), |ui| {
152+
ui.with_layout(egui::Layout::top_down(egui::Align::Center), |ui| {
153+
ui.set_width(350.0); // A bit wider for file paths
154+
ui.heading("Step 3: Select EDS File");
155+
ui.label("(Optional)");
156+
ui.add_space(10.0);
157+
158+
// Display the currently selected file path
159+
let file_path_text = if let Some(path) = &self.eds_file_path {
160+
path.display().to_string()
161+
} else {
162+
"No file selected".to_string()
163+
};
164+
ui.label(file_path_text);
165+
ui.add_space(10.0);
166+
167+
// Button to open the native file dialog
168+
if ui.button("Browse...").clicked() {
169+
// Use rfd to pick a file
170+
let file = rfd::FileDialog::new()
171+
.add_filter("CANopen EDS", &["eds"]) // Filter for .eds files
172+
.pick_file();
173+
174+
// Store the result
175+
self.eds_file_path = file;
176+
}
177+
ui.add_space(20.0);
178+
179+
// Navigation buttons
180+
ui.horizontal(|ui| {
181+
if ui.button("← Back").clicked() {
182+
self.current_view = AppView::SelectNodeId;
183+
}
184+
if ui.button("Start").clicked() {
133185
self.current_view = AppView::Main;
134186
}
135187
});

0 commit comments

Comments
 (0)