closable tabs
This commit is contained in:
parent
47e58b3e1e
commit
693d83b83f
17
src/main.rs
17
src/main.rs
|
@ -3,7 +3,7 @@ mod tools;
|
||||||
|
|
||||||
use eframe::egui;
|
use eframe::egui;
|
||||||
use egui_code_editor::{CodeEditor, ColorTheme};
|
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 TERMINAL_HEIGHT : f32 = 200.0;
|
||||||
const RED : egui::Color32 = egui::Color32::from_rgb(235, 108, 99);
|
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::GITHUB_DARK, "Github Dark");
|
||||||
ui.selectable_value(&mut self.theme, ColorTheme::GRUVBOX, "Gruvbox");
|
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::fire(), "Fire");
|
||||||
|
ui.selectable_value(&mut self.theme, tools::themes::CustomColorTheme::ash(), "Ash");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -147,9 +148,14 @@ impl Calcifer {
|
||||||
egui::TopBottomPanel::top("tabs")
|
egui::TopBottomPanel::top("tabs")
|
||||||
.resizable(false)
|
.resizable(false)
|
||||||
.show(ctx, |ui| {
|
.show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {//ffad69 #ff8724 #c46110
|
||||||
for (index, tab) in self.tabs.iter().enumerate() {
|
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());
|
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 {
|
if tools::TabNumber::from_n(self.tabs.len()) != tools::TabNumber::None {
|
||||||
ui.selectable_value(&mut self.selected_tab, tools::TabNumber::Open, "+");
|
ui.selectable_value(&mut self.selected_tab, tools::TabNumber::Open, "+");
|
||||||
|
@ -240,5 +246,10 @@ impl Calcifer {
|
||||||
self.tabs.push(new_tab);
|
self.tabs.push(new_tab);
|
||||||
return tools::TabNumber::from_n(self.tabs.len() - 1)
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ impl TabNumber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
pub path : PathBuf,
|
pub path : PathBuf,
|
||||||
pub code : String,
|
pub code : String,
|
||||||
|
|
|
@ -8,18 +8,39 @@ impl CustomColorTheme {
|
||||||
|
|
||||||
theme.name = "Fire";
|
theme.name = "Fire";
|
||||||
theme.dark = true;
|
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.bg = "#101010";
|
||||||
theme.cursor = "#fafafa"; // foreground
|
theme.cursor = "#eaeaea"; // foreground
|
||||||
theme.selection = "#fa8d3e"; // orange
|
theme.selection = "#505050"; // bg5
|
||||||
theme.comments = "#828c9a"; // gray
|
theme.comments = "#656565"; // gray
|
||||||
theme.functions = "#ffaa33"; // yellow
|
theme.functions = "#a0a0a0"; // green
|
||||||
theme.keywords = "#fa8d3e"; // orange
|
theme.keywords = "#848484"; // orange
|
||||||
theme.literals = "#5c6166"; // foreground
|
theme.literals = "#d2d2d2"; // foreground
|
||||||
theme.numerics = "#aa1010"; // magenta
|
theme.numerics = "#d2d2d2"; // magenta
|
||||||
theme.punctuation = "#fafafa"; // foreground
|
theme.punctuation = "#848484"; // foreground
|
||||||
theme.strs = "#fa8d3e"; // green
|
theme.strs = "#a0a0a0"; // green
|
||||||
theme.types = "#fa8d3e"; // blue
|
theme.types = "#c6c6c6";
|
||||||
theme.special = "#f07171"; // red
|
theme.special = "#848484";
|
||||||
|
|
||||||
theme
|
theme
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue