From 693d83b83fc834a9544316bee15807272ca6f1ff Mon Sep 17 00:00:00 2001 From: Penwing Date: Sat, 20 Jan 2024 17:31:53 +0100 Subject: [PATCH] closable tabs --- src/main.rs | 17 ++++++++++++++--- src/tools/mod.rs | 2 +- src/tools/themes.rs | 43 ++++++++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1c4fa7c..f421770 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod tools; use eframe::egui; use egui_code_editor::{CodeEditor, ColorTheme}; -use std::{path::Path, fs, io, env, cmp::max}; +use std::{path::Path, fs, io, env, cmp::max, cmp::min}; const TERMINAL_HEIGHT : f32 = 200.0; const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99); @@ -80,6 +80,7 @@ impl Calcifer { ui.selectable_value(&mut self.theme, ColorTheme::GITHUB_DARK, "Github Dark"); ui.selectable_value(&mut self.theme, ColorTheme::GRUVBOX, "Gruvbox"); ui.selectable_value(&mut self.theme, tools::themes::CustomColorTheme::fire(), "Fire"); + ui.selectable_value(&mut self.theme, tools::themes::CustomColorTheme::ash(), "Ash"); }); }); }); @@ -147,9 +148,14 @@ impl Calcifer { egui::TopBottomPanel::top("tabs") .resizable(false) .show(ctx, |ui| { - ui.horizontal(|ui| { - for (index, tab) in self.tabs.iter().enumerate() { + ui.horizontal(|ui| {//ffad69 #ff8724 #c46110 + ui.style_mut().visuals.selection.bg_fill = egui::Color32::from_hex("#b56524").expect("Could not convert color"); + for (index, tab) in self.tabs.clone().iter().enumerate() { ui.selectable_value(&mut self.selected_tab, tools::TabNumber::from_n(index), tab.get_name()); + if ui.link("X").clicked() { + self.selected_tab = self.delete_tab(index); + } + ui.separator(); } if tools::TabNumber::from_n(self.tabs.len()) != tools::TabNumber::None { ui.selectable_value(&mut self.selected_tab, tools::TabNumber::Open, "+"); @@ -240,5 +246,10 @@ impl Calcifer { self.tabs.push(new_tab); return tools::TabNumber::from_n(self.tabs.len() - 1) } + + fn delete_tab(&mut self, index : usize) -> tools::TabNumber { + self.tabs.remove(index); + return tools::TabNumber::from_n(min(index, self.tabs.len() - 1)) + } } diff --git a/src/tools/mod.rs b/src/tools/mod.rs index 3459aa9..0f0ca05 100644 --- a/src/tools/mod.rs +++ b/src/tools/mod.rs @@ -50,7 +50,7 @@ impl TabNumber { } } - +#[derive(Clone)] pub struct Tab { pub path : PathBuf, pub code : String, diff --git a/src/tools/themes.rs b/src/tools/themes.rs index 687609b..23b03d5 100644 --- a/src/tools/themes.rs +++ b/src/tools/themes.rs @@ -8,18 +8,39 @@ impl CustomColorTheme { theme.name = "Fire"; theme.dark = true; + theme.bg = "#242424"; + theme.cursor = "#dadada"; // foreground + theme.selection = "#444852"; // dunno + theme.comments = "#656565"; // dark_gray + theme.functions = "#ffad69"; // light orange + theme.keywords = "#48b1a7"; // mid green + theme.literals = "#d2d2d3"; // + theme.numerics = "#ff7b4f"; // orange + theme.punctuation = "#989898"; // gray + theme.strs = "#cbd5a1"; // light_green + theme.types = "#038e83"; // dark_green + theme.special = "#48b1a7"; // mid green + + theme + } + + pub fn ash() -> ColorTheme { + let mut theme = ColorTheme::GRUVBOX; // Or any other theme you want to modify + + theme.name = "Ash"; + theme.dark = true; theme.bg = "#101010"; - theme.cursor = "#fafafa"; // foreground - theme.selection = "#fa8d3e"; // orange - theme.comments = "#828c9a"; // gray - theme.functions = "#ffaa33"; // yellow - theme.keywords = "#fa8d3e"; // orange - theme.literals = "#5c6166"; // foreground - theme.numerics = "#aa1010"; // magenta - theme.punctuation = "#fafafa"; // foreground - theme.strs = "#fa8d3e"; // green - theme.types = "#fa8d3e"; // blue - theme.special = "#f07171"; // red + theme.cursor = "#eaeaea"; // foreground + theme.selection = "#505050"; // bg5 + theme.comments = "#656565"; // gray + theme.functions = "#a0a0a0"; // green + theme.keywords = "#848484"; // orange + theme.literals = "#d2d2d2"; // foreground + theme.numerics = "#d2d2d2"; // magenta + theme.punctuation = "#848484"; // foreground + theme.strs = "#a0a0a0"; // green + theme.types = "#c6c6c6"; + theme.special = "#848484"; theme }