use crate::prelude::*;
use getset::{Getters, MutGetters};
use ratatui::prelude::Rect;
#[derive(Default, Clone, Copy, Getters, MutGetters)]
#[getset(get = "pub", get_mut = "pub")]
pub struct PanelAreas {
feed_list: Rect,
articles_list: Rect,
article_content: Rect,
}
impl PanelAreas {
pub(super) fn panel_at(&self, col: u16, row: u16) -> Option<Panel> {
if self.feed_list.contains((col, row).into()) {
Some(Panel::FeedList)
} else if self.articles_list.contains((col, row).into()) {
Some(Panel::ArticleList)
} else if self.article_content.contains((col, row).into()) {
Some(Panel::ArticleContent)
} else {
None
}
}
pub(super) fn article_row_offset(&self, row: u16) -> Option<u16> {
let area = self.articles_list;
let inner_top = area.y + 1;
let inner_bottom = area.y + area.height.saturating_sub(1);
if row >= inner_top && row < inner_bottom {
Some(row - inner_top)
} else {
None
}
}
pub(super) fn is_on_horizontal_border(&self, col: u16, row: u16) -> bool {
let border_row = self.articles_list.y + self.articles_list.height;
let in_column_range =
col >= self.articles_list.x && col < self.articles_list.x + self.articles_list.width;
row == border_row && in_column_range
}
}