30 lines
801 B
Rust
30 lines
801 B
Rust
use crate::Widget;
|
|
|
|
pub struct WidgetData {
|
|
pub widget: Box<dyn Widget>,
|
|
pub label: String,
|
|
pub borrowed: bool,
|
|
}
|
|
|
|
impl WidgetData {
|
|
pub fn new<W: Widget>(widget: W) -> Self {
|
|
let name = std::any::type_name::<W>();
|
|
let label = match (name.find("::"), name.rfind("::")) {
|
|
(Some(first), Some(last)) => {
|
|
let suffix = &name[last + 2..];
|
|
let mut label = String::with_capacity(first + 2 + suffix.len());
|
|
label.push_str(&name[..first]);
|
|
label.push_str("::");
|
|
label.push_str(suffix);
|
|
label
|
|
}
|
|
_ => name.to_owned(),
|
|
};
|
|
Self {
|
|
widget: Box::new(widget),
|
|
label,
|
|
borrowed: false,
|
|
}
|
|
}
|
|
}
|