Skip to content

Commit

Permalink
v1.0.1
Browse files Browse the repository at this point in the history
Enable AccessKit
Fix terminal visibility on Windows
Tweak default WASM UI scale
  • Loading branch information
Colonial-Dev committed Apr 25, 2024
1 parent 6f0fe84 commit 6b7fd66
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/target
/dist
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "deduct"
authors = ["Colonial"]
version = "1.0.0"
version = "1.0.1"
edition = "2021"
description = "A Fitch-style natural deduction proof checker, with support for modal logic."
repository = "https://github.com/Colonial-Dev/deduct"
Expand All @@ -18,7 +18,7 @@ opt-level = 2

[dependencies]
# GUI
egui = "0.27.2"
egui = { version = "0.27.2", features = ["accesskit"] }
eframe = { version = "0.27.2", features = [
"wgpu", # Use the WGPU rendering backend.
"persistence", # Enable restoring app state when restarting the app.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

## Installation

### Web Version
### Web Version (Recommended)
Deduct is available as a web app [here](https://colonial-dev.github.io/deduct/). Use a laptop or desktop for the best experience.

### Precompiled Binaries
Precompiled versions of Deduct are available for:
- Windows
- Windows (note that, although unlikely, you may need to install the Microsoft Visual C/++ Redistributables)
- macOS
- Linux (compiled against `x86_64-unknown-linux-musl`, which should Just Work™ on most distributions.)

Expand Down
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Prevents Windows from opening a terminal when the executable is started
#![windows_subsystem = "windows"]

mod check;
mod parse;
mod ui;
Expand Down
21 changes: 20 additions & 1 deletion src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,25 @@ const NEW_SO: KeyboardShortcut = KeyboardShortcut::new(

const UI_ZOOM_FACTORS: [f32; 5] = [1.0, 1.25, 1.50, 1.75, 2.0];

/// Top-level application state.
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
pub struct Deduct {
/// The current proof, if any.
#[serde(skip)]
proof : Option<proof::ProofUi>,
/// Popup window visibilities.
#[serde(skip)]
vis : popups::Visibility,
/// New proof popup state.
#[serde(skip)]
new : popups::NewProof,
/// Preferences popup state.
prefs : popups::Preferences,
}

impl Deduct {
/// Called once on startup.
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
egui_extras::install_image_loaders(&cc.egui_ctx);

Expand All @@ -90,6 +96,8 @@ impl Deduct {
Default::default()
}

/// Try and use the input from the new proof popup
/// to start a new proof.
pub fn try_new_proof(&mut self) {
if let Some(ui) = self.new.try_create() {
self.proof = Some(ui);
Expand All @@ -98,6 +106,7 @@ impl Deduct {
self.new.ready = false;
}

/// Handle keyboard shortcuts.
fn handle_shortcuts(&mut self, ctx: &Context) {
let mut op = None;

Expand Down Expand Up @@ -153,6 +162,7 @@ impl eframe::App for Deduct {

self.handle_shortcuts(ctx);

// Render top menu bar.
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
egui::menu::bar(ui, |ui| {
ui.menu_button("Proof", |ui| {
Expand Down Expand Up @@ -207,6 +217,7 @@ impl eframe::App for Deduct {

});

// Render quick reference side bar.
egui::SidePanel::right("proof_rules")
.resizable(false)
.min_width(w * 0.25)
Expand Down Expand Up @@ -303,8 +314,10 @@ impl eframe::App for Deduct {
});
});

// Render central panel.
egui::CentralPanel::default()
.show(ctx, |ui| {
// If we don't have a proof, display a placeholder message.
let Some(proof) = &mut self.proof else {
ui.with_layout(
Layout::centered_and_justified(Direction::TopDown),
Expand Down Expand Up @@ -337,6 +350,7 @@ impl eframe::App for Deduct {
}
}

/// Render the about window.
fn about(ui: &mut Ui) {
let title_font = FontId::new(
40.0,
Expand All @@ -353,7 +367,7 @@ fn about(ui: &mut Ui) {
ui.label("A Fitch-style natural deduction proof checker.");

ui.label(
RichText::new("Built with love by Colonial, using Rust and egui!").weak().italics()
RichText::new("Built with love by Colonial using Rust and egui!").weak().italics()
);

ui.separator();
Expand Down Expand Up @@ -385,6 +399,7 @@ fn about(ui: &mut Ui) {
});
}

/// Render the shortcut info window.
fn shortcuts(ui: &mut Ui) {
ui.label("All shortcuts act on the currently selected line or (if no line is selected) the last line.");
ui.separator();
Expand Down Expand Up @@ -438,6 +453,7 @@ fn shortcuts(ui: &mut Ui) {
});
}

/// Load LaTeX `Latin Modern Math` font into memory under the name `math`.
fn fonts_init(cc: &eframe::CreationContext<'_>) {
let mut fonts = FontDefinitions::default();

Expand All @@ -454,6 +470,7 @@ fn fonts_init(cc: &eframe::CreationContext<'_>) {
cc.egui_ctx.set_fonts(fonts);
}

/// Return the current width and height of the window.
fn window_size(ui: &Ui) -> (f32, f32) {
let w = ui.ctx().input(|i| {
let r = i.screen_rect().x_range();
Expand All @@ -468,13 +485,15 @@ fn window_size(ui: &Ui) -> (f32, f32) {
(w, h)
}

/// Generate a dummy [`Response`] that does not influence the UI.
fn dummy_response(ui: &mut Ui) -> Response {
ui.allocate_response(
Vec2::ZERO,
Sense::click()
)
}

/// Create a new popup window with the given title and open flag.
fn new_window<'a>(title: &'static str, open: &'a mut bool) -> Window<'a> {
egui::Window::new(title)
.default_open(true)
Expand Down
7 changes: 6 additions & 1 deletion src/ui/popups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ impl Widget for &mut Preferences {

impl Default for Preferences {
fn default() -> Self {
Self { dark_mode: true, ui_scale: 0 }
// On WASM, bump the default UI scale to 125% as most browsers will be fullscreened.
if cfg!(target_arch = "wasm32") {
Self { dark_mode: true, ui_scale: 1 }
} else {
Self { dark_mode: true, ui_scale: 0 }
}
}
}

0 comments on commit 6b7fd66

Please sign in to comment.