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

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> {
@ -37,7 +39,7 @@ fn main() -> Result<(), eframe::Error> {
}
eframe::run_native(
"Calcifer v1.0.2",
"Calcifer v1.0.3",
options,
Box::new(move |_cc| Box::from(Calcifer::from_app_state(app_state))),
)
@ -55,6 +57,9 @@ struct Calcifer {
search: tools::search::SearchWindow,
searching: bool,
debug_display: bool,
time_watch: Vec<f32>,
}
@ -71,6 +76,9 @@ impl Default for Calcifer {
search: tools::search::SearchWindow::default(),
searching: false,
debug_display: false,
time_watch: vec![0.0; TIME_LABELS.len()],
}
}
}
@ -78,10 +86,16 @@ impl Default for Calcifer {
impl eframe::App for Calcifer {
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,11 +108,29 @@ impl eframe::App for Calcifer {
}
self.draw_settings(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);
}