From 6e6e7581b4c8575dd379f20a786108ce4edcd9c8 Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Wed, 1 Feb 2023 19:50:32 -0330 Subject: refactor --- src/ui.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/ui.rs') diff --git a/src/ui.rs b/src/ui.rs index 9133f1c..bb5057d 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -6,9 +6,37 @@ use crossterm::{ use std::io; use tui::{ backend::{Backend, CrosstermBackend}, - Terminal, + layout::{Constraint, Direction, Layout}, + widgets::{List, ListItem, Paragraph}, + Frame, Terminal, }; +use crate::Calculator; + +impl Calculator { + pub fn draw(&self, f: &mut Frame) { + let chunks = Layout::default() + .direction(Direction::Vertical) + .constraints( + [ + Constraint::Max(u16::MAX), + Constraint::Length(self.stack.len() as u16), + Constraint::Length(1), + ] + .as_ref(), + ) + .split(f.size()); + + let items: Vec = (self.stack) + .iter() + .map(|f| ListItem::new(format!("{}", f))) + .collect(); + f.render_widget(List::new(items), chunks[1]); + + f.render_widget(Paragraph::new(self.input_buffer.as_str()), chunks[2]); + } +} + pub fn init_terminal() -> Result>, io::Error> { enable_raw_mode()?; let mut stdout = io::stdout(); -- cgit v1.2.3