-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Add building blocks for rendering
- Loading branch information
Showing
1 changed file
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
} |