added time debug

This commit is contained in:
Penwing 2024-01-23 22:09:56 +01:00
parent 600db0ec01
commit 08d7344a02
6 changed files with 94 additions and 39 deletions

2
Cargo.lock generated
View file

@ -570,7 +570,7 @@ dependencies = [
[[package]]
name = "calcifer"
version = "1.0.2"
version = "1.0.3"
dependencies = [
"eframe",
"egui_extras",

View file

@ -1,6 +1,6 @@
[package]
name = "calcifer"
version = "1.0.2"
version = "1.0.3"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -8,8 +8,8 @@ edition = "2021"
[dependencies]
eframe = "0.25.0"
env_logger = { version = "0.10.1", default-features = false, features = [
"auto-color",
"humantime",
"auto-color",
"humantime",
] }
rfd = "0.12.1"
egui_extras = "0.25.0"

View file

@ -19,4 +19,8 @@ Added find and replace function
Added multi line tab and shift+tab
Added Ctrl+E : comment multiline
Fixed Ctr+Z (was already in library, tried to make my own, and then found the better one)
Added indent recognition (when there is a line break, the indentaion level is kept)
Added indent recognition (when there is a line break, the indentation level is kept)
# 1.0.3 :
Added Ctrl+T : turn 4 spaces into tab across the whole document

BIN
assets/source.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View file

@ -2,6 +2,7 @@ use eframe::egui;
use egui::{text::CCursor, text_edit::CCursorRange};
use std::{env, path::Path, path::PathBuf, cmp::max, io, fs, cmp::min};
use crate::tools;
use crate::TIME_LABELS;
pub mod code_editor;
use code_editor::CodeEditor;
@ -25,6 +26,19 @@ impl super::Calcifer {
ui.selectable_value(&mut self.theme, theme, theme.name);
}
});
ui.separator();
ui.checkbox(&mut self.debug_display, "Debug display");
ui.separator();
if self.debug_display {
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}", self.time_watch.clone().iter().sum::<f32>()));
ui.label(result);
}
});
});
}
@ -230,6 +244,11 @@ impl super::Calcifer {
let _ = tools::save_state(&app_state, super::SAVE_PATH);
}
pub fn indent_with_tabs(&mut self) {
let current_tab = &mut self.tabs[self.selected_tab.to_index()];
current_tab.code = current_tab.code.replace(" ", "\t")
}
fn list_files(&mut self, ui: &mut egui::Ui, path: &Path) -> io::Result<()> {
if let Some(name) = path.file_name() {
if path.is_dir() {

View file

@ -3,13 +3,15 @@ mod calcifer;
use eframe::egui;
use calcifer::code_editor::ColorTheme;
use std::{path::Path, sync::Arc};
use std::{path::Path, sync::Arc, time::Instant};
use tools::Demo;
use calcifer::code_editor::themes::DEFAULT_THEMES;
const TERMINAL_HEIGHT : f32 = 200.0;
const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
const SAVE_PATH : &str = "calcifer_save.json";
const TIME_LABELS : [&str; 5] = ["settings", "tree", "terminal", "tabs", "content"];
fn main() -> Result<(), eframe::Error> {
@ -17,49 +19,52 @@ fn main() -> Result<(), eframe::Error> {
let icon_data = tools::load_icon();
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([1200.0, 800.0])
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([1200.0, 800.0])
.with_icon(Arc::new(icon_data)),
..Default::default()
};
let app_state: tools::AppState;
// Attempt to load previous state
if Path::new(SAVE_PATH).exists() {
app_state = tools::load_state(SAVE_PATH).expect("Failed to load the save");
} else {
app_state = tools::AppState {
tabs: vec![],
theme: 0,
};
}
..Default::default()
};
let app_state: tools::AppState;
// Attempt to load previous state
if Path::new(SAVE_PATH).exists() {
app_state = tools::load_state(SAVE_PATH).expect("Failed to load the save");
} else {
app_state = tools::AppState {
tabs: vec![],
theme: 0,
};
}
eframe::run_native(
"Calcifer v1.0.2",
options,
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
)
eframe::run_native(
"Calcifer v1.0.3",
options,
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
)
}
struct Calcifer {
selected_tab : tools::TabNumber,
tabs: Vec<tools::Tab>,
selected_tab : tools::TabNumber,
tabs: Vec<tools::Tab>,
command: String,
command_history: Vec<tools::CommandEntry>,
command: String,
command_history: Vec<tools::CommandEntry>,
theme: ColorTheme,
theme: ColorTheme,
search: tools::search::SearchWindow,
searching: bool,
debug_display: bool,
time_watch: Vec<f32>,
}
impl Default for Calcifer {
fn default() -> Self {
fn default() -> Self {
Self {
selected_tab: tools::TabNumber::Zero,
tabs: vec![tools::Tab::default()],
@ -71,17 +76,26 @@ impl Default for Calcifer {
search: tools::search::SearchWindow::default(),
searching: false,
debug_display: false,
time_watch: vec![0.0; TIME_LABELS.len()],
}
}
}
impl eframe::App for Calcifer {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
let mut watch = Instant::now();
if ctx.input( |i| i.key_pressed(egui::Key::S) && i.modifiers.ctrl) {
self.handle_save_file(self.save_tab());
}
if ctx.input( |i| i.key_pressed(egui::Key::T) && i.modifiers.ctrl) {
self.indent_with_tabs();
}
if ctx.input( |i| i.key_pressed(egui::Key::S) && i.modifiers.ctrl && i.modifiers.shift) {
self.handle_save_file(self.save_tab_as());
}
@ -94,10 +108,28 @@ impl eframe::App for Calcifer {
}
self.draw_settings(ctx);
self.draw_tree_panel(ctx);
self.draw_terminal_panel(ctx);
self.draw_tab_panel(ctx);
self.draw_content_panel(ctx);
self.time_watch[0] = watch.elapsed().as_micros() as f32 / 1000.0;
watch = Instant::now();
self.draw_tree_panel(ctx);
self.time_watch[1] = watch.elapsed().as_micros() as f32 / 1000.0;
watch = Instant::now();
self.draw_terminal_panel(ctx);
self.time_watch[2] = watch.elapsed().as_micros() as f32 / 1000.0;
watch = Instant::now();
self.draw_tab_panel(ctx);
self.time_watch[3] = watch.elapsed().as_micros() as f32 / 1000.0;
watch = Instant::now();
self.draw_content_panel(ctx);
self.time_watch[4] = watch.elapsed().as_micros() as f32 / 1000.0;
if self.searching {
self.search.show(ctx, &mut self.searching, &mut self.tabs, &mut self.selected_tab);