project mode structuure
This commit is contained in:
parent
3b47ef0ca6
commit
9155e09b48
64
Cargo.lock
generated
64
Cargo.lock
generated
|
@ -591,6 +591,7 @@ version = "1.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"arboard",
|
"arboard",
|
||||||
"eframe",
|
"eframe",
|
||||||
|
"egui_dnd",
|
||||||
"egui_extras",
|
"egui_extras",
|
||||||
"homedir",
|
"homedir",
|
||||||
"image",
|
"image",
|
||||||
|
@ -743,6 +744,16 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "concat-idents"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "f76990911f2267d837d9d0ad060aa63aaad170af40904b29461734c339030d4d"
|
||||||
|
dependencies = [
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.48",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "concurrent-queue"
|
name = "concurrent-queue"
|
||||||
version = "2.4.0"
|
version = "2.4.0"
|
||||||
|
@ -978,11 +989,34 @@ dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"raw-window-handle 0.5.2",
|
"raw-window-handle 0.5.2",
|
||||||
"smithay-clipboard",
|
"smithay-clipboard",
|
||||||
"web-time",
|
"web-time 0.2.4",
|
||||||
"webbrowser",
|
"webbrowser",
|
||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "egui_animation"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "e9ccebd83685921eceb3a89df08ce02bbee7c9f7b79472f1a45d12332188a174"
|
||||||
|
dependencies = [
|
||||||
|
"egui",
|
||||||
|
"hello_egui_utils",
|
||||||
|
"simple-easing",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "egui_dnd"
|
||||||
|
version = "0.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "76ff7872d7974d88b5aa5c55d76d4e43b1628005974cb45758402224526233b2"
|
||||||
|
dependencies = [
|
||||||
|
"egui",
|
||||||
|
"egui_animation",
|
||||||
|
"simple-easing",
|
||||||
|
"web-time 1.0.0",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui_extras"
|
name = "egui_extras"
|
||||||
version = "0.25.0"
|
version = "0.25.0"
|
||||||
|
@ -1630,6 +1664,16 @@ version = "0.4.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "hello_egui_utils"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7831675138f982346346b0473a4b4e4fe5794a847ef546b0d794a2e4d8c1a364"
|
||||||
|
dependencies = [
|
||||||
|
"concat-idents",
|
||||||
|
"egui",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.3.3"
|
version = "0.3.3"
|
||||||
|
@ -2611,6 +2655,12 @@ version = "0.3.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "simple-easing"
|
||||||
|
version = "1.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "832ddd7df0d98d6fd93b973c330b7c8e0742d5cb8f1afc7dea89dba4d2531aa1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "slab"
|
name = "slab"
|
||||||
version = "0.4.9"
|
version = "0.4.9"
|
||||||
|
@ -3217,6 +3267,16 @@ dependencies = [
|
||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "web-time"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2ee269d72cc29bf77a2c4bc689cc750fb39f5cbd493d2205bbb3f5c7779cf7b0"
|
||||||
|
dependencies = [
|
||||||
|
"js-sys",
|
||||||
|
"wasm-bindgen",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "webbrowser"
|
name = "webbrowser"
|
||||||
version = "0.8.12"
|
version = "0.8.12"
|
||||||
|
@ -3602,7 +3662,7 @@ dependencies = [
|
||||||
"wayland-protocols",
|
"wayland-protocols",
|
||||||
"wayland-protocols-plasma",
|
"wayland-protocols-plasma",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"web-time",
|
"web-time 0.2.4",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
"x11-dl",
|
"x11-dl",
|
||||||
"x11rb 0.13.0",
|
"x11rb 0.13.0",
|
||||||
|
|
|
@ -15,3 +15,4 @@ serde_json = "1.0.111"
|
||||||
nix = { version = "0.27.1", features = ["fs"] }
|
nix = { version = "0.27.1", features = ["fs"] }
|
||||||
homedir = "0.2.1"
|
homedir = "0.2.1"
|
||||||
arboard = "3.3.0"
|
arboard = "3.3.0"
|
||||||
|
egui_dnd = "0.6.0"
|
||||||
|
|
|
@ -46,3 +46,7 @@ Real Ui
|
||||||
|
|
||||||
# 1.1.0 :
|
# 1.1.0 :
|
||||||
Better error handling
|
Better error handling
|
||||||
|
|
||||||
|
|
||||||
|
# releases :
|
||||||
|
latest : command can fetch multiple lines in the buffer in one frame
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl Calcifer {
|
||||||
|
|
||||||
if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION {
|
if self.tabs[self.selected_tab.to_index()].language == PROJECT_EXTENSION {
|
||||||
ui.separator();
|
ui.separator();
|
||||||
self.project_mode = self.toggle(ui, self.project_mode, "✒");
|
self.project_mode = self.toggle(ui, self.project_mode, "c");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -158,7 +158,7 @@ impl Calcifer {
|
||||||
|
|
||||||
for line in &entry.result {
|
for line in &entry.result {
|
||||||
let color = if line.error { RED } else { entry_color };
|
let color = if line.error { RED } else { entry_color };
|
||||||
ui.colored_label(color, &line.text);
|
ui.label(egui::RichText::new(&line.text).monospace().color(color));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -280,7 +280,7 @@ impl Calcifer {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_project_file(&mut self, ui: &mut egui::Ui) {
|
fn draw_project_file(&mut self, ui: &mut egui::Ui) {
|
||||||
ui.label("project mode");
|
panels::draw_project(ui, self.theme.clone(), &mut self.project_content);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_windows(&mut self, ctx: &egui::Context) {
|
pub fn draw_windows(&mut self, ctx: &egui::Context) {
|
||||||
|
|
15
src/main.rs
15
src/main.rs
|
@ -1,6 +1,6 @@
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui::{
|
use egui::{
|
||||||
FontFamily::Proportional,
|
FontFamily,
|
||||||
FontId,
|
FontId,
|
||||||
TextStyle::{Body, Button, Heading, Monospace, Small},
|
TextStyle::{Body, Button, Heading, Monospace, Small},
|
||||||
};
|
};
|
||||||
|
@ -29,6 +29,7 @@ const TIME_LABELS: [&str; 7] = [
|
||||||
const MAX_FPS: f32 = 30.0;
|
const MAX_FPS: f32 = 30.0;
|
||||||
const DISPLAY_PATH_DEPTH: usize = 3;
|
const DISPLAY_PATH_DEPTH: usize = 3;
|
||||||
const MAX_TABS: usize = 20;
|
const MAX_TABS: usize = 20;
|
||||||
|
const MAX_PROJECT_COLUMNS: usize = 8;
|
||||||
|
|
||||||
fn main() -> Result<(), eframe::Error> {
|
fn main() -> Result<(), eframe::Error> {
|
||||||
let icon_data = core::load_icon().unwrap_or_default();
|
let icon_data = core::load_icon().unwrap_or_default();
|
||||||
|
@ -68,6 +69,7 @@ struct Calcifer {
|
||||||
font_size: f32,
|
font_size: f32,
|
||||||
|
|
||||||
project_mode: bool,
|
project_mode: bool,
|
||||||
|
project_content: panels::Project,
|
||||||
|
|
||||||
home: PathBuf,
|
home: PathBuf,
|
||||||
tree_dir_opened: Vec<String>,
|
tree_dir_opened: Vec<String>,
|
||||||
|
@ -104,6 +106,7 @@ impl Default for Calcifer {
|
||||||
font_size: 14.0,
|
font_size: 14.0,
|
||||||
|
|
||||||
project_mode: true,
|
project_mode: true,
|
||||||
|
project_content: panels::Project::new(),
|
||||||
|
|
||||||
home: get_my_home().unwrap().unwrap(),
|
home: get_my_home().unwrap().unwrap(),
|
||||||
tree_dir_opened: vec![],
|
tree_dir_opened: vec![],
|
||||||
|
@ -146,11 +149,11 @@ impl eframe::App for Calcifer {
|
||||||
|
|
||||||
let mut style = (*ctx.style()).clone();
|
let mut style = (*ctx.style()).clone();
|
||||||
style.text_styles = [
|
style.text_styles = [
|
||||||
(Heading, FontId::new(self.font_size * 1.6, Proportional)),
|
(Heading, FontId::new(self.font_size * 1.6, FontFamily::Proportional)),
|
||||||
(Body, FontId::new(self.font_size, Proportional)),
|
(Body, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||||
(Monospace, FontId::new(self.font_size, Proportional)),
|
(Monospace, FontId::new(self.font_size * 0.8, FontFamily::Monospace)),
|
||||||
(Button, FontId::new(self.font_size, Proportional)),
|
(Button, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||||
(Small, FontId::new(self.font_size, Proportional)),
|
(Small, FontId::new(self.font_size, FontFamily::Proportional)),
|
||||||
]
|
]
|
||||||
.into();
|
.into();
|
||||||
ctx.set_style(style);
|
ctx.set_style(style);
|
||||||
|
|
|
@ -7,3 +7,6 @@ pub use file_tree::*;
|
||||||
|
|
||||||
mod terminal;
|
mod terminal;
|
||||||
pub use terminal::*;
|
pub use terminal::*;
|
||||||
|
|
||||||
|
mod project_mode;
|
||||||
|
pub use project_mode::*;
|
||||||
|
|
131
src/panels/project_mode.rs
Normal file
131
src/panels/project_mode.rs
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
use eframe::egui;
|
||||||
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
|
use crate::MAX_PROJECT_COLUMNS;
|
||||||
|
use crate::core::hex_str_to_color;
|
||||||
|
use crate::editor::ColorTheme;
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Project {
|
||||||
|
categories: Vec<Category>,
|
||||||
|
selected_item: Option<[usize; 2]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Project {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
categories: vec![Category::create()],
|
||||||
|
selected_item: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn add_category(&mut self) {
|
||||||
|
let last = self.categories.len() - 1;
|
||||||
|
self.categories[last].initialize();
|
||||||
|
if self.categories.len() < MAX_PROJECT_COLUMNS {
|
||||||
|
self.categories.push(Category::create());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn delete_category(&mut self, index: usize) {
|
||||||
|
self.categories.remove(index);
|
||||||
|
let last = self.categories.len() - 1;
|
||||||
|
if self.categories[last].name != "+" {
|
||||||
|
self.categories.push(Category::create());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
struct Category {
|
||||||
|
name: String,
|
||||||
|
content: Vec<Item>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Category {
|
||||||
|
fn create() -> Self {
|
||||||
|
Self {
|
||||||
|
name: "+".into(),
|
||||||
|
content: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn initialize(&mut self) {
|
||||||
|
self.name = "untitled".into();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[derive(Clone, Hash)]
|
||||||
|
struct Item {
|
||||||
|
name: String,
|
||||||
|
description: String,
|
||||||
|
id: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Item {
|
||||||
|
fn new(name: &str) -> Self {
|
||||||
|
Self {
|
||||||
|
name: name.to_string(),
|
||||||
|
description: "".to_string(),
|
||||||
|
id: get_id(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub struct Location {
|
||||||
|
category: usize,
|
||||||
|
row: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
fn get_id() -> usize {
|
||||||
|
static COUNTER:AtomicUsize = AtomicUsize::new(1);
|
||||||
|
COUNTER.fetch_add(1, Ordering::Relaxed)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn draw_project(ui: &mut egui::Ui, theme: ColorTheme, project: &mut Project) {
|
||||||
|
ui.columns(MAX_PROJECT_COLUMNS, |uis| {
|
||||||
|
for (category_index, category) in project.categories.clone().into_iter().enumerate() {
|
||||||
|
let ui = &mut uis[category_index];
|
||||||
|
|
||||||
|
if category.name == "+" {
|
||||||
|
if ui.add(egui::Button::new("+")).clicked() {
|
||||||
|
project.add_category();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let response = ui.add(egui::TextEdit::singleline(&mut project.categories[category_index].name).desired_width(f32::INFINITY));
|
||||||
|
if response.lost_focus() && project.categories[category_index].name.is_empty() {
|
||||||
|
project.delete_category(category_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (item_index, item) in category.content.iter().enumerate() {
|
||||||
|
ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |ui| {
|
||||||
|
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
|
||||||
|
if ui.add(egui::Button::new("✒")).clicked() {
|
||||||
|
println!("yes");
|
||||||
|
}
|
||||||
|
|
||||||
|
if project.selected_item == Some([category_index, item_index]) {
|
||||||
|
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.bg));
|
||||||
|
ui.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.functions)));
|
||||||
|
} else {
|
||||||
|
ui.style_mut().visuals.override_text_color = Some(hex_str_to_color(theme.literals));
|
||||||
|
if ui.add(egui::Button::new(item.name.clone()).fill(hex_str_to_color(theme.bg))).clicked() {
|
||||||
|
project.selected_item = Some([category_index, item_index]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if category.name != "+" {
|
||||||
|
if ui.add(egui::Button::new("+")).clicked() {
|
||||||
|
project.categories[category_index].content.push(Item::new("item"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
|
@ -92,7 +92,8 @@ fn read_file_contents(path: &Path) -> String {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn format_file_path(path: &Path, contents: &str) -> PathBuf {
|
fn format_file_path(path: &Path, contents: &str) -> PathBuf {
|
||||||
if contents.contains("Error reading file") {
|
let error_type = "reading file";
|
||||||
|
if contents.contains(&format!("Error {}", error_type)) {
|
||||||
"untitled".into()
|
"untitled".into()
|
||||||
} else {
|
} else {
|
||||||
path.to_path_buf()
|
path.to_path_buf()
|
||||||
|
|
Loading…
Reference in a new issue