Skip to content

Commit

Permalink
WIP: Add building blocks for rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Mroik committed May 6, 2024
1 parent ecdfaae commit 146647e
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion src/ui.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,73 @@
use crate::fitch::Fitch;
use ratatui::{
backend::CrosstermBackend,
layout::{Constraint, Direction, Layout, Rect},
widgets::{Block, BorderType, Borders, Paragraph},
Terminal,
};
use std::io::Stdout;

use ratatui::{backend::CrosstermBackend, Terminal};
const INFO_AREA_HEIGHT: u16 = 3;

pub struct Renderer {
terminal: Terminal<CrosstermBackend<Stdout>>,
}

impl Renderer {
fn render_fitch(&mut self, model: &Fitch) {
self.terminal
.draw(|frame| {
let (f_a, i_a) = base_area(frame.size());
let fitch_widget = Paragraph::new(model.to_string()).block(
Block::default()
.borders(Borders::ALL)
.border_type(BorderType::Rounded),
);
let info_widget = Paragraph::new(info_text());

frame.render_widget(fitch_widget, f_a);
frame.render_widget(info_widget, i_a);
})
.unwrap();
}
}

fn info_text() -> String {
// TODO fill info array
let info = [""];
info.iter().fold(String::new(), |mut acc, inf| {
acc.push_str(inf);
acc
})
}

fn base_area(whole: Rect) -> (Rect, Rect) {
let temp = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(whole.height - INFO_AREA_HEIGHT),
Constraint::Length(INFO_AREA_HEIGHT),
])
.split(whole);

(temp[0], temp[1])
}

fn expression_box_area(whole: Rect) -> Rect {
let temp = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(whole.height / 2 - 1),
Constraint::Length(1),
Constraint::Length(whole.height / 2),
])
.split(whole)[1];
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Percentage(18),
Constraint::Percentage(64),
Constraint::Percentage(18),
])
.split(temp)[1]
}

0 comments on commit 146647e

Please sign in to comment.