use crate::core::{ObjectId, Point, Rect, Size};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SizePolicy {
Fixed,
Preferred,
Expanding,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct LayoutConstraints {
pub min: u32,
pub max: Option<u32>,
}
impl LayoutConstraints {
pub fn new(min: u32, max: Option<u32>) -> Self {
Self { min, max }
}
}
#[derive(Debug, Clone, Copy)]
pub struct LayoutContext {
pub layout_scale: f32,
pub font_scale: f32,
pub min_touch_size: Size,
}
impl Default for LayoutContext {
fn default() -> Self {
Self { layout_scale: 1.0, font_scale: 1.0, min_touch_size: Size::new(32, 32) }
}
}
pub trait Layout {
fn add_widget(&mut self, widget_id: ObjectId, stretch: u32);
fn remove_widget(&mut self, widget_id: ObjectId);
fn update(&self, rect: Rect, widgets: &mut dyn FnMut(ObjectId, Rect));
fn update_from_position_size(
&self,
position: Point,
size: Size,
widgets: &mut dyn FnMut(ObjectId, Rect),
) {
self.update(Rect::from_position_size(position, size), widgets);
}
fn child_ids(&self) -> Vec<ObjectId> {
vec![]
}
fn has_child(&self, _id: ObjectId) -> bool {
false
}
fn clear(&mut self) {
}
fn update_with_context(
&self,
rect: Rect,
context: &LayoutContext,
widgets: &mut dyn FnMut(ObjectId, Rect),
) {
let _ = context;
self.update(rect, widgets);
}
fn as_any(&self) -> &dyn std::any::Any;
fn as_any_mut(&mut self) -> &mut dyn std::any::Any;
}