hUI/hui/src/element.rs

36 lines
934 B
Rust
Raw Normal View History

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,
state::StateRepo,
text::TextMeasure,
LayoutInfo
2024-02-17 14:43:46 -06:00
};
mod builtin;
2024-02-17 14:43:46 -06:00
pub use builtin::*;
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,
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 }
fn measure(&self, ctx: MeasureContext) -> Response;
fn process(&self, ctx: ProcessContext);
2024-02-17 14:43:46 -06:00
}