Skip to content

Commit

Permalink
webpage: app: Run cargo fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and joaoantoniocardoso committed Feb 26, 2025
1 parent c26ab2e commit 86ae31c
Showing 1 changed file with 84 additions and 69 deletions.
153 changes: 84 additions & 69 deletions src/webpage/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,105 +209,120 @@ impl App {
}

fn show_helper_screen(&mut self, ctx: &Context) {
egui::CentralPanel::default()
.show(ctx, |ui| {
ui.horizontal_top(|ui| {
ui.label("Search:");
ui.add(
AutoCompleteTextEdit::new(
&mut self.search_help_mavlink_query,
mavlink_names,
),
);

if ui.button("Find").clicked() {
let mavlink_code = self.mavlink_code.clone();
ehttp::fetch(Request::get(format!("/{MAVLINK_HELPER}?name={}", self.search_help_mavlink_query)), move |res| {
egui::CentralPanel::default().show(ctx, |ui| {
ui.horizontal_top(|ui| {
ui.label("Search:");
ui.add(AutoCompleteTextEdit::new(
&mut self.search_help_mavlink_query,
mavlink_names,
));

if ui.button("Find").clicked() {
let mavlink_code = self.mavlink_code.clone();
ehttp::fetch(
Request::get(format!(
"/{MAVLINK_HELPER}?name={}",
self.search_help_mavlink_query
)),
move |res| {
let mut s = mavlink_code.lock();
*s = match res {
Ok(Response { bytes, .. }) => String::from_utf8(bytes).unwrap(),
Err(error) => format!("Error: {error:?}"),
};
});
}
});

let mut theme = egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx(), ui.style());
ui.collapsing("Theme", |ui| {
ui.group(|ui| {
theme.ui(ui);
theme.clone().store_in_memory(ui.ctx());
});
});

let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job = egui_extras::syntax_highlighting::highlight(
ui.ctx(),
ui.style(),
&theme,
string,
"js",
},
);
layout_job.wrap.max_width = wrap_width;
ui.fonts(|f| f.layout_job(layout_job))
};
}
});

egui::ScrollArea::vertical().show(ui, |ui| {
let mut mavlink_code = self.mavlink_code.lock().to_owned();
ui.add(
egui::TextEdit::multiline(&mut mavlink_code)
.font(egui::TextStyle::Monospace)
.code_editor()
.desired_rows(30)
.lock_focus(true)
.desired_width(500.0)
.layouter(&mut layouter),
);
*self.mavlink_code.lock() = mavlink_code;
let mut theme =
egui_extras::syntax_highlighting::CodeTheme::from_memory(ui.ctx(), ui.style());
ui.collapsing("Theme", |ui| {
ui.group(|ui| {
theme.ui(ui);
theme.clone().store_in_memory(ui.ctx());
});
});

ui.horizontal_top(|ui| {
if ui.button("Send").clicked() {
let mavlink_code = self.mavlink_code.lock();

let mut request = Request::post(format!("/{MAVLINK_POST}"), mavlink_code.clone().into_bytes());
request.headers.insert("Content-Type", "application/json");
let mut layouter = |ui: &egui::Ui, string: &str, wrap_width: f32| {
let mut layout_job = egui_extras::syntax_highlighting::highlight(
ui.ctx(),
ui.style(),
&theme,
string,
"js",
);
layout_job.wrap.max_width = wrap_width;
ui.fonts(|f| f.layout_job(layout_job))
};

let mavlink_code_post_response = self.mavlink_code_post_response.clone();
*mavlink_code_post_response.lock() = String::default();
ehttp::fetch(request, move |res| {
let mut s = mavlink_code_post_response.lock();
*s = match res {
Ok(Response { bytes, .. }) => String::from_utf8(bytes).unwrap(),
Err(error) => format!("Error: {error:?}"),
};
});
}
ui.label(format!("{}", *self.mavlink_code_post_response.lock()));
egui::ScrollArea::vertical().show(ui, |ui| {
let mut mavlink_code = self.mavlink_code.lock().to_owned();
ui.add(
egui::TextEdit::multiline(&mut mavlink_code)
.font(egui::TextStyle::Monospace)
.code_editor()
.desired_rows(30)
.lock_focus(true)
.desired_width(500.0)
.layouter(&mut layouter),
);
*self.mavlink_code.lock() = mavlink_code;
});

ui.horizontal_top(|ui| {
if ui.button("Send").clicked() {
let mavlink_code = self.mavlink_code.lock();

let mut request = Request::post(
format!("/{MAVLINK_POST}"),
mavlink_code.clone().into_bytes(),
);
request.headers.insert("Content-Type", "application/json");

let mavlink_code_post_response = self.mavlink_code_post_response.clone();
*mavlink_code_post_response.lock() = String::default();
ehttp::fetch(request, move |res| {
let mut s = mavlink_code_post_response.lock();
*s = match res {
Ok(Response { bytes, .. }) => String::from_utf8(bytes).unwrap(),
Err(error) => format!("Error: {error:?}"),
};
});
}
ui.label(format!("{}", *self.mavlink_code_post_response.lock()));
});
});
}

fn show_control_screen(&mut self, ctx: &Context) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.label("Control");
if ui.button("Arm").clicked() {
let mut request = Request::post(format!("/{CONTROL_VEHICLES}/arm"), "{
let mut request = Request::post(
format!("/{CONTROL_VEHICLES}/arm"),
"{
\"system_id\": 1,
\"component_id\": 1,
\"force\": true
}".into());
}"
.into(),
);
request.headers.insert("Content-Type", "application/json");
ehttp::fetch(request, |res| {
log::info!("Arm response: {res:?}");
});
}
if ui.button("Disarm").clicked() {
let mut request = Request::post(format!("/{CONTROL_VEHICLES}/disarm"), "{
let mut request = Request::post(
format!("/{CONTROL_VEHICLES}/disarm"),
"{
\"system_id\": 1,
\"component_id\": 1,
\"force\": true
}".into());
}"
.into(),
);
request.headers.insert("Content-Type", "application/json");
ehttp::fetch(request, |res| {
log::info!("Disarm response: {res:?}");
Expand Down

0 comments on commit 86ae31c

Please sign in to comment.