use std::hash::Hash;
use super::*;
use ggez::{graphics::Canvas, Context};
pub trait UiContent<T: Copy + Eq + Hash> {
fn to_element_builder(self, id: u32, _ctx: &Context) -> UiElementBuilder<T>
where
Self: Sized + 'static,
{
UiElementBuilder::new(id, self)
}
fn to_element(self, id: u32, ctx: &Context) -> UiElement<T>
where
Self: Sized + 'static,
{
self.to_element_builder(id, ctx).build()
}
fn draw_content(&mut self, ctx: &mut Context, canvas: &mut Canvas, param: UiDrawParam);
fn expired(&self) -> bool {
false
}
fn container(&self) -> Option<&dyn UiContainer<T>> {
None
}
fn container_mut(&mut self) -> Option<&mut dyn UiContainer<T>> {
None
}
}
pub trait UiContainer<T: Copy + Eq + Hash>: UiContent<T> {
fn content_width_range(&self) -> (f32, f32) {
(0., f32::INFINITY)
}
fn content_height_range(&self) -> (f32, f32) {
(0., f32::INFINITY)
}
fn get_children(&self) -> &[UiElement<T>];
fn get_children_mut(&mut self) -> &mut [UiElement<T>];
fn add(&mut self, element: UiElement<T>);
fn remove_expired(&mut self);
fn remove_id(&mut self, id: u32);
}