Skip to content

Commit

Permalink
feat(term): simplify ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed May 28, 2024
1 parent 72f90cb commit b2fa928
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 67 deletions.
32 changes: 12 additions & 20 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ use crate::{
},
};
use ratatui::{
prelude::{Alignment, Buffer, Constraint, Layout, Margin, Rect},
prelude::{Alignment, Buffer, Constraint, Layout, Rect},
style::Stylize,
text::{Line, Span, Text},
widgets::{
block::{Position, Title},
Block, BorderType, Borders, Cell, Padding, Paragraph, Row, Scrollbar, ScrollbarOrientation,
ScrollbarState, StatefulWidget, Table, TableState, Widget, Wrap,
},
Expand Down Expand Up @@ -121,11 +120,14 @@ impl Entries {
}

fn render_entries(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
// padding
let entries_area = area.inner(&Margin {
vertical: 1,
horizontal: 1,
});
let entries_area = Block::new()
.padding(Padding {
top: 1,
left: 0,
right: 1,
bottom: 0,
})
.inner(area);

let mut entries_state = TableState::new()
.with_offset(0)
Expand All @@ -144,7 +146,7 @@ impl Entries {

let scrollbar_area = Rect {
y: area.y + 2, // table header
height: area.height.saturating_sub(3),
height: area.height.saturating_sub(1),
..area
};

Expand Down Expand Up @@ -237,17 +239,7 @@ impl Entries {

fn render_summary(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let block = Block::new()
.padding(Padding {
left: 3,
right: 3,
top: 1,
bottom: 1,
})
.title(
Title::from(" Summary ")
.position(Position::Top)
.alignment(Alignment::Center),
)
.padding(Padding::horizontal(2))
.borders(Borders::TOP)
.border_type(BorderType::Plain);

Expand All @@ -264,7 +256,7 @@ impl Entries {
let paragraph = Paragraph::new(Text::from(summary))
.wrap(Wrap { trim: false })
.style(cx.theme.entries.summary)
.alignment(Alignment::Center);
.alignment(Alignment::Left);

Widget::render(paragraph, inner, buf);
}
Expand Down
32 changes: 11 additions & 21 deletions crates/synd_term/src/ui/components/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ impl Filter {
pub fn render(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let area = Block::new()
.padding(Padding {
left: 3,
left: 2,
right: 1,
top: 0,
bottom: 0,
})
.inner(area);
let vertical = Layout::vertical([Constraint::Length(1), Constraint::Length(1)]);
let vertical = Layout::vertical([Constraint::Length(2), Constraint::Length(1)]);
let [filter_area, search_area] = vertical.areas(area);

self.render_filter(filter_area, buf, cx);
Expand All @@ -338,26 +338,18 @@ impl Filter {

fn render_filter(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let mut spans = vec![
Span::from(concat!(icon!(filter), " Filter")),
Span::from(" "),
Span::from(concat!(icon!(requirement), " Requirement")).dim(),
Span::from(" "),
];
spans.push(self.requirement.label(&cx.theme.requirement).bold());

spans.extend([
Span::from(concat!(icon!(filter), " Filter")).dim(),
Span::from(" "),
{
let s = Span::from(concat!(icon!(category), " Categories"));

if self.state == State::CategoryFiltering {
s
let r = self.requirement.label(&cx.theme.requirement);
if r.content == "MAY" {
r.dim()
} else {
s.dim()
r
}
},
Span::from(" "),
]);
Span::from(" | ").dim(),
];

for c in &self.categories {
let state = self
Expand Down Expand Up @@ -390,18 +382,16 @@ impl Filter {
if self.state == State::CategoryFiltering {
spans.push(Span::from("(Esc/+/-)").dim());
}

Line::from(spans).render(area, buf);
}
fn render_search(&self, area: Rect, buf: &mut Buffer, _cx: &Context<'_>) {
let mut spans = vec![Span::from(" ")];

let mut spans = vec![];
let mut label = Span::from(concat!(icon!(search), " Search"));

if self.state != State::SearchFiltering {
label = label.dim();
}
spans.push(label);
spans.push(Span::from(""));

let search = Line::from(spans);
let margin = search.width() + 1;
Expand Down
39 changes: 15 additions & 24 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use std::borrow::Cow;

use itertools::Itertools;
use ratatui::{
prelude::{Alignment, Buffer, Constraint, Layout, Margin, Rect},
prelude::{Alignment, Buffer, Constraint, Layout, Rect},
style::{Modifier, Style, Stylize},
text::{Line, Span},
widgets::{
block::{Position, Title},
Block, BorderType, Borders, Cell, HighlightSpacing, Padding, Paragraph, Row, Scrollbar,
ScrollbarOrientation, ScrollbarState, StatefulWidget, Table, TableState, Tabs, Widget,
},
Expand Down Expand Up @@ -178,11 +177,14 @@ impl Subscription {
}

fn render_feeds(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
// padding
let feeds_area = area.inner(&Margin {
vertical: 1,
horizontal: 1,
});
let feeds_area = Block::new()
.padding(Padding {
top: 1,
left: 0,
right: 1,
bottom: 0,
})
.inner(area);

let mut feeds_state = TableState::new()
.with_offset(0)
Expand All @@ -208,7 +210,7 @@ impl Subscription {

let scrollbar_area = Rect {
y: area.y + 2, // table header
height: area.height.saturating_sub(3),
height: area.height.saturating_sub(1),
..area
};

Expand Down Expand Up @@ -317,16 +319,11 @@ impl Subscription {
fn render_feed_detail(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let block = Block::new()
.padding(Padding {
left: 3,
right: 3,
top: 1,
left: 2,
right: 2,
top: 0,
bottom: 0,
})
.title(
Title::from(" Detail ")
.position(Position::Top)
.alignment(Alignment::Center),
)
.borders(Borders::TOP)
.border_type(BorderType::Plain);

Expand All @@ -339,10 +336,7 @@ impl Subscription {

let vertical = Layout::vertical([Constraint::Length(3), Constraint::Min(0)]);
let [meta_area, entries_area] = vertical.areas(inner);
let entries_area = entries_area.inner(&Margin {
vertical: 1,
horizontal: 0,
});
let entries_area = Block::new().padding(Padding::top(1)).inner(entries_area);

let widths = [
Constraint::Length(11),
Expand Down Expand Up @@ -393,10 +387,7 @@ impl Subscription {
)),
Cell::new(Span::from(feed.category().as_str())),
Cell::new(Line::from(vec![
Span::styled(
" Requirement ",
Style::default().add_modifier(Modifier::BOLD),
),
Span::styled(" Req ", Style::default().add_modifier(Modifier::BOLD)),
Span::from(feed.requirement().to_string()),
])),
]),
Expand Down
4 changes: 2 additions & 2 deletions crates/synd_term/src/ui/components/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ impl Tabs {
impl Tabs {
pub fn render(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let area = Rect {
x: area.x + 3,
width: area.width.saturating_sub(5),
x: area.x + 2,
width: area.width.saturating_sub(3),
..area
};

Expand Down

0 comments on commit b2fa928

Please sign in to comment.