Skip to content

Commit

Permalink
feat: add command capabillity
Browse files Browse the repository at this point in the history
  • Loading branch information
SilenLoc committed Mar 28, 2023
1 parent fc54f9b commit 248a552
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 56 deletions.
153 changes: 97 additions & 56 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,121 @@
use egui::Ui;

/// 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
pub struct TypeFastApp {
label: String,
command: String,
settings_open: bool,
}

impl Default for TypeFastApp {
fn default() -> Self {
Self {
// Example stuff:
label: "Hello World!".to_owned(),
fn default() -> Self {
Self {
command: "".into(),
settings_open: false,
}
}
}
}

impl TypeFastApp {
/// Called once before the first frame.
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
if let Some(storage) = cc.storage {
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
}
/// Called once before the first frame.
pub fn new(cc: &eframe::CreationContext<'_>) -> Self {
if let Some(storage) = cc.storage {
return eframe::get_value(storage, eframe::APP_KEY).unwrap_or_default();
}

Default::default()
}
Default::default()
}
}

impl eframe::App for TypeFastApp {
/// 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: _} = self;

// Examples of how to create different panels and windows.
// Pick whichever suits you.
// Tip: a good default choice is to just keep the `CentralPanel`.
// For inspiration and more examples, go to https://emilk.github.io/egui

egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar:
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Quit").clicked() {
_frame.close();
}
});
});
});

egui::SidePanel::left("side_panel_1").show(ctx, |ui| {
ui.heading("Left");
} );

/// 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) {
// Examples of how to create different panels and windows.
// Pick whichever suits you.
// Tip: a good default choice is to just keep the `CentralPanel`.
// For inspiration and more examples, go to https://emilk.github.io/egui

egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
// The top panel is often a good place for a menu bar:
egui::menu::bar(ui, |ui| {
ui.menu_button("File", |ui| {
if ui.button("Quit").clicked() {
_frame.close();
}
});
});



});

egui::SidePanel::right("side_panel_0").show(ctx, |ui| {
ui.heading("Right");
egui::TopBottomPanel::bottom("bottom_panel_0").show(ctx, |ui| {

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.text_edit_singleline(&mut self.command);
process_command(self, ui, ctx);
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x= 0.5;
if ui.button("open settings").clicked() {
self.command = "open settings;".into();
}
if ui.button("close settings").clicked() {
self.command = "close settings;".into();
}
});
});
});

egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("central");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
ui.label("placeholder");
});
}

/// Called by the frame work to save state before shutdown.
fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, eframe::APP_KEY, self);
}
}

ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| {
ui.horizontal(|ui| {
ui.spacing_mut().item_spacing.x = 0.0;
ui.label("TypeFast");
});
});
});
fn process_command(app: &mut TypeFastApp, ui: &mut Ui, ctx: &egui::Context) {
let command = app.command.clone();
if app.command.contains(";") {
app.command.clear();
}

egui::CentralPanel::default().show(ctx, |ui| {
if command.eq("") {
ui.label(&app.command);
}

ui.heading("central");
if command.eq("open settings;") {
app.settings_open = true
}

});
}
if command.eq("close settings;") {
app.settings_open = false
}

/// Called by the frame work to save state before shutdown.
fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, eframe::APP_KEY, self);
}
}
if app.settings_open {
egui::Window::new("Draft setting").show(ctx, |ui| {
ui.label("Hey");
if ui.button("close").clicked() {
app.settings_open = false
}
});
}
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ fn main() -> eframe::Result<()> {
// Log to stdout (if you run with `RUST_LOG=debug`).
tracing_subscriber::fmt::init();




let native_options = eframe::NativeOptions::default();
eframe::run_native(
"TypeFast",
Expand Down

0 comments on commit 248a552

Please sign in to comment.