pub trait DataGenerator<Index> {
type Data;
type Key: DataKey;
type Item: Clone + Default + PartialEq;
// Required methods
fn update(&mut self, data: &Self::Data) -> GeneratorChanges<Index>;
fn len(&self, data: &Self::Data, lbound: Index) -> DataLen<Index>;
fn key(&self, data: &Self::Data, index: Index) -> Option<Self::Key>;
fn generate(&self, data: &Self::Data, key: &Self::Key) -> Self::Item;
}Expand description
A generator for use with GeneratorClerk
This provides a substantially simpler interface than DataClerk.
Required Associated Types§
Sourcetype Data
type Data
Input data type (of parent widget)
Data of this type is passed through the parent widget; see
Widget::Data and the Events trait. This input data might be used
to access a data set stored in another widget or to pass a query or
filter into the DataClerk.
Note that it is not currently possible to pass in references to multiple
data items (such as an external data set and a filter) via Data. This
would require use of Generic Associated Types (GATs), not only here but
also in the Widget trait; alas, GATs are not (yet)
compatible with dyn traits and Kas requires use of dyn Widget. Instead
one can share the data set (e.g. Rc<RefCell<DataSet>>) or store within
the DataClerk using the clerk / clerk_mut methods to access; in
both cases it may be necessary to update the view controller explicitly
(e.g. cx.update(list.as_node(&input))) after the data set changes.
Required Methods§
Sourcefn update(&mut self, data: &Self::Data) -> GeneratorChanges<Index>
fn update(&mut self, data: &Self::Data) -> GeneratorChanges<Index>
Update the generator
This is called by kas::Events::update. It should update self as
required reflecting possible data-changes and indicate through the
returned GeneratorChanges value the updates required to tokens and
views.
Note: this method is called automatically when input data changes. When
data owned or referenced by the DataClerk implementation is changed it
may be necessary to explicitly update the view controller, e.g. using
ConfigCx::update or Action::UPDATE.
This method may be called frequently and without changes to data.
Sourcefn len(&self, data: &Self::Data, lbound: Index) -> DataLen<Index>
fn len(&self, data: &Self::Data, lbound: Index) -> DataLen<Index>
Get the number of indexable items
Scroll bars and the index values passed to Self::generate are
limited by the result of this method.
Where the data set size is a known fixed len (or unfixed but with
maximum len <= lbound), this method should return
DataLen::Known(len).
Where the data set size is unknown (or unfixed and greater than
lbound), this method should return
DataLen::LBound(lbound).
lbound is set to allow scrolling a little beyond the current view
position (i.e. a little larger than the last prepared range.end).
Sourcefn key(&self, data: &Self::Data, index: Index) -> Option<Self::Key>
fn key(&self, data: &Self::Data, index: Index) -> Option<Self::Key>
Get a key for a given index, if available
This method should be fast since it may be called repeatedly.
This method is only called for index less than the result of
Self::len.
This may return None even when index is within the query’s range
since data may be sparse; in this case the view widget at this index
is hidden.