yuno 0.1.1

A declarative UI layout and rendering framework powered by Skia.
pub mod sprites;

use anyhow::Result;
use skia_safe::{Canvas, Rect};

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Plan {
    None,     // Whatever, give as much as you like.
    Fit(f32), // I need this much space.
    Fill,     // Give me as much space as you can; give me all the space others don't want.
}

pub trait Drawable: HasPlanner {
    fn draw(&self, canvas: &Canvas) -> Result<()>;

    // The control can specify how much space it needs (but the planner may not follow), which is important for planners like Row and Column.
    // Note that this is the control's own declaration;
    // its implementation must not call `get_planned_drawing_area`, because `measure_child` itself may depend on `get_required_size`.
    // If a control doesn't know its own size, it delegates this decision to its parent layout manager, and `get_required_size` should return `None`.
    fn get_horizontal_plan(&self) -> Plan;
    fn get_vertical_plan(&self) -> Plan;

    fn get_planned_drawing_area(&self, canvas: &Canvas) -> Rect
    where
        Self: Sized,
    {
        if let Some(p) = self.planner().borrow().as_ref() {
            return p.measure_child(self, canvas);
        }

        Rect {
            left: 0.0,
            top: 0.0,
            right: canvas.image_info().width() as f32,
            bottom: canvas.image_info().height() as f32,
        }
    }
}

use crate::layouts::HasPlanner;
#[allow(unused)]
pub use sprites::RoundedRectangle;