21 lines
574 B
Rust
21 lines
574 B
Rust
use crate::layout::{Ui, WidgetRef, WidgetIdFn, WidgetLike};
|
|
|
|
pub trait WidgetAttr<W: ?Sized> {
|
|
type Input;
|
|
fn run(ui: &mut Ui, id: &WidgetRef<W>, input: Self::Input);
|
|
}
|
|
|
|
pub trait Attrable<W: ?Sized, Tag> {
|
|
fn attr<A: WidgetAttr<W>>(self, input: A::Input) -> impl WidgetIdFn<W>;
|
|
}
|
|
|
|
impl<WL: WidgetLike<Tag>, Tag> Attrable<WL::Widget, Tag> for WL {
|
|
fn attr<A: WidgetAttr<WL::Widget>>(self, input: A::Input) -> impl WidgetIdFn<WL::Widget> {
|
|
|ui| {
|
|
let id = self.add(ui);
|
|
A::run(ui, &id, input);
|
|
id
|
|
}
|
|
}
|
|
}
|