Lines
100 %
Functions
Branches
//! A field caption as Turbo Vision draws it: lit while the control it names has the focus.
use ratatui::buffer::Buffer;
use ratatui::layout::Rect;
use ratatui::text::Line;
use ratatui::widgets::{Paragraph, Widget};
use crate::{Role, Theme};
/// The text of a field caption, drawn as it is.
pub struct Label<'a> {
theme: &'a Theme,
text: &'a str,
lit: bool,
}
impl<'a> Label<'a> {
/// `lit` is whether the linked control has the focus.
#[must_use]
pub fn new(theme: &'a Theme, text: &'a str, lit: bool) -> Self {
Label { theme, text, lit }
impl Widget for Label<'_> {
fn render(self, area: Rect, buf: &mut Buffer) {
let role = if self.lit {
Role::LabelLit
} else {
Role::Label
};
let base = self.theme.style(role);
buf.set_style(area.intersection(buf.area), base);
Paragraph::new(Line::styled(self.text, base)).render(area, buf);
#[cfg(test)]
mod tests;