Rui::Model::SelectionInList - selection in a list
$selectionInList = Rui::Model::SelectionInList->new( list => Rui::Model::List->new(data => qw[ a b c ]), selection => Rui::Model::Value->new(value => 'a'), ); $selectionInList = Rui::Model::SelectionInList->new( data => [qw( a b c )], selectedItem => 'a', attach => 0, # not needed because 0 is default ); $selectionInList = Rui::Model::SelectionInList->new( data => [qw( a b c )], selectedIndex => 0, events => { List_RangeAdded => $listener, List_RangeRemoved => $listener, List_RangeChanged => $listener, List_Change => $listener, Selection_Change => $listener, }, ); $firstItemInList = $selectionInList->list->get(0); # 'a' $selectedIndex = $selectionInList->selectedIndex; # 0 $selectionInList->selectedItem('b'); # selection='b' $selectionInList->selection(Rui::Model::Value->new); # selection undefined $selectionInList->selectedIndex(1); # selection='b' $selectionInList->list->remove(1); # selection='a' $self->addBeforeSelection('foo'); # selection='foo' $self->addAfterSelection('bar'); # selection='bar' $self->removeSelection; # selection='foo' $selectionInList->list(Rui::Model::List->new); # selection undefined
the Rui::Model::Value manpage, the Rui::Model::List manpage
$event->index
is
the first index of change in the list, $event->size
is the number
of relevant elements. The selection in list propagates all list events.
A model of a list and a selection from it. Provides a simple interface for managing the list and the selection.
The selection is automatically changd when it has become invalid because of certain changes to the list. These list events can cause me to change the selection:
List_Change
will undefine the selection, as it is meaningless for the
new list.
List_RangeRemoved
if the selected item is removed, we will try to
select the previous item from the list. If there is no such item, we
select the first item in the list. If there is no such item, we undefine
the selection. This is for the default case, when isNavigating
is
true. When it is false, we simply undefine the selection.
List_RangeChanged
will undefine the selection if the selected item is
no longer in the list.
The selection is advanced to the new item when calling
addBefore/AfterSelection()
.