26 lines
709 B
Rust
26 lines
709 B
Rust
use crate::{HasUi, StateLike, WidgetIdFn, WidgetLike, WidgetRef};
|
|
|
|
pub trait WidgetAttr<State, W: ?Sized> {
|
|
type Input;
|
|
fn run(state: &mut State, id: WidgetRef<W>, input: Self::Input);
|
|
}
|
|
|
|
pub trait Attrable<State, W: ?Sized, Tag> {
|
|
fn attr<A: WidgetAttr<State, W>>(self, input: A::Input) -> impl WidgetIdFn<State, W>;
|
|
}
|
|
|
|
impl<State: HasUi + StateLike<State>, WL: WidgetLike<State, Tag>, Tag>
|
|
Attrable<State, WL::Widget, Tag> for WL
|
|
{
|
|
fn attr<A: WidgetAttr<State, WL::Widget>>(
|
|
self,
|
|
input: A::Input,
|
|
) -> impl WidgetIdFn<State, WL::Widget> {
|
|
|state| {
|
|
let id = self.add(state);
|
|
A::run(state, id, input);
|
|
id
|
|
}
|
|
}
|
|
}
|