mx-bookmarks

A small bookmarks tui based on the matrix protocol and MSC2771
git clone git://archive.git.mtrnord.blog/MTRNord/mx-bookmarks.git
Log | Files | Refs | LICENSE

ui.rs (1575B)


      1 use crate::app::App;
      2 use tui::layout::{ Rect};
      3 use tui::style::Modifier;
      4 use tui::widgets::{Paragraph, Wrap};
      5 use tui::{
      6     backend::Backend,
      7     layout::{Constraint, Layout},
      8     style::{Color, Style},
      9     text::{Span, Spans},
     10     widgets::{Block, Borders, Tabs},
     11     Frame,
     12 };
     13 
     14 pub fn draw<B: Backend>(f: &mut Frame<B>, app: &mut App) {
     15     let chunks = Layout::default()
     16         .constraints([Constraint::Length(3), Constraint::Min(0)].as_ref())
     17         .split(f.size());
     18     let titles = app
     19         .tabs
     20         .titles
     21         .iter()
     22         .map(|t| Spans::from(Span::styled(*t, Style::default().fg(Color::Green))))
     23         .collect();
     24     let tabs = Tabs::new(titles)
     25         .block(Block::default().borders(Borders::ALL).title(app.title))
     26         .highlight_style(Style::default().fg(Color::Yellow))
     27         .select(app.tabs.index);
     28     f.render_widget(tabs, chunks[0]);
     29     match app.tabs.index {
     30         0 => draw_first_tab(f, app, chunks[1]),
     31         1 => draw_second_tab(f, app, chunks[1]),
     32         _ => {}
     33     };
     34 }
     35 
     36 fn draw_first_tab<B>(f: &mut Frame<B>, app: &mut App, area: Rect)
     37 where
     38     B: Backend,
     39 {
     40     let chunks = Layout::default()
     41         .constraints(
     42             [
     43                 Constraint::Length(9),
     44                 Constraint::Min(8),
     45                 Constraint::Length(7),
     46             ]
     47             .as_ref(),
     48         )
     49         .split(area);
     50     draw_text(f, chunks[2]);
     51 }
     52 
     53 fn draw_text<B>(f: &mut Frame<B>, area: Rect)
     54 where
     55     B: Backend,
     56 {
     57 
     58 }
     59 fn draw_second_tab<B>(f: &mut Frame<B>, app: &mut App, area: Rect)
     60 where
     61     B: Backend,
     62 {
     63 }