use crate::{
plugin::PluginMarker as Plugin, rendering::cursor::Cursor, style::VerticalOverdraw, TextBox,
};
use core::ops::Range;
use embedded_graphics::{geometry::Dimensions, text::renderer::TextRenderer};
#[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)]
pub enum HeightMode {
Exact(VerticalOverdraw),
FitToText,
ShrinkToText(VerticalOverdraw),
}
impl HeightMode {
pub(crate) fn apply<'a, F, M>(self, text_box: &mut TextBox<'a, F, M>)
where
F: TextRenderer,
M: Plugin<'a, F::Color>,
{
match self {
HeightMode::Exact(_) => {}
HeightMode::FitToText => {
text_box.fit_height();
}
HeightMode::ShrinkToText(_) => {
text_box.fit_height_limited(text_box.bounding_box().size.height);
}
}
}
pub(crate) fn calculate_displayed_row_range(self, cursor: &Cursor) -> Range<u32> {
let overdraw = match self {
HeightMode::Exact(overdraw) | HeightMode::ShrinkToText(overdraw) => overdraw,
HeightMode::FitToText => VerticalOverdraw::Visible,
};
overdraw.calculate_displayed_row_range(cursor)
}
}