Some cleanup
This commit is contained in:
parent
9bad829054
commit
aa22859f25
|
@ -54,15 +54,15 @@ impl MenuSelection {
|
|||
pub struct ConsoleUI {
|
||||
rx: EventReceiver,
|
||||
terminal: Terminal,
|
||||
frame: Rect,
|
||||
sub_frames: Vec<Rect>,
|
||||
stat_sub_frames: Vec<Rect>,
|
||||
cur_size: Rect,
|
||||
main_chunks: Vec<Rect>,
|
||||
stats_chunks: Vec<Rect>,
|
||||
menu_selection: MenuSelection,
|
||||
}
|
||||
|
||||
impl ConsoleUI {
|
||||
pub fn new(rx: EventReceiver, terminal: Terminal) -> ConsoleUI {
|
||||
ConsoleUI{rx, terminal, frame: Rect::default(), sub_frames: Vec::default(), stat_sub_frames: Vec::default(), menu_selection: MenuSelection::Stats}
|
||||
ConsoleUI{rx, terminal, cur_size: Rect::default(), main_chunks: Vec::default(), stats_chunks: Vec::default(), menu_selection: MenuSelection::Stats}
|
||||
}
|
||||
|
||||
pub fn update(&mut self) -> Result<UIState, Error> {
|
||||
|
@ -90,7 +90,7 @@ impl ConsoleUI {
|
|||
}
|
||||
},
|
||||
Event::Tick => {
|
||||
if self.terminal.size().expect("Getting size of terminal") != self.frame {
|
||||
if self.terminal.size().expect("Getting size of terminal") != self.cur_size {
|
||||
Ok(UIState::Render)
|
||||
}
|
||||
|
||||
|
@ -104,16 +104,16 @@ impl ConsoleUI {
|
|||
|
||||
pub fn render(&mut self) -> Result<(), Error> {
|
||||
self.terminal.draw(|frame| {
|
||||
Self::update_sub_frames(&mut self.sub_frames, &mut self.stat_sub_frames, &mut self.frame, frame.size());
|
||||
Self::update_sub_frames(&mut self.main_chunks, &mut self.stats_chunks, &mut self.cur_size, frame.size());
|
||||
|
||||
frame.render_widget(Self::create_titel(), self.sub_frames[0]);
|
||||
frame.render_widget(Self::create_menu(&self.menu_selection), self.sub_frames[1]);
|
||||
frame.render_widget(Self::create_titel(), self.main_chunks[0]);
|
||||
frame.render_widget(Self::create_menu(&self.menu_selection), self.main_chunks[1]);
|
||||
match self.menu_selection {
|
||||
MenuSelection::Stats => {
|
||||
Self::render_stats(frame, &self.stat_sub_frames);
|
||||
Self::render_stats(frame, &self.stats_chunks);
|
||||
},
|
||||
MenuSelection::Quit => {
|
||||
frame.render_widget(Self::create_exit_message(), self.sub_frames[2]);
|
||||
frame.render_widget(Self::create_exit_message(), self.main_chunks[2]);
|
||||
}
|
||||
}
|
||||
})?;
|
||||
|
|
|
@ -26,7 +26,7 @@ pub fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
fn run_main(_cmd: CommandLine) -> Result<(), Error> {
|
||||
fn run_main(cmd: CommandLine) -> Result<(), Error> {
|
||||
let _sections = load_memory_map(Some(cmd.input))?;
|
||||
let rx = start_event_loop();
|
||||
let terminal = setup_console()?;
|
||||
|
|
Loading…
Reference in New Issue