use crate::drawing::{DrawingCtx, FrameBuilder};
use crate::frame::{FontId, FontStyleRef};
use crate::geom::{Css, Px, RectPx};
use crate::text::{TextMeasurer, text_width};
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum LayerPosition {
Background,
BelowSeries,
AboveSeries,
Overlay,
}
pub trait LayerPlugin: Send {
fn position(&self) -> LayerPosition;
fn build(&self, ctx: &LayerCtx<'_>, out: &mut FrameBuilder<'_>);
}
pub struct LayerCtx<'a> {
pub(crate) rect: RectPx,
pub(crate) dpr: f32,
pub(crate) text: &'a dyn TextMeasurer,
pub(crate) coords: Option<DrawingCtx<'a>>,
}
impl<'a> LayerCtx<'a> {
pub fn rect(&self) -> RectPx {
self.rect
}
pub fn dpr(&self) -> f32 {
self.dpr
}
pub fn px(&self, v: Css) -> Px {
v.to_px(self.dpr)
}
pub fn font(&self, size: Css) -> FontStyleRef {
FontStyleRef {
font: FontId(0),
size: size.to_px(self.dpr).0,
}
}
pub fn text_width(&self, text: &str, font: FontStyleRef) -> f32 {
text_width(self.text, text, font)
}
pub fn line_height(&self, font: FontStyleRef) -> f32 {
self.text.line_height(font)
}
pub fn coords(&self) -> Option<&DrawingCtx<'a>> {
self.coords.as_ref()
}
}