2024-02-17 14:43:46 -06:00
|
|
|
use std::any::Any;
|
|
|
|
use crate::{
|
2024-02-19 14:12:12 -06:00
|
|
|
draw::UiDrawCommandList,
|
2024-02-17 14:43:46 -06:00
|
|
|
measure::Response,
|
2024-02-17 21:04:02 -06:00
|
|
|
state::StateRepo,
|
|
|
|
text::TextMeasure,
|
|
|
|
LayoutInfo
|
2024-02-17 14:43:46 -06:00
|
|
|
};
|
|
|
|
|
2024-02-19 16:13:35 -06:00
|
|
|
mod builtin;
|
2024-02-17 14:43:46 -06:00
|
|
|
pub use builtin::*;
|
|
|
|
|
2024-02-17 21:04:02 -06:00
|
|
|
pub struct MeasureContext<'a> {
|
|
|
|
pub state: &'a StateRepo,
|
|
|
|
pub layout: &'a LayoutInfo,
|
|
|
|
pub text_measure: TextMeasure<'a>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ProcessContext<'a> {
|
|
|
|
pub measure: &'a Response,
|
|
|
|
pub state: &'a mut StateRepo,
|
|
|
|
pub layout: &'a LayoutInfo,
|
2024-02-19 14:12:12 -06:00
|
|
|
pub draw: &'a mut UiDrawCommandList,
|
2024-02-17 21:04:02 -06:00
|
|
|
pub text_measure: TextMeasure<'a>,
|
|
|
|
}
|
|
|
|
|
2024-02-17 14:43:46 -06:00
|
|
|
pub trait UiElement {
|
|
|
|
fn name(&self) -> &'static str { "UiElement" }
|
|
|
|
fn state_id(&self) -> Option<u64> { None }
|
|
|
|
fn is_stateful(&self) -> bool { self.state_id().is_some() }
|
|
|
|
fn is_stateless(&self) -> bool { self.state_id().is_none() }
|
|
|
|
fn init_state(&self) -> Option<Box<dyn Any>> { None }
|
2024-02-17 21:04:02 -06:00
|
|
|
fn measure(&self, ctx: MeasureContext) -> Response;
|
|
|
|
fn process(&self, ctx: ProcessContext);
|
2024-02-17 14:43:46 -06:00
|
|
|
}
|