Skip to content

Commit

Permalink
Add ability to show errors
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jan 23, 2024
1 parent 4705d89 commit a437c5f
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct CalculatorApp {
value: Option<f64>,
answer: Option<f64>,
last_operation: Option<Operator>,
error_message: Option<String>,
}

#[derive(serde::Deserialize, serde::Serialize)]
Expand Down Expand Up @@ -88,14 +89,18 @@ impl eframe::App for CalculatorApp {
ui.heading("Calculator");

ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
ui.label(&format!(
"{}",
if let Some(value) = self.value {
value
} else {
self.answer.unwrap_or_default()
}
));
if let Some(error_message) = &self.error_message {
ui.label(error_message)
} else {
ui.label(&format!(
"{}",
if let Some(value) = self.value {
value
} else {
self.answer.unwrap_or_default()
}
))
};
});

ui.horizontal(|ui| {
Expand Down

0 comments on commit a437c5f

Please sign in to comment.