closable tabs

This commit is contained in:
Penwing 2024-01-20 17:31:53 +01:00
parent 47e58b3e1e
commit 693d83b83f
3 changed files with 47 additions and 15 deletions

View file

@ -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))
}
}

View file

@ -50,7 +50,7 @@ impl TabNumber {
}
}
#[derive(Clone)]
pub struct Tab {
pub path : PathBuf,
pub code : String,

View file

@ -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
}