mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 21:34:50 +00:00
Move the repeater part that is specific to rust within the rust lib
This commit is contained in:
parent
911d34e777
commit
56a75a69e5
3 changed files with 40 additions and 39 deletions
|
@ -66,13 +66,15 @@ fn main() {
|
|||
|
||||
pub use sixtyfps_rs_macro::sixtyfps;
|
||||
|
||||
pub(crate) mod repeater;
|
||||
|
||||
/// internal re_exports used by the macro generated
|
||||
#[doc(hidden)]
|
||||
pub mod re_exports {
|
||||
pub use crate::repeater::*;
|
||||
pub use const_field_offset::{self, FieldOffsets};
|
||||
pub use once_cell::sync::Lazy;
|
||||
pub use sixtyfps_corelib::abi::datastructures::*;
|
||||
pub use sixtyfps_corelib::abi::model::*;
|
||||
pub use sixtyfps_corelib::abi::primitives::*;
|
||||
pub use sixtyfps_corelib::abi::properties::Property;
|
||||
pub use sixtyfps_corelib::abi::signals::Signal;
|
||||
|
|
37
api/sixtyfps-rs/repeater.rs
Normal file
37
api/sixtyfps-rs/repeater.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
/// Component that can be instantiated by a repeater.
|
||||
pub trait RepeatedComponent: sixtyfps_corelib::abi::datastructures::Component {
|
||||
/// The data corresponding to the model
|
||||
type Data;
|
||||
|
||||
/// Update this component at the given index and the given data
|
||||
fn update(&self, index: usize, data: &Self::Data);
|
||||
}
|
||||
|
||||
/// This field is put in a component when using the `for` syntax
|
||||
/// It helps instantiating the components `C`
|
||||
#[derive(Default)]
|
||||
pub struct Repeater<C> {
|
||||
components: Vec<Box<C>>,
|
||||
}
|
||||
|
||||
impl<Data, C> Repeater<C>
|
||||
where
|
||||
C: RepeatedComponent<Data = Data>,
|
||||
{
|
||||
/// Called when the model is changed
|
||||
pub fn update_model(&mut self, data: &[Data]) {
|
||||
self.components.clear();
|
||||
for (i, d) in data.iter().enumerate() {
|
||||
let c = C::create();
|
||||
c.update(i, d);
|
||||
self.components.push(Box::new(c));
|
||||
}
|
||||
}
|
||||
|
||||
/// Call the visitor for each component
|
||||
pub fn visit(&self, mut visitor: sixtyfps_corelib::abi::datastructures::ItemVisitorRefMut) {
|
||||
for c in &self.components {
|
||||
c.visit_children_item(-1, visitor.borrow_mut());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,41 +26,3 @@ pub struct ComponentVecHolder {
|
|||
_todo: Vec<vtable::VBox<super::datastructures::ComponentVTable>>,
|
||||
}
|
||||
*/
|
||||
|
||||
/// Component that can be instantiated by a repeater.
|
||||
pub trait RepeatedComponent: crate::abi::datastructures::Component {
|
||||
/// The data corresponding to the model
|
||||
type Data;
|
||||
|
||||
/// Update this component at the given index and the given data
|
||||
fn update(&self, index: usize, data: &Self::Data);
|
||||
}
|
||||
|
||||
/// This field is put in a component when using the `for` syntax
|
||||
/// It helps instantiating the components `C`
|
||||
#[derive(Default)]
|
||||
pub struct Repeater<C> {
|
||||
components: Vec<Box<C>>,
|
||||
}
|
||||
|
||||
impl<Data, C> Repeater<C>
|
||||
where
|
||||
C: RepeatedComponent<Data = Data>,
|
||||
{
|
||||
/// Called when the model is changed
|
||||
pub fn update_model(&mut self, data: &[Data]) {
|
||||
self.components.clear();
|
||||
for (i, d) in data.iter().enumerate() {
|
||||
let c = C::create();
|
||||
c.update(i, d);
|
||||
self.components.push(Box::new(c));
|
||||
}
|
||||
}
|
||||
|
||||
/// Call the visitor for each component
|
||||
pub fn visit(&self, mut visitor: super::datastructures::ItemVisitorRefMut) {
|
||||
for c in &self.components {
|
||||
c.visit_children_item(-1, visitor.borrow_mut());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue