From fee92f29a8b6c744f29cb42dec3a9d6c919e02b2 Mon Sep 17 00:00:00 2001 From: Penwing Date: Thu, 25 Jan 2024 10:54:42 +0100 Subject: [PATCH] terminal resize and hide --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 3 ++- src/calcifer.rs | 31 ++++++++++++++++++++++------- src/calcifer/app_base.rs | 13 +++++++++++++ src/main.rs | 36 ++++++++++++++++++++-------------- src/tools/confirm.rs | 4 ++-- src/tools/mod.rs | 2 +- src/tools/profiler.rs | 38 ------------------------------------ src/tools/shortcuts.rs | 42 ++++++++++++++++++++++++++++++++++++++++ 10 files changed, 107 insertions(+), 66 deletions(-) delete mode 100644 src/tools/profiler.rs create mode 100644 src/tools/shortcuts.rs diff --git a/Cargo.lock b/Cargo.lock index e02b603..a4edfff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -570,7 +570,7 @@ dependencies = [ [[package]] name = "calcifer" -version = "1.0.4" +version = "1.1.0" dependencies = [ "eframe", "egui_extras", diff --git a/Cargo.toml b/Cargo.toml index b15cee1..979c019 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "calcifer" -version = "1.0.4" +version = "1.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/README.md b/README.md index 56bc015..cce0137 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Added terminal color Max tabs 8 => 20 Max framerate => 30 fps (less cpu usage) -# 1.0.4 : +# 1.1.0 : Added close tab and refresh confirm prompt Async terminal ! +Better Ui \ No newline at end of file diff --git a/src/calcifer.rs b/src/calcifer.rs index 0c38cfd..dc24da2 100644 --- a/src/calcifer.rs +++ b/src/calcifer.rs @@ -1,5 +1,5 @@ use eframe::egui; -use egui::{text::CCursor, text_edit::CCursorRange}; +use egui::{text::CCursor, text_edit::CCursorRange, Rangef}; use std::{env, path::Path, cmp::max}; use crate::tools; @@ -26,19 +26,22 @@ impl Calcifer { } } ui.separator(); - self.tree_display = self.toggle(ui, self.tree_display, "🗐"); + self.tree_visible = self.toggle(ui, self.tree_visible, "🗐"); + ui.separator(); + self.terminal_visible = self.toggle(ui, self.terminal_visible, "🖵"); ui.separator(); self.settings_menu.visible = self.toggle(ui, self.settings_menu.visible, "⚙"); ui.separator(); - self.profiler_menu.visible = self.toggle(ui, self.profiler_menu.visible, "🗠"); + self.shortcuts_menu.visible = self.toggle(ui, self.shortcuts_menu.visible, "⌨"); ui.separator(); + self.profiler_visible = self.toggle(ui, self.profiler_visible, "🗠"); }); }); } pub fn draw_tree_panel(&mut self, ctx: &egui::Context) { - if !self.tree_display { + if !self.tree_visible { return } egui::SidePanel::left("file_tree_panel").show(ctx, |ui| { @@ -49,11 +52,24 @@ impl Calcifer { }); } + pub fn draw_bottom_tray(&mut self, ctx: &egui::Context) { + egui::TopBottomPanel::bottom("tray") + .default_height(self.font_size * 1.2) + .resizable(false) + .show(ctx, |ui| { + ui.label(self.profiler()); + }); + } + pub fn draw_terminal_panel(&mut self, ctx: &egui::Context) { + if !self.terminal_visible { + return + } egui::TopBottomPanel::bottom("terminal") .default_height(super::TERMINAL_HEIGHT.clone()) - .min_height(0.0) + .height_range(Rangef::new(super::TERMINAL_RANGE.start, super::TERMINAL_RANGE.end)) + .resizable(true) .show(ctx, |ui| { ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { let command_color = egui::Color32::from_hex(self.theme.functions).expect("Theme color issue (functions)"); @@ -61,6 +77,7 @@ impl Calcifer { let bg_color = egui::Color32::from_hex(self.theme.bg).expect("Theme color issue (bg)"); ui.label(""); + ui.horizontal(|ui| { ui.style_mut().visuals.extreme_bg_color = bg_color; let Self { command, .. } = self; @@ -192,8 +209,8 @@ impl Calcifer { if self.refresh_confirm.visible { self.refresh_confirm.show(ctx); } - if self.profiler_menu.visible { - self.profiler_menu.show(ctx, self.time_watch.clone()); + if self.shortcuts_menu.visible { + self.shortcuts_menu.show(ctx); } if self.settings_menu.visible { self.settings_menu.show(ctx); diff --git a/src/calcifer/app_base.rs b/src/calcifer/app_base.rs index ea90c9e..375bde3 100644 --- a/src/calcifer/app_base.rs +++ b/src/calcifer/app_base.rs @@ -8,6 +8,7 @@ use crate::PATH_ROOT; use crate::DEFAULT_THEMES; use crate::MAX_TABS; use crate::SAVE_PATH; +use crate::TIME_LABELS; impl Calcifer { @@ -163,4 +164,16 @@ impl Calcifer { } return display } + + pub fn profiler(&self) -> String { + if !self.profiler_visible { + return "".to_string() + } + let combined_string: Vec = TIME_LABELS.into_iter().zip(self.time_watch.clone().into_iter()) + .map(|(s, v)| format!("{} : {:.1} ms", s, v)).collect(); + + let mut result = combined_string.join(" ; "); + result.push_str(&format!(" total : {:.1} ms", self.time_watch.clone().iter().sum::())); + return result + } } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index cf0fec5..0799653 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod calcifer; use eframe::egui; use calcifer::code_editor::ColorTheme; -use std::{path::Path, sync::Arc, time, thread}; +use std::{path::Path, sync::Arc, time, thread, ops::Range}; use egui::FontFamily::Proportional; use egui::FontId; use egui::TextStyle::{Small, Button, Body, Heading, Monospace}; @@ -26,6 +26,7 @@ use build::SAVE_PATH; use build::TITLE; const TERMINAL_HEIGHT : f32 = 200.0; +const TERMINAL_RANGE : Range = 100.0..500.0; const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99); const TIME_LABELS : [&str; 7] = ["input", "settings", "tree", "terminal", "tabs", "content", "windows"]; const MAX_FPS : f32 = 30.0; @@ -72,7 +73,9 @@ struct Calcifer { theme: ColorTheme, font_size: f32, - tree_display: bool, + tree_visible: bool, + profiler_visible: bool, + terminal_visible: bool, close_tab_confirm: tools::confirm::ConfirmWindow, tab_to_close: usize, @@ -80,7 +83,7 @@ struct Calcifer { search: tools::search::SearchWindow, settings_menu: tools::settings::SettingsWindow, - profiler_menu: tools::profiler::ProfilerWindow, + shortcuts_menu: tools::shortcuts::ShortcutsWindow, time_watch: Vec, next_frame: time::Instant, @@ -99,7 +102,9 @@ impl Default for Calcifer { theme: DEFAULT_THEMES[0], font_size: 14.0, - tree_display: false, + tree_visible: false, + profiler_visible: false, + terminal_visible: false, close_tab_confirm: tools::confirm::ConfirmWindow::new("You have some unsaved changes, Do you still want to close this document ?", "Confirm Close"), tab_to_close: 0, @@ -107,7 +112,7 @@ impl Default for Calcifer { search: tools::search::SearchWindow::default(), settings_menu: tools::settings::SettingsWindow::new(DEFAULT_THEMES[0]), - profiler_menu: tools::profiler::ProfilerWindow::new(), + shortcuts_menu: tools::shortcuts::ShortcutsWindow::new(), time_watch: vec![0.0; TIME_LABELS.len()], next_frame: time::Instant::now(), @@ -124,17 +129,17 @@ impl eframe::App for Calcifer { let mut watch = time::Instant::now(); let mut style = (*ctx.style()).clone(); - style.text_styles = [ - (Heading, FontId::new(self.font_size * 1.6, Proportional)), - (Body, FontId::new(self.font_size, Proportional)), - (Monospace, FontId::new(self.font_size, Proportional)), - (Button, FontId::new(self.font_size, Proportional)), - (Small, FontId::new(self.font_size, Proportional)), - ] - .into(); - ctx.set_style(style); + style.text_styles = [ + (Heading, FontId::new(self.font_size * 1.6, Proportional)), + (Body, FontId::new(self.font_size, Proportional)), + (Monospace, FontId::new(self.font_size, Proportional)), + (Button, FontId::new(self.font_size, Proportional)), + (Small, FontId::new(self.font_size, Proportional)), + ] + .into(); + ctx.set_style(style); - if ctx.input( |i| i.key_pressed(egui::Key::T) && i.modifiers.ctrl) && !self.refresh_confirm.visible { + if ctx.input( |i| i.key_pressed(egui::Key::R) && i.modifiers.ctrl) && !self.refresh_confirm.visible { if self.tabs[self.selected_tab.to_index()].saved { self.tabs[self.selected_tab.to_index()].refresh(); } else { @@ -184,6 +189,7 @@ impl eframe::App for Calcifer { self.time_watch[2] = watch.elapsed().as_micros() as f32 / 1000.0; watch = time::Instant::now(); + self.draw_bottom_tray(ctx); self.draw_terminal_panel(ctx); self.time_watch[3] = watch.elapsed().as_micros() as f32 / 1000.0; diff --git a/src/tools/confirm.rs b/src/tools/confirm.rs index e029a5a..99dcbd1 100644 --- a/src/tools/confirm.rs +++ b/src/tools/confirm.rs @@ -23,10 +23,10 @@ impl ConfirmWindow { pub fn show(&mut self, ctx: &egui::Context) { let mut visible = self.visible.clone(); egui::Window::new(self.id.clone()) - .open(&mut visible) //I want it to be able to change its visibility (if user close manually) + .open(&mut visible) .vscroll(true) .hscroll(true) - .show(ctx, |ui| self.ui(ui)); //but I want to edit the rest of the parameters and maybe close automatically + .show(ctx, |ui| self.ui(ui)); self.visible = self.visible.clone() && visible; } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 1dabf7d..220d6ae 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -9,7 +9,7 @@ use toml::Value; pub mod search; pub mod confirm; pub mod settings; -pub mod profiler; +pub mod shortcuts; pub mod terminal; pub use terminal::*; diff --git a/src/tools/profiler.rs b/src/tools/profiler.rs deleted file mode 100644 index fd83d86..0000000 --- a/src/tools/profiler.rs +++ /dev/null @@ -1,38 +0,0 @@ -use eframe::egui; -use crate::TIME_LABELS; - - -pub struct ProfilerWindow { - pub visible: bool, -} - - -impl ProfilerWindow { - pub fn new() -> Self { - Self { - visible: false, - } - } - - - pub fn show(&mut self, ctx: &egui::Context, time_watch: Vec) { - let mut visible = self.visible.clone(); - egui::Window::new("Profiler") - .open(&mut visible) //I want it to be able to change its visibility (if user close manually) - .vscroll(true) - .hscroll(true) - .show(ctx, |ui| self.ui(ui, time_watch)); //but I want to edit the rest of the parameters and maybe close automatically - self.visible = self.visible.clone() && visible; - } - - - fn ui(&mut self, ui: &mut egui::Ui, time_watch: Vec) { - ui.set_min_width(100.0); - - for (index, entry) in TIME_LABELS.iter().enumerate() { - ui.label(format!("{} : {:.1} ms", entry, time_watch[index])); - } - ui.separator(); - ui.label(&format!("total : {:.1} ms", time_watch.clone().iter().sum::())); - } -} \ No newline at end of file diff --git a/src/tools/shortcuts.rs b/src/tools/shortcuts.rs new file mode 100644 index 0000000..222b44f --- /dev/null +++ b/src/tools/shortcuts.rs @@ -0,0 +1,42 @@ +use eframe::egui; + + +pub struct ShortcutsWindow { + pub visible: bool, +} + + +impl ShortcutsWindow { + pub fn new() -> Self { + Self { + visible: false, + } + } + + + pub fn show(&mut self, ctx: &egui::Context) { + let mut visible = self.visible.clone(); + egui::Window::new("Shortcuts") + .open(&mut visible) + .vscroll(true) + .hscroll(true) + .show(ctx, |ui| self.ui(ui,)); + self.visible = self.visible.clone() && visible; + } + + + fn ui(&mut self, ui: &mut egui::Ui) { + ui.set_min_width(250.0); + ui.label("Ctrl+S : save file"); + ui.label("Ctrl+Shift+S : save file as"); + ui.label("Ctrl+R : reload file"); + ui.separator(); + ui.label("Ctrl+F : open search window"); + ui.separator(); + ui.label("Ctrl+Z : undo"); + ui.label("Ctrl+Y : redo"); + ui.label("Tab on selection : add indent of selection"); + ui.label("Shift+Tab on selection : remove indent of selection"); + ui.label("Ctrl+E : comment selection"); + } +} \ No newline at end of file