ux-components 0.1.3

Backend agnostic GUI framework
Documentation
/*
build(BuildContext context, int index) -> Widget?
Returns the child with the given index.
override
debugFillDescription(List<String> description) -> void
Add additional information to the given description for use by toString.
@mustCallSuper, @protected, inherited
didFinishLayout(int firstIndex, int lastIndex) -> void
Called at the end of layout to indicate that layout is now complete.
inherited
estimateMaxScrollOffset(int firstIndex, int lastIndex, double leadingScrollOffset, double trailingScrollOffset) -> double?
Returns an estimate of the max scroll extent for all the children.
inherited
findIndexByKey(Key key) -> int?
Find index of child element with associated key.
override
noSuchMethod(Invocation invocation) -> dynamic
Invoked when a non-existent method or property is accessed.
inherited
shouldRebuild(covariant SliverChildBuilderDelegate oldDelegate) -> bool
Called whenever a new instance of the child delegate class is provided to the sliver.
override
toString() -> String
A string representation of this object.
inherited
*/

use crate::foundation::Key;

use super::{BuildContext, Widget};

// Widget widget, int localIndex
pub type SemanticIndexCallback = Box<dyn Fn(&dyn Widget, usize) -> Option<usize>>;

pub type ChildIndexGetter = Box<dyn Fn(Key) -> Option<usize>>;

// BuildContext context, int index
pub type NullableIndexedWidgetBuilder = Box<dyn Fn(BuildContext, usize) -> Option<Box<dyn Widget>>>;

pub struct SliverChildBuilderDelegate {
    // Whether to wrap each child in an AutomaticKeepAlive.
    pub add_automatic_keep_alives: bool,

    // Whether to wrap each child in a RepaintBoundary.
    pub add_repaint_boundaries: bool,

    // Whether to wrap each child in an IndexedSemantics.
    pub add_semantic_indexes: bool,

    // Called to build children for the sliver.
    pub builder: NullableIndexedWidgetBuilder,

    // The total number of children this delegate can provide.
    pub child_count: usize,

    // Returns an estimate of the number of children this delegate will build.
    pub estimated_child_count: i32,

    // Called to find the new index of a child based on its key in case of reordering.
    pub find_child_index_callback: ChildIndexGetter,

    // A SemanticIndexCallback which is used when addSemanticIndexes is true.
    pub semantic_index_callback: SemanticIndexCallback,

    // An initial offset to add to the semantic indexes generated by this widget.
    pub semantic_index_offset: i32,
}

impl Default for SliverChildBuilderDelegate {
    fn default() -> Self {
        Self {
            add_automatic_keep_alives: Default::default(),
            add_repaint_boundaries: Default::default(),
            add_semantic_indexes: Default::default(),
            builder: box |_,_| None,
            child_count: Default::default(),
            estimated_child_count: Default::default(),
            find_child_index_callback: box |_| None,
            semantic_index_callback: box |_,_| None,
            semantic_index_offset: Default::default(),
        }
    }
}