#[widget_mixin]Expand description
Expands a struct to a widget mixin.
Widget mixins can be inserted on a widgets inheritance chain, but they cannot be instantiated directly. Unlike the full widgets it defines its parent as a generic type, that must be filled with a real widget when used.
By convention mixins have the suffix Mix and the generic parent is named P. The P must not have any generic bounds
in the declaration, the expansion will bound it to WidgetImpl.
§Examples
use zng::prelude_wgt::*;
/// Make a widget capable of receiving keyboard focus.
#[widget_mixin]
pub struct FocusableMix<P>(P);
impl<P: WidgetImpl> FocusableMix<P> {
fn widget_intrinsic(&mut self) {
widget_set! {
self;
focusable = true;
}
}
widget_impl! {
/// If the widget can receive focus, enabled by default.
pub zng::focus::focusable(enabled: impl IntoVar<bool>);
}
}
/// Foo is focusable.
#[widget($crate::Foo)]
pub struct Foo(FocusableMix<WidgetBase>);The example above declares a mixin FocusableMix<P> and a widget Foo, the mixin is used as a parent of the widget, only
the Foo! { } widget can be instantiated, and it will have the strongly associated property focusable from the mixin.
All widget impl items can be declared in a mixin, including the fn widget_build(&mut self) -> T. Multiple mixins can be inherited
by nesting the types in a full widget Foo(AMix<BMix<Base>>). Mixins cannot inherit from other mixins.
Expands a generic struct to a widget mixin.
§Full Documentation
Read the documentation in the zng::widget::widget_mixin page.