Update gui
This commit is contained in:
parent
cd1eb22a7d
commit
9a12104044
1292
Cargo.lock
generated
1292
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -14,18 +14,20 @@ categories = ["command-line-utilities"]
|
||||
[workspace]
|
||||
members = [
|
||||
".",
|
||||
"./rpn_rs_tui/",
|
||||
"./rpn_rs_gui/",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
crossterm = "0.18"
|
||||
tui = { version = "0.14", default-features = false, features = ['crossterm'] }
|
||||
serde = {version = "1.0", features = ["derive"]}
|
||||
# confy = "0.4.0"
|
||||
toml = "0.4.2"
|
||||
lazy_static = "1.4.0"
|
||||
rust_decimal = { version = "1.29.1", features=["maths"] }
|
||||
rust_decimal_macros = "1.29.1"
|
||||
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
|
||||
tracing-appender = "0.2.2"
|
||||
tracing = "0.1.37"
|
||||
|
||||
[dependencies.confy]
|
||||
# TODO: Update this to v0.5.0 when it finally comes out -- for now, use latest git master
|
||||
|
229
rpn_rs_gui/Cargo.lock
generated
229
rpn_rs_gui/Cargo.lock
generated
@ -35,7 +35,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cee8cf1202a4f94d31837f1902ab0a75c77b65bf59719e093703abe83efd74ec"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -48,7 +48,7 @@ dependencies = [
|
||||
"accesskit_consumer",
|
||||
"objc2",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -62,7 +62,7 @@ dependencies = [
|
||||
"async-channel",
|
||||
"atspi",
|
||||
"futures-lite",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
"serde",
|
||||
"zbus",
|
||||
]
|
||||
@ -77,7 +77,7 @@ dependencies = [
|
||||
"accesskit_consumer",
|
||||
"arrayvec",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
"paste",
|
||||
"windows",
|
||||
]
|
||||
@ -92,7 +92,7 @@ dependencies = [
|
||||
"accesskit_macos",
|
||||
"accesskit_unix",
|
||||
"accesskit_windows",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
"winit",
|
||||
]
|
||||
|
||||
@ -159,7 +159,7 @@ dependencies = [
|
||||
"objc-foundation",
|
||||
"objc_id",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
"thiserror",
|
||||
"winapi",
|
||||
"x11rb",
|
||||
@ -185,7 +185,7 @@ checksum = "1b19760fa2b7301cf235360ffd6d3558b1ed4249edd16d6cca8d690cee265b95"
|
||||
dependencies = [
|
||||
"event-listener",
|
||||
"futures-core",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -412,6 +412,12 @@ dependencies = [
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cassowary"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.0.79"
|
||||
@ -478,6 +484,17 @@ dependencies = [
|
||||
"crossbeam-utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "confy"
|
||||
version = "0.5.1"
|
||||
source = "git+https://github.com/rust-cli/confy/#700337e5a3fbc12f4f49fc9b7ce449b1b71040ee"
|
||||
dependencies = [
|
||||
"directories",
|
||||
"serde",
|
||||
"serde_yaml",
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console_error_panic_hook"
|
||||
version = "0.1.7"
|
||||
@ -556,6 +573,31 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm"
|
||||
version = "0.18.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e86d73f2a0b407b5768d10a8c720cf5d2df49a9efc10ca09176d201ead4b7fb"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"crossterm_winapi",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"mio 0.7.14",
|
||||
"parking_lot 0.11.2",
|
||||
"signal-hook",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossterm_winapi"
|
||||
version = "0.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c2265c3f8e080075d9b6417aa72293fc71662f34b4af2612d8d1b074d29510db"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crypto-common"
|
||||
version = "0.1.6"
|
||||
@ -593,6 +635,15 @@ dependencies = [
|
||||
"crypto-common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "directories"
|
||||
version = "4.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210"
|
||||
dependencies = [
|
||||
"dirs-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "directories-next"
|
||||
version = "2.0.0"
|
||||
@ -795,7 +846,7 @@ dependencies = [
|
||||
"ecolor",
|
||||
"emath",
|
||||
"nohash-hasher",
|
||||
"parking_lot",
|
||||
"parking_lot 0.12.1",
|
||||
"serde",
|
||||
]
|
||||
|
||||
@ -1139,6 +1190,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.9"
|
||||
@ -1206,6 +1263,19 @@ dependencies = [
|
||||
"adler",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.7.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8067b404fe97c70829f082dec8bcf4f71225d7eaea1d8645349cb76fa06205cc"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"log",
|
||||
"miow",
|
||||
"ntapi",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
version = "0.8.5"
|
||||
@ -1218,6 +1288,15 @@ dependencies = [
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miow"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9f1c5b025cda876f66ef43a113f91ebc9f4ccef34843000e0adf6ebbab84e21"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ndk"
|
||||
version = "0.7.0"
|
||||
@ -1298,6 +1377,15 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ntapi"
|
||||
version = "0.3.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c28774a7fd2fbb4f0babd8237ce554b73af68021b5f695a3cebd6c59bac0980f"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nu-ansi-term"
|
||||
version = "0.46.0"
|
||||
@ -1433,6 +1521,17 @@ version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72"
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99"
|
||||
dependencies = [
|
||||
"instant",
|
||||
"lock_api",
|
||||
"parking_lot_core 0.8.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot"
|
||||
version = "0.12.1"
|
||||
@ -1440,7 +1539,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f"
|
||||
dependencies = [
|
||||
"lock_api",
|
||||
"parking_lot_core",
|
||||
"parking_lot_core 0.9.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "parking_lot_core"
|
||||
version = "0.8.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"instant",
|
||||
"libc",
|
||||
"redox_syscall 0.2.16",
|
||||
"smallvec",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1652,18 +1765,37 @@ dependencies = [
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rpn_rs2"
|
||||
name = "rpn_rs"
|
||||
version = "0.6.0"
|
||||
dependencies = [
|
||||
"confy",
|
||||
"crossterm",
|
||||
"lazy_static",
|
||||
"serde",
|
||||
"toml",
|
||||
"tui",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rpn_rs_gui"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"eframe",
|
||||
"egui",
|
||||
"rpn_rs",
|
||||
"serde",
|
||||
"tracing-subscriber",
|
||||
"tracing-wasm",
|
||||
"wasm-bindgen-futures",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
@ -1741,6 +1873,18 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.8.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "578a7433b776b56a35785ed5ce9a7e777ac0598aac5a6dd1b4b18a307c7fc71b"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"ryu",
|
||||
"serde",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha1"
|
||||
version = "0.10.5"
|
||||
@ -1761,6 +1905,26 @@ dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7e31d442c16f047a671b5a71e2161d6e68814012b7f5379d269ebd915fac2729"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"mio 0.7.14",
|
||||
"signal-hook-registry",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "signal-hook-registry"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.7"
|
||||
@ -1937,6 +2101,15 @@ version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.4.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.5.1"
|
||||
@ -2029,6 +2202,19 @@ version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0609f771ad9c6155384897e1df4d948e692667cc0588548b68eb44d052b27633"
|
||||
|
||||
[[package]]
|
||||
name = "tui"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ced152a8e9295a5b168adc254074525c17ac4a83c90b2716274cc38118bddc9"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cassowary",
|
||||
"crossterm",
|
||||
"unicode-segmentation",
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.16.0"
|
||||
@ -2066,6 +2252,18 @@ dependencies = [
|
||||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.3.1"
|
||||
@ -2468,7 +2666,7 @@ dependencies = [
|
||||
"instant",
|
||||
"libc",
|
||||
"log",
|
||||
"mio",
|
||||
"mio 0.8.5",
|
||||
"ndk",
|
||||
"objc2",
|
||||
"once_cell",
|
||||
@ -2536,6 +2734,15 @@ version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d2d7d3948613f75c98fd9328cfdcc45acc4d360655289d0a7d4ec931392200a3"
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zbus"
|
||||
version = "3.9.0"
|
||||
|
@ -18,6 +18,7 @@ eframe = { version = "0.21.0", default-features = false, features = [
|
||||
|
||||
# You only need serde if you want app persistence:
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
tracing = "0.1.37"
|
||||
|
||||
# native:
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
|
@ -6,6 +6,11 @@ var filesToCache = [
|
||||
'./eframe_template_bg.wasm',
|
||||
];
|
||||
|
||||
// self.addEventListener('keydown', function (e) {
|
||||
// console.log("Got keydown", e);
|
||||
// e.preventDefault();
|
||||
// })
|
||||
|
||||
/* Start the service worker and cache all of the app's content */
|
||||
self.addEventListener('install', function (e) {
|
||||
e.waitUntil(
|
||||
|
@ -1,5 +1,12 @@
|
||||
use egui::Key;
|
||||
use rpn_rs::calc::Calculator;
|
||||
use egui::{Button, Color32, FontId, Grid, Key, RichText, Rounding, Stroke, Vec2};
|
||||
use rpn_rs::calc::{errors::CalculatorError, Calculator};
|
||||
use tracing::{error, info};
|
||||
|
||||
const DEFAULT_FONT_SIZE: f32 = 45.0;
|
||||
const STACK_FONT_SIZE: f32 = 25.0;
|
||||
const DEFAULT_FONT: FontId = FontId::monospace(DEFAULT_FONT_SIZE);
|
||||
const BUTTON_SPACING: Vec2 = Vec2 { x: 0.0, y: 0.0 };
|
||||
const BUTTON_PADDING: Vec2 = Vec2 { x: 24.0, y: 5.0 };
|
||||
|
||||
/// We derive Deserialize/Serialize so we can persist app state on shutdown.
|
||||
#[derive(serde::Deserialize, serde::Serialize)]
|
||||
@ -10,9 +17,8 @@ pub struct TemplateApp {
|
||||
// Example stuff:
|
||||
label: String,
|
||||
|
||||
// this how you opt-out of serialization of a member
|
||||
#[serde(skip)]
|
||||
value: f32,
|
||||
latest_error: Option<CalculatorError>,
|
||||
}
|
||||
|
||||
impl Default for TemplateApp {
|
||||
@ -21,7 +27,7 @@ impl Default for TemplateApp {
|
||||
calculator: Calculator::default(),
|
||||
// Example stuff:
|
||||
label: "Hello World!".to_owned(),
|
||||
value: 2.7,
|
||||
latest_error: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,6 +46,14 @@ impl TemplateApp {
|
||||
|
||||
Default::default()
|
||||
}
|
||||
|
||||
fn calculator_input(&mut self, c: char, error_state: &mut ErrorState) {
|
||||
if let Err(e) = self.calculator.take_input(c) {
|
||||
error_state.errored(e);
|
||||
} else {
|
||||
error_state.success();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl eframe::App for TemplateApp {
|
||||
@ -51,7 +65,7 @@ impl eframe::App for TemplateApp {
|
||||
/// Called each time the UI needs repainting, which may be many times per second.
|
||||
/// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`.
|
||||
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||
let Self { label, value, .. } = self;
|
||||
let Self { label, .. } = self;
|
||||
|
||||
// Examples of how to create different panels and windows.
|
||||
// Pick whichever suits you.
|
||||
@ -70,47 +84,15 @@ impl eframe::App for TemplateApp {
|
||||
});
|
||||
});
|
||||
|
||||
egui::SidePanel::left("side_panel").show(ctx, |ui| {
|
||||
ui.heading("Side Panel");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Write something: ");
|
||||
ui.text_edit_singleline(label);
|
||||
});
|
||||
|
||||
ui.add(egui::Slider::new(value, 0.0..=10.0).text("value"));
|
||||
if ui.button("Increment").clicked() {
|
||||
*value += 1.0;
|
||||
}
|
||||
|
||||
ui.label(format!("{:?}", self.calculator.stack.iter().next()));
|
||||
|
||||
// ui.add(ui.text_edit_singleline(self.calculator.stack.iter().next().map(|_| String::from("e")).unwrap_or_default()));
|
||||
|
||||
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
ui.label("powered by ");
|
||||
ui.hyperlink_to("egui", "https://github.com/emilk/egui");
|
||||
ui.label(" and ");
|
||||
ui.hyperlink_to(
|
||||
"eframe",
|
||||
"https://github.com/emilk/egui/tree/master/crates/eframe",
|
||||
);
|
||||
ui.label(".");
|
||||
});
|
||||
});
|
||||
});
|
||||
let mut error_state = ErrorState::NoModify;
|
||||
|
||||
egui::CentralPanel::default().show(ctx, |ui| {
|
||||
ui.style_mut().spacing.button_padding = BUTTON_PADDING;
|
||||
|
||||
// The central panel the region left after adding TopPanel's and SidePanel's
|
||||
|
||||
ui.heading("eframe template");
|
||||
ui.hyperlink("https://github.com/emilk/eframe_template");
|
||||
ui.add(egui::github_link_file!(
|
||||
"https://github.com/emilk/eframe_template/blob/master/",
|
||||
"Source code."
|
||||
));
|
||||
ui.heading("rpn_rs_gui");
|
||||
ui.hyperlink("https://gitea.austen-wares.com/stonewareslord/rpn_rs");
|
||||
|
||||
ui.input(|i| {
|
||||
if i.events.is_empty() {
|
||||
@ -120,45 +102,45 @@ impl eframe::App for TemplateApp {
|
||||
for e in i.events.iter() {
|
||||
match e {
|
||||
egui::Event::Text(t) => {
|
||||
self.calculator.take_input(t.chars().next().unwrap());
|
||||
self.calculator_input(t.chars().next().unwrap(), &mut error_state);
|
||||
}
|
||||
egui::Event::Key {
|
||||
key: Key::ArrowLeft,
|
||||
pressed: true,
|
||||
..
|
||||
} => {
|
||||
self.calculator.take_input('<');
|
||||
self.calculator_input('<', &mut error_state);
|
||||
}
|
||||
egui::Event::Key {
|
||||
key: Key::ArrowRight,
|
||||
pressed: true,
|
||||
..
|
||||
} => {
|
||||
self.calculator.take_input('>');
|
||||
self.calculator_input('>', &mut error_state);
|
||||
}
|
||||
egui::Event::Key {
|
||||
key: Key::Enter,
|
||||
pressed: true,
|
||||
..
|
||||
} => {
|
||||
self.calculator.take_input(' ');
|
||||
self.calculator_input(' ', &mut error_state);
|
||||
}
|
||||
|
||||
egui::Event::Copy => continue,
|
||||
egui::Event::Cut => continue,
|
||||
egui::Event::Paste(_) => continue,
|
||||
egui::Event::Key {
|
||||
key,
|
||||
pressed,
|
||||
repeat,
|
||||
modifiers,
|
||||
key: _,
|
||||
pressed: _,
|
||||
repeat: _,
|
||||
modifiers: _,
|
||||
} => continue,
|
||||
egui::Event::PointerMoved(_) => continue,
|
||||
egui::Event::PointerButton {
|
||||
pos,
|
||||
button,
|
||||
pressed,
|
||||
modifiers,
|
||||
pos: _,
|
||||
button: _,
|
||||
pressed: _,
|
||||
modifiers: _,
|
||||
} => continue,
|
||||
egui::Event::PointerGone => continue,
|
||||
egui::Event::Scroll(_) => continue,
|
||||
@ -167,18 +149,46 @@ impl eframe::App for TemplateApp {
|
||||
egui::Event::CompositionUpdate(_) => continue,
|
||||
egui::Event::CompositionEnd(_) => continue,
|
||||
egui::Event::Touch {
|
||||
device_id,
|
||||
id,
|
||||
phase,
|
||||
pos,
|
||||
force,
|
||||
device_id: _,
|
||||
id: _,
|
||||
phase: _,
|
||||
pos: _,
|
||||
force: _,
|
||||
} => continue,
|
||||
egui::Event::AccessKitActionRequest(_) => continue,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Grid::new("grid").spacing(BUTTON_SPACING).show(ui, |ui| {
|
||||
for row in BUTTON_LAYOUT.iter() {
|
||||
for button in row.iter() {
|
||||
let label = RichText::new(button.value).font(DEFAULT_FONT);
|
||||
if ui
|
||||
.add(
|
||||
Button::new(label)
|
||||
.stroke(Stroke::NONE)
|
||||
.rounding(Rounding::none()),
|
||||
)
|
||||
.clicked()
|
||||
{
|
||||
info!("Clicked button {}", button.value);
|
||||
self.calculator_input(button.value, &mut error_state);
|
||||
// if let Err(e) = self.calculator.take_input(button.value) {
|
||||
// error!("Calculator input error: {e:?}");
|
||||
// self.latest_error = Some(e);
|
||||
// fresh_error = true;
|
||||
// } else if !fresh_error {
|
||||
// self.latest_error = None;
|
||||
// }
|
||||
}
|
||||
}
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
|
||||
ui.label(
|
||||
RichText::new(
|
||||
self.calculator
|
||||
.stack
|
||||
.iter()
|
||||
@ -186,21 +196,154 @@ impl eframe::App for TemplateApp {
|
||||
.map(|e| e.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n"),
|
||||
)
|
||||
.background_color(egui::Color32::RED)
|
||||
.font(DEFAULT_FONT)
|
||||
.size(STACK_FONT_SIZE)
|
||||
.color(Color32::WHITE),
|
||||
);
|
||||
|
||||
// ui.label(format!("Calc details: {:#?}", self.calculator.stack));
|
||||
ui.label(format!("Entry buffer: {}", self.calculator.get_l()));
|
||||
egui::Frame::none()
|
||||
.fill(egui::Color32::RED)
|
||||
.inner_margin(5.0)
|
||||
.stroke(Stroke::new(10.0, Color32::BLUE))
|
||||
.show(ui, |ui| {
|
||||
ui.label(
|
||||
RichText::new(self.calculator.get_l())
|
||||
.color(Color32::WHITE)
|
||||
.font(DEFAULT_FONT),
|
||||
);
|
||||
});
|
||||
|
||||
match error_state {
|
||||
ErrorState::NoModify => {}
|
||||
ErrorState::Errored(e) => self.latest_error = Some(e),
|
||||
ErrorState::Clear => self.latest_error = None,
|
||||
}
|
||||
|
||||
if let Some(ref e) = self.latest_error {
|
||||
ui.label(
|
||||
RichText::new(e.to_string())
|
||||
.font(DEFAULT_FONT)
|
||||
.size(STACK_FONT_SIZE)
|
||||
.color(Color32::RED),
|
||||
);
|
||||
}
|
||||
|
||||
egui::warn_if_debug_build(ui);
|
||||
});
|
||||
|
||||
if false {
|
||||
egui::Window::new("Window").show(ctx, |ui| {
|
||||
ui.label("Windows can be moved by dragging them.");
|
||||
ui.label("They are automatically sized based on contents.");
|
||||
ui.label("You can turn on resizing and scrolling if you like.");
|
||||
ui.label("You would normally choose either panels OR windows.");
|
||||
});
|
||||
// if false {
|
||||
// egui::Window::new("Window").show(ctx, |ui| {
|
||||
// ui.label("Windows can be moved by dragging them.");
|
||||
// ui.label("They are automatically sized based on contents.");
|
||||
// ui.label("You can turn on resizing and scrolling if you like.");
|
||||
// ui.label("You would normally choose either panels OR windows.");
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
struct CalculatorButton {
|
||||
value: char,
|
||||
help: &'static str,
|
||||
}
|
||||
|
||||
impl CalculatorButton {
|
||||
const fn new(value: char, help: &'static str) -> Self {
|
||||
Self { value, help }
|
||||
}
|
||||
}
|
||||
|
||||
const BUTTON_LAYOUT: &[&[CalculatorButton]] = &[
|
||||
&[
|
||||
CalculatorButton::new('s', "Sin"),
|
||||
CalculatorButton::new('u', "Undo"),
|
||||
CalculatorButton::new('U', "Redo"),
|
||||
CalculatorButton::new('>', "Swap"),
|
||||
// CalculatorButton::new('\\', "Drop"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('|', "AbsoluteValue"),
|
||||
CalculatorButton::new('v', "Sqrt"),
|
||||
CalculatorButton::new('^', "Pow"),
|
||||
CalculatorButton::new('l', "Log"),
|
||||
CalculatorButton::new('L', "Ln"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('c', "Cos"),
|
||||
CalculatorButton::new('n', "Negate"),
|
||||
CalculatorButton::new('%', "Modulo"),
|
||||
CalculatorButton::new('i', "Inverse"),
|
||||
CalculatorButton::new('/', "Divide"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('t', "Tan"),
|
||||
CalculatorButton::new('7', "7"),
|
||||
CalculatorButton::new('8', "8"),
|
||||
CalculatorButton::new('9', "9"),
|
||||
CalculatorButton::new('*', "Multiply"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('S', "ASin"),
|
||||
CalculatorButton::new('4', "4"),
|
||||
CalculatorButton::new('5', "5"),
|
||||
CalculatorButton::new('6', "6"),
|
||||
CalculatorButton::new('-', "Subtract"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('C', "ACos"),
|
||||
CalculatorButton::new('1', "1"),
|
||||
CalculatorButton::new('2', "2"),
|
||||
CalculatorButton::new('3', "3"),
|
||||
CalculatorButton::new('+', "Add"),
|
||||
],
|
||||
&[
|
||||
CalculatorButton::new('T', "ATan"),
|
||||
CalculatorButton::new('0', "0"),
|
||||
CalculatorButton::new('\\', "Drop"),
|
||||
CalculatorButton::new('.', "Decimal"),
|
||||
CalculatorButton::new(' ', "Return"),
|
||||
],
|
||||
// CalculatorButton::new ( '?', "IntegerDivide"),
|
||||
// CalculatorButton::new ( 'V', "BuildVector"),
|
||||
// CalculatorButton::new ( 'M', "BuildMatrix"),
|
||||
// CalculatorButton::new ( '_', "Deconstruct"),
|
||||
// CalculatorButton::new ( ')', "Transpose"),
|
||||
];
|
||||
|
||||
enum ErrorState {
|
||||
// Do not touch the state of the error
|
||||
NoModify,
|
||||
// There was an error; this was the latest value
|
||||
Errored(CalculatorError),
|
||||
// We should clear the error at the end
|
||||
Clear,
|
||||
}
|
||||
|
||||
impl ErrorState {
|
||||
fn errored(&mut self, e: CalculatorError) {
|
||||
error!("Calculator input error: {e:?}");
|
||||
|
||||
match self {
|
||||
Self::NoModify | ErrorState::Clear => *self = Self::Errored(e),
|
||||
Self::Errored(_) => {
|
||||
// We already errored, so do not change anything
|
||||
}
|
||||
}
|
||||
}
|
||||
fn success(&mut self) {
|
||||
match self {
|
||||
Self::NoModify => {
|
||||
// There was a success and there was no previous failure, so clear any error value
|
||||
*self = Self::Clear
|
||||
}
|
||||
Self::Errored(_) => {
|
||||
// There was a previous error. We can't clear the error
|
||||
}
|
||||
Self::Clear => {
|
||||
// The calculator error was already removed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
rpn_rs_tui/Cargo.toml
Normal file
14
rpn_rs_tui/Cargo.toml
Normal file
@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "rpn_rs_tui"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
rpn_rs = {path=".."}
|
||||
crossterm = { version = "0.18" }
|
||||
tui = { version = "0.14", default-features = false, features = ["crossterm"] }
|
||||
tracing-appender = "0.2.2"
|
||||
tracing-subscriber = "0.3.17"
|
||||
tracing = "0.1.37"
|
@ -5,9 +5,9 @@
|
||||
// Cannot fix this, so don't warn me about it
|
||||
#![allow(clippy::multiple_crate_versions)]
|
||||
|
||||
mod calc;
|
||||
mod constants;
|
||||
use rpn_rs::{calc, constants};
|
||||
mod event;
|
||||
use tracing::info;
|
||||
|
||||
const BORDER_SIZE: u16 = 2;
|
||||
const HELP_TEXT: &str = "\
|
||||
@ -62,7 +62,7 @@ use crossterm::{
|
||||
use event::{Event, Events};
|
||||
// use io::stdout;
|
||||
|
||||
use std::{cmp, convert::TryFrom, error::Error, io, io::Write};
|
||||
use std::{cmp, convert::TryFrom, error::Error, fs::OpenOptions, io, io::Write};
|
||||
use tui::{
|
||||
backend::CrosstermBackend,
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
@ -309,7 +309,36 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_logging() {
|
||||
use tracing_subscriber::{filter::LevelFilter, fmt, prelude::*, EnvFilter};
|
||||
|
||||
let file = OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open("/tmp/rpn_rs.log")
|
||||
.unwrap();
|
||||
let (non_blocking_file, _guard) = tracing_appender::non_blocking(file);
|
||||
|
||||
tracing_subscriber::registry()
|
||||
.with(fmt::layer().with_writer(non_blocking_file))
|
||||
// .with(fmt::layer().with_writer(io::stderr))
|
||||
.with(
|
||||
EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::ERROR.into())
|
||||
.with_env_var("RPN_RS_LOG")
|
||||
.from_env()
|
||||
.unwrap(),
|
||||
)
|
||||
.init();
|
||||
|
||||
info!("Logging initialized");
|
||||
}
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
if std::env::var("ENABLE_LOGGING").as_ref().map(String::as_str) == Ok("1") {
|
||||
init_logging();
|
||||
}
|
||||
|
||||
enable_raw_mode()?;
|
||||
|
||||
let mut stdout = io::stdout();
|
@ -1,3 +1,2 @@
|
||||
pub mod calc;
|
||||
pub mod constants;
|
||||
pub mod event;
|
||||
|
Loading…
Reference in New Issue
Block a user