servoshell: Port SelectDevice dialog code to use egui instead of tinyfiledialogs (#35657)

Signed-off-by: L Ashwin B <lashwinib@gmail.com>
This commit is contained in:
chickenleaf 2025-02-26 15:29:47 +05:30 committed by GitHub
parent 0568820f01
commit e956f0c5af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 69 additions and 38 deletions

View file

@ -39,6 +39,11 @@ pub enum Dialog {
message: String,
request: Option<PermissionRequest>,
},
SelectDevice {
devices: Vec<String>,
selected_device_index: usize,
response_sender: IpcSender<Option<String>>,
},
}
impl Dialog {
@ -110,6 +115,17 @@ impl Dialog {
}
}
pub fn new_device_selection_dialog(
devices: Vec<String>,
response_sender: IpcSender<Option<String>>,
) -> Self {
Dialog::SelectDevice {
devices,
selected_device_index: 0,
response_sender,
}
}
pub fn update(&mut self, ctx: &egui::Context) -> bool {
match self {
Dialog::File {
@ -230,7 +246,7 @@ impl Dialog {
ref mut request,
} => {
let mut is_open = true;
Modal::new("input".into()).show(ctx, |ui| {
Modal::new("authentication".into()).show(ctx, |ui| {
let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
frame.content_ui.set_min_width(150.0);
@ -302,6 +318,54 @@ impl Dialog {
});
is_open
},
Dialog::SelectDevice {
devices,
selected_device_index,
response_sender,
} => {
let mut is_open = true;
let modal = Modal::new("device_picker".into());
modal.show(ctx, |ui| {
let mut frame = egui::Frame::default().inner_margin(10.0).begin(ui);
frame.content_ui.set_min_width(150.0);
frame.content_ui.heading("Choose a Device");
frame.content_ui.add_space(10.0);
egui::ComboBox::from_label("")
.selected_text(&devices[*selected_device_index + 1])
.show_ui(&mut frame.content_ui, |ui| {
for i in (0..devices.len() - 1).step_by(2) {
let device_name = &devices[i + 1];
ui.selectable_value(selected_device_index, i, device_name);
}
});
frame.end(ui);
egui::Sides::new().show(
ui,
|_ui| {},
|ui| {
if ui.button("Ok").clicked() {
if let Err(e) = response_sender
.send(Some(devices[*selected_device_index].clone()))
{
warn!("Failed to send device selection: {}", e);
}
is_open = false;
}
if ui.button("Cancel").clicked() {
if let Err(e) = response_sender.send(None) {
warn!("Failed to send cancellation: {}", e);
}
is_open = false;
}
},
);
});
is_open
},
}
}
}