Skip to content

Commit

Permalink
Merge pull request #919 from devanlooches/main
Browse files Browse the repository at this point in the history
Extend status report element
  • Loading branch information
hannobraun authored Aug 8, 2022
2 parents 98b8a86 + 27e4059 commit bbf3b0d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 12 deletions.
14 changes: 13 additions & 1 deletion crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,25 @@ impl Model {

let command = command_root
.arg("build")
.arg("-q")
.args(["--manifest-path", &manifest_path]);
let exit_status = command.status()?;

if exit_status.success() {
status.update_status("Model compiled successfully!");
} else {
status.update_status("Error compiling the model!");
let output = match command.output() {
Ok(output) => {
String::from_utf8(output.stderr).unwrap_or_else(|_| {
String::from("Failed to fetch command output")
})
}
Err(_) => String::from("Failed to fetch command output"),
};
status.update_status(&format!(
"Failed to compile model:\n{}",
output
));
return Err(Error::Compile);
}

Expand Down
20 changes: 13 additions & 7 deletions crates/fj-interop/src/status_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@
/// Struct to store and update status messages
pub struct StatusReport {
status: String,
status: Vec<String>,
}

impl StatusReport {
/// Create a new ``StatusReport`` instance with a blank status
pub fn new() -> Self {
Self {
status: String::new(),
}
Self { status: Vec::new() }
}

/// Update the status
pub fn update_status(&mut self, status: &str) {
self.status = status.to_string();
if self.status.len() >= 5 {
self.clear_status();
}
self.status.push(status.to_string());
}

/// Get current status
pub fn status(&self) -> &str {
self.status.as_str()
pub fn status(&self) -> String {
self.status.join("\n")
}

/// Reset status
fn clear_status(&mut self) {
self.status.clear();
}
}

Expand Down
17 changes: 13 additions & 4 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,8 @@ impl Renderer {
}

let line_drawing_available = self.is_line_drawing_available();
egui::SidePanel::left("fj-left-panel").show(&self.egui.context, |ui| {
ui.add_space(16.0);

ui.label(format!("Status Report:\n{}", status.status()));

egui::SidePanel::left("fj-left-panel").show(&self.egui.context, |ui| {
ui.add_space(16.0);

ui.group(|ui| {
Expand Down Expand Up @@ -574,6 +571,18 @@ impl Renderer {
ui.add_space(16.0);
});

egui::Area::new("fj-status-message").show(&self.egui.context, |ui| {
ui.group(|ui| {
ui.add(egui::Label::new(
egui::RichText::new(format!(
"Status:\n{}",
status.status()
))
.color(egui::Color32::BLACK),
))
})
});

// End the UI frame. We could now handle the output and draw the UI with the backend.
let egui_output = self.egui.context.end_frame();
let egui_paint_jobs = self.egui.context.tessellate(egui_output.shapes);
Expand Down

0 comments on commit bbf3b0d

Please sign in to comment.