-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): setup layout for books, pages, & content
- Loading branch information
1 parent
47da791
commit 9e1d769
Showing
1 changed file
with
31 additions
and
22 deletions.
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,36 +1,45 @@ | ||
use tui::{ | ||
backend::Backend, | ||
layout::Alignment, | ||
style::{Color, Style}, | ||
widgets::{Block, BorderType, Borders, Paragraph}, | ||
layout::{Alignment, Constraint, Direction, Layout}, | ||
widgets::{Block, Borders}, | ||
Frame, | ||
}; | ||
|
||
use crate::app::App; | ||
|
||
/// Renders the user interface widgets. | ||
pub fn render<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>) { | ||
pub fn render<B: Backend>(_app: &mut App, frame: &mut Frame<'_, B>) { | ||
// This is where you add new widgets. | ||
// See the following resources: | ||
// - https://docs.rs/ratatui/latest/ratatui/widgets/index.html | ||
// - https://github.com/tui-rs-revival/ratatui/tree/master/examples | ||
frame.render_widget( | ||
Paragraph::new(format!( | ||
"This is a tui template.\n\ | ||
Press `Esc`, `Ctrl-C` or `q` to stop running.\n\ | ||
Press left and right to increment and decrement the counter respectively.\n\ | ||
Counter: {}", | ||
app.counter | ||
)) | ||
.block( | ||
Block::default() | ||
.title("Template") | ||
.title_alignment(Alignment::Center) | ||
.borders(Borders::ALL) | ||
.border_type(BorderType::Rounded), | ||
let chunks = Layout::default() | ||
.direction(Direction::Horizontal) | ||
.margin(1) | ||
.constraints( | ||
[ | ||
Constraint::Percentage(20), | ||
Constraint::Percentage(30), | ||
Constraint::Percentage(50), | ||
] | ||
.as_ref(), | ||
) | ||
.style(Style::default().fg(Color::Cyan).bg(Color::Black)) | ||
.alignment(Alignment::Center), | ||
frame.size(), | ||
) | ||
.split(frame.size()); | ||
let books_block = Block::default() | ||
.title("Books") | ||
.title_alignment(Alignment::Center) | ||
.borders(Borders::ALL); | ||
frame.render_widget(books_block, chunks[0]); | ||
|
||
let pages_block = Block::default() | ||
.title("Pages") | ||
.title_alignment(Alignment::Center) | ||
.borders(Borders::ALL); | ||
frame.render_widget(pages_block, chunks[1]); | ||
|
||
let content_block = Block::default() | ||
.title("Content") | ||
.title_alignment(Alignment::Center) | ||
.borders(Borders::ALL); | ||
frame.render_widget(content_block, chunks[2]); | ||
} |