pub trait Driver<Item, Data>where
Data: SharedData<Item = Item>,{
type Widget: Widget<Data = Item>;
// Required method
fn make(&mut self, key: &<Data as SharedData>::Key) -> Self::Widget;
// Provided methods
fn set_key(
&mut self,
widget: &mut Self::Widget,
key: &<Data as SharedData>::Key
) { ... }
fn on_messages(
&mut self,
cx: &mut EventCx<'_>,
data: &Data,
key: &<Data as SharedData>::Key,
widget: &mut Self::Widget
) { ... }
}
view
only.Expand description
View widget driver
This trait is implemented to “drive” a ListView
or MatrixView
,
constructing, updating, and optionally intercepting messages from so called
“view widgets”.
A few simple implementations are provided: View
, NavView
.
Each view widget has an Id
corresponding to its data item, and
handles events like any other widget. In order to associate a returned
message with a SharedData::Key
, either embed that key while constructing
the widget with Driver::make
or intercept the message in
Driver::on_messages
.
NOTE: Item
is a direct type parameter (in addition to an assoc. type
param. of SharedData
) only to avoid “conflicting implementations” errors.
Similar to: rust#20400, rust#92894. Given fixes, we may remove the param.
Required Associated Types§
Required Methods§
sourcefn make(&mut self, key: &<Data as SharedData>::Key) -> Self::Widget
fn make(&mut self, key: &<Data as SharedData>::Key) -> Self::Widget
Construct a new view widget
Provided Methods§
sourcefn set_key(
&mut self,
widget: &mut Self::Widget,
key: &<Data as SharedData>::Key
)
fn set_key( &mut self, widget: &mut Self::Widget, key: &<Data as SharedData>::Key )
Called to bind an existing view widget to a new key
This should reset widget metadata, for example so that when a view widget with a text selection is assigned to a new key it does not attempt to apply the old selection to the new text.
This does not need to set data; Events::update
does that.
The default implementation simply replaces widget with self.make(key)
,
which is sufficient, if not always optimal.