Skip to content

Commit

Permalink
feat(term): make the space policy consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
ymgyt committed Mar 18, 2024
1 parent ef2842e commit 0a3d9df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 20 deletions.
6 changes: 3 additions & 3 deletions crates/synd_term/src/ui/components/entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Entries {

impl Entries {
pub fn render(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let vertical = Layout::vertical([Constraint::Percentage(70), Constraint::Percentage(30)]);
let vertical = Layout::vertical([Constraint::Fill(2), Constraint::Fill(1)]);
let [entries_area, summary_area] = vertical.areas(area);

self.render_entries(entries_area, buf, cx);
Expand Down Expand Up @@ -161,8 +161,8 @@ impl Entries {
fn render_summary(&self, area: Rect, buf: &mut Buffer, _cx: &Context<'_>) {
let block = Block::new()
.padding(Padding {
left: 1,
right: 1,
left: 3,
right: 3,
top: 1,
bottom: 1,
})
Expand Down
25 changes: 11 additions & 14 deletions crates/synd_term/src/ui/components/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use ratatui::{
},
};
use synd_feed::types::FeedType;
use unicode_segmentation::UnicodeSegmentation;

use crate::{
application::{Direction, IndexOutOfRange, ListAction},
Expand Down Expand Up @@ -92,7 +91,7 @@ impl Subscription {

impl Subscription {
pub fn render(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let vertical = Layout::vertical([Constraint::Min(0), Constraint::Max(19)]);
let vertical = Layout::vertical([Constraint::Fill(2), Constraint::Fill(1)]);
let [feeds_area, feed_detail_area] = vertical.areas(area);

self.render_feeds(feeds_area, buf, cx);
Expand All @@ -113,6 +112,12 @@ impl Subscription {
let (header, widths, rows) = self.feed_rows(cx);

let feeds = Table::new(rows, widths)
.block(Block::new().padding(Padding {
left: 0,
right: 2,
top: 0,
bottom: 0,
}))
.header(header.style(cx.theme.subscription.header))
.column_spacing(2)
.style(cx.theme.subscription.background)
Expand Down Expand Up @@ -195,8 +200,8 @@ impl Subscription {
fn render_feed_detail(&self, area: Rect, buf: &mut Buffer, cx: &Context<'_>) {
let block = Block::new()
.padding(Padding {
left: 1,
right: 1,
left: 3,
right: 3,
top: 1,
bottom: 1,
})
Expand Down Expand Up @@ -264,14 +269,6 @@ impl Subscription {
};
Widget::render(meta, meta_area, buf);

let title_width = feed
.entries
.iter()
.filter_map(|entry| entry.title.as_deref())
.map(|title| title.graphemes(true).count())
.max()
.unwrap_or(0);

let entry = |entry: &EntryMeta| {
let title = entry.title.as_deref().unwrap_or(ui::UNKNOWN_SYMBOL);
let published = entry
Expand All @@ -296,8 +293,8 @@ impl Subscription {

let widths = [
Constraint::Length(10),
Constraint::Length(title_width.try_into().unwrap_or(100)),
Constraint::Max(200),
Constraint::Fill(1),
Constraint::Fill(2),
];
let rows = feed.entries.iter().map(entry);
let table = Table::new(rows, widths)
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 + 4,
width: area.width - 6,
x: area.x + 3,
width: area.width - 5,
..area
};
// left padding * 2 + len("Entries" + "Feeds") = 20
Expand Down
2 changes: 1 addition & 1 deletion crates/synd_term/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod theme;
pub mod widgets;

pub const UNKNOWN_SYMBOL: &str = "-";
pub const TABLE_HIGHLIGHT_SYMBOL: &str = ">> ";
pub const TABLE_HIGHLIGHT_SYMBOL: &str = " ";

pub struct Context<'a> {
pub theme: &'a Theme,
Expand Down

0 comments on commit 0a3d9df

Please sign in to comment.