Skip to content

Commit

Permalink
Adjust sizes for new button sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jan 30, 2024
1 parent ef3b84e commit 360a69c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
41 changes: 21 additions & 20 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use egui::{Button, Vec2};
use log::error;

const BUTTON_SIZE: Vec2 = Vec2::new(60.0, 40.0);

// We derive Deserialize/Serialize so we can persist app state on shutdown.
#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)] // if we add new fields, give them default values when deserializing old state
Expand Down Expand Up @@ -113,13 +116,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.heading("Calculator");

ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
if let Some(error_message) = &self.error_message {
ui.label(error_message)
ui.heading(error_message)
} else {
ui.label(&format!(
ui.heading(&format!(
"{}",
if let Some(value) = self.value {
value
Expand All @@ -131,56 +132,56 @@ impl eframe::App for CalculatorApp {
});

ui.horizontal(|ui| {
if ui.button("7").clicked() {
if ui.add(Button::new("7").min_size(BUTTON_SIZE)).clicked() {
self.click_number(7.0);
};
if ui.button("8").clicked() {
if ui.add(Button::new("8").min_size(BUTTON_SIZE)).clicked() {
self.click_number(8.0);
};
if ui.button("9").clicked() {
if ui.add(Button::new("9").min_size(BUTTON_SIZE)).clicked() {
self.click_number(9.0);
};
if ui.button("/").clicked() {};
if ui.add(Button::new("/").min_size(BUTTON_SIZE)).clicked() {};
});

ui.horizontal(|ui| {
if ui.button("4").clicked() {
if ui.add(Button::new("4").min_size(BUTTON_SIZE)).clicked() {
self.click_number(4.0);
};
if ui.button("5").clicked() {
if ui.add(Button::new("5").min_size(BUTTON_SIZE)).clicked() {
self.click_number(5.0);
};
if ui.button("6").clicked() {
if ui.add(Button::new("6").min_size(BUTTON_SIZE)).clicked() {
self.click_number(6.0);
};
if ui.button("x").clicked() {};
if ui.add(Button::new("x").min_size(BUTTON_SIZE)).clicked() {}
});

ui.horizontal(|ui| {
if ui.button("1").clicked() {
if ui.add(Button::new("1").min_size(BUTTON_SIZE)).clicked() {
self.click_number(1.0);
};
if ui.button("2").clicked() {
if ui.add(Button::new("2").min_size(BUTTON_SIZE)).clicked() {
self.click_number(2.0);
};
if ui.button("3").clicked() {
if ui.add(Button::new("3").min_size(BUTTON_SIZE)).clicked() {
self.click_number(3.0);
};
if ui.button("-").clicked() {};
if ui.add(Button::new("-").min_size(BUTTON_SIZE)).clicked() {};
});

ui.horizontal(|ui| {
if ui.button("0").clicked() {
if ui.add(Button::new("0").min_size(BUTTON_SIZE)).clicked() {
self.click_number(0.0);
};
if ui.button("C").clicked() {
if ui.add(Button::new("C").min_size(BUTTON_SIZE)).clicked() {
self.answer = None;
self.value = None;
// TODO update C for new fields
// TODO ensure we don't miss fields in the future
};
if ui.button("=").clicked() {};
if ui.button("+").clicked() {
if ui.add(Button::new("=").min_size(BUTTON_SIZE)).clicked() {};
if ui.add(Button::new("+").min_size(BUTTON_SIZE)).clicked() {
self.click_operator(Operator::Add);
};
});
Expand Down
5 changes: 2 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ fn main() -> eframe::Result<()> {

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

..Default::default()
};
eframe::run_native(
Expand Down

0 comments on commit 360a69c

Please sign in to comment.