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

Replace Vec with VecDeque and remove status updates as they are added #952

Merged
merged 1 commit into from
Aug 13, 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
1 change: 1 addition & 0 deletions crates/fj-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl Model {
}
Err(_) => String::from("Failed to fetch command output"),
};
status.clear_status();
status.update_status(&format!(
"Failed to compile model:\n{}",
output
Expand Down
24 changes: 17 additions & 7 deletions crates/fj-interop/src/status_report.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
//! Struct to store and update status messages
use std::collections::VecDeque;

/// Struct to store and update status messages
pub struct StatusReport {
status: Vec<String>,
status: VecDeque<String>,
}

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

/// Update the status
pub fn update_status(&mut self, status: &str) {
if self.status.len() >= 5 {
self.clear_status();
let status = format!("\n{}", status.to_owned());
self.status.push_back(status);
if self.status.len() > 5 {
for _ in 0..(self.status.len() - 5) {
self.status.pop_front();
}
}
self.status.push(status.to_string());
}

/// Get current status
pub fn status(&self) -> String {
self.status.join("\n")
self.status
.iter()
.map(std::string::ToString::to_string)
.collect::<String>()
}

/// Reset status
fn clear_status(&mut self) {
pub fn clear_status(&mut self) {
self.status.clear();
}
}
Expand Down
7 changes: 2 additions & 5 deletions crates/fj-viewer/src/graphics/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,8 @@ impl Renderer {
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),
egui::RichText::new(format!("Status:{}", status.status()))
.color(egui::Color32::BLACK),
))
})
});
Expand Down