27 lines
747 B
Rust
27 lines
747 B
Rust
use std::any::TypeId;
|
|
|
|
use crate::{Widget, util::HashSet};
|
|
|
|
pub struct WidgetData<State> {
|
|
pub widget: Box<dyn Widget<State>>,
|
|
pub label: String,
|
|
pub event_mgrs: HashSet<TypeId>,
|
|
/// dynamic borrow checking
|
|
pub borrowed: bool,
|
|
}
|
|
|
|
impl<State> WidgetData<State> {
|
|
pub fn new<W: Widget<State>>(widget: W) -> Self {
|
|
let mut label = std::any::type_name::<W>().to_string();
|
|
if let (Some(first), Some(last)) = (label.find(":"), label.rfind(":")) {
|
|
label = label.split_at(first).0.to_string() + "::" + label.split_at(last + 1).1;
|
|
}
|
|
Self {
|
|
widget: Box::new(widget),
|
|
label,
|
|
borrowed: false,
|
|
event_mgrs: Default::default(),
|
|
}
|
|
}
|
|
}
|