Files

73 lines
2.1 KiB
Rust

/*
* Copyright (C) 2023 Valentin Lorentz
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use enum_dispatch::enum_dispatch;
use ratatui::prelude::*;
use ratatui::widgets::Widget;
mod bottom_aligned_paragraph;
pub use bottom_aligned_paragraph::BottomAlignedParagraph;
pub(crate) mod prerender;
pub use prerender::Prerender;
mod divider;
pub use divider::Divider;
#[rustfmt::skip] // reflow is vendored from ratatui, let's avoid changes
mod reflow;
/// A [`Widget`] that returns how many columns and lines it needs to draw everything
/// (which is the number of lines it actually drew if it fits on screen)
#[enum_dispatch]
pub trait OverlappableWidget {
/// Returns how many lines, from the bottom of the area, this widget would actually draw
/// if rendered with the given width
fn height(&self, width: u16) -> u64;
/// Render the widget from the bottom, and return the width and height of the area
/// actually drawn.
fn render_overlap(self, area: Rect, buf: &mut Buffer) -> (u16, u16);
}
/// Enum of [`OverlappableWidget`] implementors
#[enum_dispatch(OverlappableWidget)]
pub enum BacklogItemWidget<'a> {
Paragraph(BottomAlignedParagraph<'a>),
Divider(Divider<'a>),
Empty(EmptyWidget),
}
#[derive(Clone)]
pub struct EmptyWidget;
impl OverlappableWidget for EmptyWidget {
fn height(&self, _width: u16) -> u64 {
0
}
fn render_overlap(self, _area: Rect, _buf: &mut Buffer) -> (u16, u16) {
(0, 0)
}
}
/*
impl<W: OverlappableWidget> Widget for W {
fn render(self, area: Rect, buf: &mut Buffer) {
self.render_overlap(area, buf);
}
}
*/