use std::time::Instant;
use tessera_ui::{
Color, ComputedData, Dp, LayoutInput, LayoutOutput, LayoutSpec, MeasurementError, Px,
RenderInput, tessera,
};
use crate::pipelines::shape::command::ShapeCommand;
pub(crate) const CURSOR_WIDRH: Dp = Dp(2.5);
#[derive(Clone, PartialEq)]
struct CursorLayout {
height: Px,
visible: bool,
}
impl LayoutSpec for CursorLayout {
fn measure(
&self,
_input: &LayoutInput<'_>,
_output: &mut LayoutOutput<'_>,
) -> Result<ComputedData, MeasurementError> {
Ok(ComputedData {
width: CURSOR_WIDRH.into(),
height: self.height,
})
}
fn record(&self, input: &RenderInput<'_>) {
if !self.visible {
return;
}
let drawable = ShapeCommand::Rect {
color: Color::BLACK,
corner_radii: glam::Vec4::ZERO.into(),
corner_g2: [3.0; 4],
shadow: None,
};
input.metadata_mut().push_draw_command(drawable);
}
}
#[tessera]
pub(super) fn cursor(height_px: Px, bink_timer: Instant) {
let visible = bink_timer.elapsed().as_millis() % 1000 >= 500;
layout(CursorLayout {
height: height_px,
visible,
});
}