Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
feat: add a way to add tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Oct 5, 2023
1 parent 0e832a4 commit b7f8d03
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 6 deletions.
5 changes: 4 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[target.wasm32-unknown-unknown]
rustflags = ["--cfg=web_sys_unstable_apis"]
rustflags = ["--cfg=web_sys_unstable_apis"]

[build]
incremental = true
File renamed without changes.
68 changes: 68 additions & 0 deletions src/app/menu/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use crate::app::modules::{AckermannState, AdditionState, SubtractionState};
use crate::app::{Math, Module, Pane};

#[derive(Clone)]
pub struct OpenableOption {
pub id: &'static str,
pub version: &'static str,
pub description: &'static str,
}

pub const OPTIONS: [OpenableOption; 3] = [
OpenableOption {
id: "Ackermann",
version: "0.2",
description: "The not not simple recursive function",
},
OpenableOption {
id: "Addition",
version: "0.1",
description: "some english words",
},
OpenableOption {
id: "Subtraction",
version: "0.1",
description: "hard english words to type",
},
];

fn module_from_option(openable: OpenableOption) -> Pane {
match openable.id {
"Ackermann" => Pane {
title: openable.id.to_string(),
module: Module::Ackermann(AckermannState::default()),
},
"Addition" => Pane {
title: openable.id.to_string(),
module: Module::Addition(AdditionState::default()),
},
"Subtraction" => Pane {
title: openable.id.to_string(),
module: Module::Subtraction(SubtractionState::default()),
},
_ => Pane {
title: openable.id.to_string(),
module: Module::Addition(AdditionState::default()),
},
}
}

pub fn menu(ui: &mut egui::Ui, app: &mut Math) {
egui::Window::new("Tabs")
.vscroll(true)
.default_height(300.00)
.default_width(300.00)
.resizable(false)
.collapsible(false)
.show(ui.ctx(), |ui| {
for openable in OPTIONS {
if ui.button(openable.id).clicked() {
app.add_pane(module_from_option(openable))
}
}
ui.add_space(10.0);
if ui.button("close").clicked() {
app.close_menu()
}
});
}
32 changes: 31 additions & 1 deletion src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
mod memath;
mod functions;
mod menu;
mod modules;

use crate::app::menu::menu;
use crate::app::modules::{AckermannState, AdditionState, SubtractionState};
use egui::WidgetText;
use egui_tiles::Tile;

#[derive(serde::Deserialize, serde::Serialize)]
#[serde(default)]
Expand All @@ -12,13 +15,17 @@ pub struct Math {

#[serde(skip)]
behavior: TreeBehavior,

#[serde(skip)]
command_center_open: bool,
}

impl Default for Math {
fn default() -> Self {
Self {
behavior: TreeBehavior {},
tree: create_tree(),
command_center_open: false,
}
}
}
Expand All @@ -30,12 +37,34 @@ impl Math {
}
Default::default()
}
fn close_menu(&mut self) {
self.command_center_open = false
}

fn add_pane(&mut self, pane: Pane) {
if let Some(root) = self.tree.root {
let new_tile_id = self.tree.tiles.insert_new(Tile::Pane(pane));
if let Tile::Container(cont) = self.tree.tiles.get_mut(root).unwrap() {
cont.add_child(new_tile_id)
}
}
}
}

impl eframe::App for Math {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
ctx.request_repaint();
catppuccin_egui::set_theme(ctx, catppuccin_egui::MACCHIATO);

egui::TopBottomPanel::top("top").show(ctx, |ui| {
if ui.button("Tabs").clicked() {
self.command_center_open = !self.command_center_open
};

if self.command_center_open {
menu(ui, self)
}
});
egui::CentralPanel::default().show(ctx, |ui| {
let mut behavior = TreeBehavior {};
self.tree.ui(&mut behavior, ui);
Expand All @@ -52,6 +81,7 @@ struct Pane {
module: Module,
}

#[derive(Clone)]
enum Module {
Addition(AdditionState),
Subtraction(SubtractionState),
Expand Down
8 changes: 4 additions & 4 deletions src/app/modules/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::app::memath::{ack, addition, subtraction};
use crate::app::functions::{ack, addition, subtraction};
use bigdecimal::BigDecimal;
use egui::Ui;

#[derive(Default)]
#[derive(Default, Clone)]
pub struct SubtractionState {
result: String,
left: i32,
Expand All @@ -23,7 +23,7 @@ impl SubtractionState {
}
}

#[derive(Default)]
#[derive(Default, Clone)]
pub struct AdditionState {
result: String,
left: i32,
Expand All @@ -44,7 +44,7 @@ impl AdditionState {
}
}

#[derive(Default)]
#[derive(Default, Clone)]
pub struct AckermannState {
result: String,
m: i32,
Expand Down

0 comments on commit b7f8d03

Please sign in to comment.