oxedyne/fe2o3/fe2o3_tui/src/app/cfg.rs
7.8 KiB, 7 runs
created by r1870400018:4678, 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::{ |
| 2 | App, |
| 3 | lib_tui::{ |
| 4 | action::Action, |
| 5 | cfg::style::StyleLibrary, |
| 6 | draw::{ |
| 7 | tab::{ |
| 8 | TabbedTextBox, |
| 9 | TabbedTextManager, |
| 10 | }, |
| 11 | tbox::TextBox, |
| 12 | window::{ |
| 13 | TextBoxesState, |
| 14 | WindowConfig, |
| 15 | WindowStateInit, |
| 16 | WindowType, |
| 17 | }, |
| 18 | }, |
| 19 | style::{ |
| 20 | Colour, |
| 21 | Symbol, |
| 22 | }, |
| 23 | text::{ |
| 24 | edit::Editor, |
| 25 | typ::{ |
| 26 | ContentType, |
| 27 | TextType, |
| 28 | TextViewType, |
| 29 | }, |
| 30 | view::TextView, |
| 31 | }, |
| 32 | window::{ |
| 33 | MenuList, |
| 34 | WindowManagerConfig, |
| 35 | }, |
| 36 | }, |
| 37 | }; |
| 38 | |
| 39 | use oxedyne_fe2o3_core::prelude::*; |
| 40 | use oxedyne_fe2o3_geom::{ |
| 41 | dim::{ |
| 42 | Dim, |
| 43 | FlexDim, |
| 44 | }, |
| 45 | rect::{ |
| 46 | AbsSize, |
| 47 | RectView, |
| 48 | RelSize, |
| 49 | RelRect, |
| 50 | }, |
| 51 | }; |
| 52 | use oxedyne_fe2o3_text::{ |
| 53 | Text, |
| 54 | access::AccessibleText, |
| 55 | lines::TextLines, |
| 56 | }; |
| 57 | |
| 58 | use std::{ |
| 59 | rc::Rc, |
| 60 | sync::RwLock, |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | #[derive(Clone, Debug)] |
| 65 | pub struct AppConfig { |
| 66 | pub tab_string: String, |
| 67 | pub window_count_limit: u8, |
| 68 | pub window_min_size_x: u8, |
| 69 | pub window_min_size_y: u8, |
| 70 | } |
| 71 | |
| 72 | impl Default for AppConfig { |
| 73 | fn default() -> Self { |
| 74 | Self { |
| 75 | tab_string: fmt!(" "), |
| 76 | window_count_limit: 100, |
| 77 | window_min_size_x: 6, |
| 78 | window_min_size_y: 6, |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | impl From<AppConfig> for WindowManagerConfig { |
| 84 | fn from(cfg: AppConfig) -> Self { |
| 85 | Self { |
| 86 | tab_string: cfg.tab_string.clone(), |
| 87 | window_count_limit: cfg.window_count_limit, |
| 88 | window_min_size_x: cfg.window_min_size_x, |
| 89 | window_min_size_y: cfg.window_min_size_y, |
| 90 | ..Default::default() |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | impl App<'_> { |
| 96 | |
| 97 | pub fn make_windows(&mut self, _term: AbsSize) -> Outcome<()> { |
| 98 | |
| 99 | let min_size = AbsSize::new((Dim(6), Dim(6))); |
| 100 | let lib = ConfigLibrary::default(); |
| 101 | |
| 102 | let main_win = RectView::InitiallyRelative(RelRect::RelSize(RelSize::new(( |
| 103 | FlexDim::PadFixedFill(Dim(50), Dim(70)), |
| 104 | FlexDim::PadFixedFill(Dim(2), Dim(50)), |
| 105 | )))); |
| 106 | let main_win_cfg = WindowConfig { |
| 107 | typ: WindowType::Fixed, |
| 108 | canvas: lib.fe2o3.canvas_colour(None, None), |
| 109 | outlines: lib.fe2o3.default_window_outlines(), |
| 110 | header: Some(lib.fe2o3.standard_header_config(Some(Colour::White), Some(Colour::Magenta))), |
| 111 | footer: Some(lib.fe2o3.standard_footer_config(Some(Colour::White), Some(Colour::Blue))), |
| 112 | min_size: min_size.clone(), |
| 113 | menu_text: Some(res!(MenuList::from(vec![ |
| 114 | ( |
| 115 | TextType::new_menu_item("Create new text tab "), |
| 116 | Some(Action::CreateNewTextTab), |
| 117 | ), |
| 118 | ]).text_lines())), |
| 119 | }; |
| 120 | |
| 121 | let (id, cfg, view, state) = res!(lib.fe2o3.default_log_window(&self.win_mgr.cfg, self.log.clone())); |
| 122 | res!(self.win_mgr.add_window( |
| 123 | Some(id.clone()), |
| 124 | cfg, |
| 125 | view, |
| 126 | )); |
| 127 | res!(self.win_mgr.set_state(&id, state)); |
| 128 | |
| 129 | let (id, cfg, view, state) = res!(lib.fe2o3.default_menu_window( |
| 130 | &self.win_mgr.cfg, |
| 131 | self.win_mgr.state.window_list.clone(), |
| 132 | self.win_mgr.state.menu_text.clone(), |
| 133 | )); |
| 134 | res!(self.win_mgr.add_window( |
| 135 | Some(id.clone()), |
| 136 | cfg, |
| 137 | view, |
| 138 | )); |
| 139 | res!(self.win_mgr.set_state(&id, state)); |
| 140 | let (id, cfg, view, state) = res!(lib.fe2o3.default_help_window(&self.win_mgr.cfg)); |
| 141 | res!(self.win_mgr.add_window( |
| 142 | Some(id.clone()), |
| 143 | cfg, |
| 144 | view, |
| 145 | )); |
| 146 | res!(self.win_mgr.set_state(&id, state)); |
| 147 | |
| 148 | let (id, _) = res!(self.win_mgr.add_window( |
| 149 | None, |
| 150 | main_win_cfg, |
| 151 | main_win, |
| 152 | )); |
| 153 | res!(self.win_mgr.set_state( |
| 154 | &id, |
| 155 | WindowStateInit { |
| 156 | header: Some(lib.fe2o3.status_strip_labels_with_mode( |
| 157 | Some("/a/really/long/file/path/to/a/veryveryveryvery/loong/file/name"), |
| 158 | &id.label(), |
| 159 | )), |
| 160 | footer: Some(lib.fe2o3.status_strip_cursor(None::<&str>)), |
| 161 | text_boxes: Some(TextBoxesState::Tabbed(res!(TabbedTextManager::new( |
| 162 | res!(lib.fe2o3.standard_tab_styles()), |
| 163 | vec![], |
| 164 | None, |
| 165 | None, |
| 166 | )))), |
| 167 | }, |
| 168 | )); |
| 169 | let test_txt = [ |
| 170 | Text::from("1. The procrastinator's meeting has been postponed."), |
| 171 | Text::from("2. The mechanic's car is always the last to get fixed."), |
| 172 | Text::from("3. My Wi-Fi went down for five minutes, so I had to talk to my family. They seem like nice people."), |
| 173 | Text::from("4. The fire station burned down last night."), |
| 174 | Text::from("5. I always arrive late at the office, but I make up for it by leaving early."), |
| 175 | Text::from("6. The plumber's house has leaky taps."), |
| 176 | Text::from("7. My diet plan includes eating donuts for breakfast."), |
| 177 | Text::from("8. The marriage counselor is getting a divorce."), |
| 178 | Text::from("9. I told my boss I was late because I was stuck in traffic. He replied, 'At home?'"), |
| 179 | Text::from("10. The vegetarian worked in a butcher shop."), |
| 180 | Text::from("11. My calendar says I have no time to procrastinate today."), |
| 181 | Text::from("12. The lifeguard can't swim."), |
| 182 | Text::from("13. My phone bill was so high, I had to call the phone company to complain."), |
| 183 | Text::from("14. I keep forgetting to go to my memory improvement class."), |
| 184 | Text::from("15. The dentist has a sweet tooth."), |
| 185 | Text::from("16. I quit my job to pursue my passion for unemployment."), |
| 186 | Text::from("17. The tailor's clothes are always too loose or too tight."), |
| 187 | Text::from("18. The librarian lost her book."), |
| 188 | Text::from("19. My therapist told me to write a letter to someone who hurt me and then burn it. Now I don't know what to do with the letter!"), |
| 189 | Text::from("20. The meteorologist said it would be sunny all day, but I got drenched in the rain."), |
| 190 | ]; |
| 191 | res!(self.win_mgr.add_text_box( |
| 192 | &id, |
| 193 | TabbedTextBox { |
| 194 | tbox: res!(TextBox::new( |
| 195 | lib.fe2o3.navigable_text_box(), |
| 196 | res!(TextView::new( |
| 197 | ContentType::Text, |
| 198 | TextViewType::Editable(Editor::default()), |
| 199 | AccessibleText::Shared(Rc::new(RwLock::new( |
| 200 | TextLines::from(test_txt) |
| 201 | ))), |
| 202 | )), |
| 203 | )), |
| 204 | tab: lib.fe2o3.tab_with_label(Some(Symbol::File), "File"), |
| 205 | }, |
| 206 | )); |
| 207 | res!(self.win_mgr.add_text_box( |
| 208 | &id, |
| 209 | TabbedTextBox { |
| 210 | tbox: res!(TextBox::new( |
| 211 | lib.fe2o3.navigable_text_box(), |
| 212 | res!(TextView::new( |
| 213 | ContentType::Text, |
| 214 | TextViewType::Editable(Editor::default()), |
| 215 | AccessibleText::Shared(Rc::new(RwLock::new( |
| 216 | TextLines::from(vec![ |
| 217 | Text::from("Hello World."), |
| 218 | ]), |
| 219 | ))), |
| 220 | )), |
| 221 | )), |
| 222 | tab: lib.fe2o3.tab_with_label(Some(Symbol::Buffer), "Buffer"), |
| 223 | }, |
| 224 | )); |
| 225 | |
| 226 | Ok(()) |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | #[derive(Clone, Debug, Default)] |
| 231 | pub struct ConfigLibrary { |
| 232 | pub fe2o3: StyleLibrary, |
| 233 | } |
| 234 | |
| 235 | impl ConfigLibrary {} |