Skip to content

Commit

Permalink
Set width of display area to fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jan 30, 2024
1 parent 360a69c commit 3f882d0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
36 changes: 21 additions & 15 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use egui::{Button, Vec2};
use egui::{Button, Layout, RichText, Vec2};
use log::error;

const BUTTON_SIZE: Vec2 = Vec2::new(60.0, 40.0);
Expand Down Expand Up @@ -82,6 +82,21 @@ impl CalculatorApp {
fn log_debug_info_for_operator_click(&mut self, operator: Operator) {
error!("[current operator received: {:?}] {:?}", operator, self);
}

fn display_value(&self) -> String {
if let Some(error_message) = &self.error_message {
error_message.clone()
} else {
format!(
"{}",
if let Some(value) = self.value {
value
} else {
self.answer.unwrap_or_default()
}
)
}
}
}

impl eframe::App for CalculatorApp {
Expand Down Expand Up @@ -116,20 +131,11 @@ impl eframe::App for CalculatorApp {

egui::CentralPanel::default().show(ctx, |ui| {
// The central panel the region left after adding TopPanel's and SidePanel's
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
if let Some(error_message) = &self.error_message {
ui.heading(error_message)
} else {
ui.heading(&format!(
"{}",
if let Some(value) = self.value {
value
} else {
self.answer.unwrap_or_default()
}
))
};
});
ui.allocate_ui_with_layout(
Vec2::new(250., 40.),
Layout::right_to_left(egui::Align::BOTTOM),
|ui| ui.label(RichText::new(self.display_value()).heading()),
);

ui.horizontal(|ui| {
if ui.add(Button::new("7").min_size(BUTTON_SIZE)).clicked() {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ fn main() -> eframe::Result<()> {

let native_options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([280.0, 230.0])
.with_min_inner_size([280.0, 230.0])
.with_inner_size([280.0, 250.0])
.with_min_inner_size([280.0, 250.0])
.with_icon(
eframe::icon_data::from_png_bytes(&include_bytes!("../assets/icon-256.png")[..])
.unwrap(),
Expand Down

0 comments on commit 3f882d0

Please sign in to comment.