mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Add X's to tabs
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
mod app;
|
||||
mod windows;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
|
||||
use crate::{
|
||||
app::windows::WindowWrapper, auth::Auth, config::Config, flowchart::FlowChart,
|
||||
@@ -14,7 +14,7 @@ use egui_tiles::{TileId, Tree};
|
||||
pub struct AppState {
|
||||
pub auth: Auth,
|
||||
|
||||
pub open_windows: HashMap<AppWindow, TileId>,
|
||||
pub open_windows: HashSet<AppWindow>,
|
||||
|
||||
pub flowchart: FlowChart,
|
||||
pub config: Config,
|
||||
@@ -31,14 +31,26 @@ impl AppState {
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
let enabled = self.open_windows.contains_key(&key);
|
||||
let enabled = self.open_windows.contains(&key);
|
||||
|
||||
if ui.selectable_label(enabled, *name).clicked() {
|
||||
if enabled {
|
||||
let tid = *self.open_windows.get(&key).unwrap();
|
||||
tree.remove_recursively(tid);
|
||||
tree.tiles.remove(tid);
|
||||
self.open_windows.remove(&key);
|
||||
// if let Some(tid) = Self::find_pane_id(*key, tree) {
|
||||
// tree.remove_recursively(*tid);
|
||||
// tree.tiles.remove(*tid);
|
||||
// self.open_windows.remove(&key);
|
||||
// }
|
||||
// let tid = *self.open_windows.get(&key).unwrap();
|
||||
|
||||
match Self::find_pane_id(*key, tree) {
|
||||
Some(tid) => {
|
||||
let tid = tid.clone();
|
||||
tree.remove_recursively(tid);
|
||||
tree.tiles.remove(tid);
|
||||
self.open_windows.remove(&key);
|
||||
}
|
||||
None => unreachable!(),
|
||||
}
|
||||
|
||||
// if self.open_windows.is_empty()
|
||||
} else {
|
||||
@@ -63,11 +75,25 @@ impl AppState {
|
||||
tree.move_tile_to_container(tid, tree.root.unwrap().clone(), n, true);
|
||||
}
|
||||
}
|
||||
self.open_windows.insert(key.clone(), tid);
|
||||
self.open_windows.insert(key.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_pane_id(window_type: AppWindow, tree: &Tree<WindowWrapper>) -> Option<&TileId> {
|
||||
for (tid, window) in tree.tiles.iter() {
|
||||
match window {
|
||||
egui_tiles::Tile::Pane(pane) => {
|
||||
if pane.window == window_type {
|
||||
return Some(tid);
|
||||
}
|
||||
}
|
||||
egui_tiles::Tile::Container(_) => {}
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, serde::Deserialize, serde::Serialize, PartialEq, Eq, Hash)]
|
||||
|
||||
@@ -63,6 +63,28 @@ impl egui_tiles::Behavior<WindowWrapper> for AppState {
|
||||
ret
|
||||
}
|
||||
|
||||
fn is_tab_closable(
|
||||
&self,
|
||||
tiles: &egui_tiles::Tiles<WindowWrapper>,
|
||||
tile_id: egui_tiles::TileId,
|
||||
) -> bool {
|
||||
match tiles.get(tile_id).unwrap() {
|
||||
egui_tiles::Tile::Pane(_) => true,
|
||||
egui_tiles::Tile::Container(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_tab_close(
|
||||
&mut self,
|
||||
tiles: &mut egui_tiles::Tiles<WindowWrapper>,
|
||||
tile_id: egui_tiles::TileId,
|
||||
) -> bool {
|
||||
match tiles.get(tile_id).unwrap() {
|
||||
egui_tiles::Tile::Pane(pane) => self.open_windows.remove(&pane.window),
|
||||
egui_tiles::Tile::Container(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn tab_bar_color(&self, visuals: &egui::Visuals) -> egui::Color32 {
|
||||
visuals.panel_fill // same as the tab contents
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user