Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend status report element #919

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
Comment on lines +16 to +18
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this implementation is a bit weird, as it results in lots of statuses being removed at once. Might be better to just remove the oldest status, until only 5 are left. Maybe VecDeque is a better type for this than Vec, as it provides convenient push_back/pop_front methods.

But that's something that can be fixed later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Thanks for the feedback! Your right, VecDeque does look convenient. I'll look into it.

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