1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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;