terminal resize and hide
This commit is contained in:
parent
fcb1b7abba
commit
fee92f29a8
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -570,7 +570,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "calcifer"
|
||||
version = "1.0.4"
|
||||
version = "1.1.0"
|
||||
dependencies = [
|
||||
"eframe",
|
||||
"egui_extras",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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);
|
||||
|
|
|
@ -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<String> = 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::<f32>()));
|
||||
return result
|
||||
}
|
||||
}
|
36
src/main.rs
36
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<f32> = 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<f32>,
|
||||
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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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<f32>) {
|
||||
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<f32>) {
|
||||
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::<f32>()));
|
||||
}
|
||||
}
|
42
src/tools/shortcuts.rs
Normal file
42
src/tools/shortcuts.rs
Normal file
|
@ -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");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue