oxedyne/fe2o3/fe2o3_tui/src/lib_tui/cfg/tab.rs
2.7 KiB, 7 runs
created by r1870400018:1165, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use crate::lib_tui::{ |
| 2 | cfg::style::StyleLibrary, |
| 3 | draw::{ |
| 4 | tab::{ |
| 5 | Tab, |
| 6 | TabbedTextBox, |
| 7 | TabStripConfig, |
| 8 | }, |
| 9 | tbox::TextBox, |
| 10 | }, |
| 11 | style::{ |
| 12 | Colour, |
| 13 | Style, |
| 14 | Symbol, |
| 15 | }, |
| 16 | text::{ |
| 17 | edit::Editor, |
| 18 | typ::{ |
| 19 | ContentType, |
| 20 | TextViewType, |
| 21 | }, |
| 22 | view::TextView, |
| 23 | }, |
| 24 | }; |
| 25 | |
| 26 | use oxedyne_fe2o3_core::prelude::*; |
| 27 | use oxedyne_fe2o3_text::{ |
| 28 | Text, |
| 29 | access::AccessibleText, |
| 30 | lines::TextLines, |
| 31 | }; |
| 32 | |
| 33 | use std::{ |
| 34 | rc::Rc, |
| 35 | sync::{ |
| 36 | RwLock, |
| 37 | }, |
| 38 | }; |
| 39 | |
| 40 | |
| 41 | #[derive(Clone, Debug, Default)] |
| 42 | pub struct TabLibrary; |
| 43 | |
| 44 | impl TabLibrary { |
| 45 | |
| 46 | pub fn tab_label(&self, symbol: Option<Symbol>, label: &str) -> String { |
| 47 | fmt!("{}{}", |
| 48 | match symbol { |
| 49 | Some(symbol) => fmt!("{} ", symbol), |
| 50 | None => String::new(), |
| 51 | }, |
| 52 | label, |
| 53 | ) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl StyleLibrary { |
| 58 | |
| 59 | pub fn tab_with_label(&self, symbol: Option<Symbol>, label: &str) -> Tab { |
| 60 | Tab { |
| 61 | label: self.tab.tab_label(symbol, label), |
| 62 | ..Default::default() |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | pub fn standard_tab_styles(&self) -> Outcome<TabStripConfig> { |
| 67 | TabStripConfig::new(vec![ |
| 68 | Style::new(Some(Colour::White), None, None), |
| 69 | Style::new(Some(Colour::White), Some(Colour::Green), None), |
| 70 | Style::new(Some(Colour::White), Some(Colour::Red), None), |
| 71 | Style::new(Some(Colour::White), Some(Colour::Blue), None), |
| 72 | Style::new(Some(Colour::Black), Some(Colour::Yellow), None), |
| 73 | Style::new(Some(Colour::LightRed), Some(Colour::Black), None), |
| 74 | ]) |
| 75 | } |
| 76 | |
| 77 | pub fn tabbed_text_box(&self, ctyp: ContentType) -> Outcome<TabbedTextBox> { |
| 78 | Ok(TabbedTextBox { |
| 79 | tbox: match ctyp { |
| 80 | ContentType::FileTree => { |
| 81 | res!(self.file_tree_text_box()) |
| 82 | } |
| 83 | _ => { |
| 84 | res!(TextBox::new( |
| 85 | self.navigable_text_box(), |
| 86 | res!(TextView::new( |
| 87 | ContentType::Text, |
| 88 | TextViewType::Editable(Editor::default()), |
| 89 | AccessibleText::Shared( |
| 90 | Rc::new(RwLock::new( |
| 91 | TextLines::new( |
| 92 | vec![Text::new("", None)], |
| 93 | None, |
| 94 | ), |
| 95 | )), |
| 96 | ), |
| 97 | )), |
| 98 | )) |
| 99 | } |
| 100 | }, |
| 101 | tab: self.tab_with_label(ctyp.symbol(), ctyp.label()), |
| 102 | }) |
| 103 | } |
| 104 | } |