Trait sixtyfps_corelib::model::Model [−][src]
pub trait Model { type Data; fn row_count(&self) -> usize; fn row_data(&self, row: usize) -> Self::Data; fn attach_peer(&self, peer: ModelPeer); fn set_row_data(&self, _row: usize, _data: Self::Data) { ... } fn iter(&self) -> ModelIterator<'_, Self::Data>ⓘNotable traits for ModelIterator<'a, T>impl<'a, T> Iterator for ModelIterator<'a, T> type Item = T;
where
Self: Sized, { ... } fn as_any(&self) -> &dyn Any { ... } }
Expand description
A Model is providing Data for the Repeater or ListView elements of the .60
language
Associated Types
Required methods
Returns the data for a particular row. This function should be called with row < row_count()
.
fn attach_peer(&self, peer: ModelPeer)
fn attach_peer(&self, peer: ModelPeer)
Should forward to the internal ModelNotify::attach
Provided methods
fn set_row_data(&self, _row: usize, _data: Self::Data)
fn set_row_data(&self, _row: usize, _data: Self::Data)
Sets the data for a particular row. This function should be called with row < row_count()
.
If the model cannot support data changes, then it is ok to do nothing (default implementation).
If the model can update the data, it should also call row_changed on its internal ModelNotify
.
fn iter(&self) -> ModelIterator<'_, Self::Data>ⓘNotable traits for ModelIterator<'a, T>impl<'a, T> Iterator for ModelIterator<'a, T> type Item = T;
where
Self: Sized,
fn iter(&self) -> ModelIterator<'_, Self::Data>ⓘNotable traits for ModelIterator<'a, T>impl<'a, T> Iterator for ModelIterator<'a, T> type Item = T;
where
Self: Sized,
impl<'a, T> Iterator for ModelIterator<'a, T> type Item = T;
Returns an iterator visiting all elements of the model.
Return something that can be downcast’ed (typically self)
This is useful to get back to the actual model from a ModelHandle stored in a component.
let vec_model = Rc::new(VecModel::from(vec![1i32, 2, 3])); let handle = ModelHandle::from(vec_model as Rc<dyn Model<Data = i32>>); // later: handle.as_any().downcast_ref::<VecModel<i32>>().unwrap().push(4); assert_eq!(handle.row_data(3), 4);
Note: the default implementation returns nothing interesting. this method should be implemented by model implementation to return something useful. For example:
fn as_any(&self) -> &dyn core::any::Any { self }