use core::ops::Range;
use crate::{draw_target::DrawTarget, primitives::common::Scanline};
#[derive(Clone, Eq, PartialEq, Hash, Debug)]
#[cfg_attr(feature = "defmt", derive(::defmt::Format))]
pub struct StyledScanline {
y: i32,
stroke_range: Range<i32>,
fill_range: Range<i32>,
}
impl StyledScanline {
pub fn new(y: i32, stroke_range: Range<i32>, fill_range: Option<Range<i32>>) -> Self {
let fill_range = fill_range.unwrap_or_else(|| stroke_range.end..stroke_range.end);
Self {
y,
stroke_range,
fill_range,
}
}
pub const fn stroke_left(&self) -> Scanline {
Scanline::new(self.y, self.stroke_range.start..self.fill_range.start)
}
pub const fn stroke_right(&self) -> Scanline {
Scanline::new(self.y, self.fill_range.end..self.stroke_range.end)
}
pub fn fill(&self) -> Scanline {
Scanline::new(self.y, self.fill_range.clone())
}
pub fn draw_stroke<T: DrawTarget>(
&self,
target: &mut T,
stroke_color: T::Color,
) -> Result<(), T::Error> {
self.stroke_left().draw(target, stroke_color)?;
self.stroke_right().draw(target, stroke_color)
}
pub fn draw_stroke_and_fill<T: DrawTarget>(
&self,
target: &mut T,
stroke_color: T::Color,
fill_color: T::Color,
) -> Result<(), T::Error> {
self.stroke_left().draw(target, stroke_color)?;
self.fill().draw(target, fill_color)?;
self.stroke_right().draw(target, stroke_color)
}
}