1- use std:: { collections:: HashSet , fmt, iter :: FromIterator } ;
1+ use std:: { collections:: HashSet , fmt} ;
22
33use crate :: { core:: listbox:: Listbox , grapheme:: StyledGraphemes } ;
44
@@ -16,20 +16,23 @@ pub struct Checkbox {
1616 picked : HashSet < usize > ,
1717}
1818
19- impl < T : fmt:: Display > FromIterator < T > for Checkbox {
20- /// Creates a `Checkbox` from an iterator of items
21- /// that implement the `Display` trait.
22- /// Each item is added to the listbox,
23- /// and the set of picked indices is initialized as empty.
24- fn from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> Self {
19+ impl Checkbox {
20+ /// Creates a new `Checkbox` from a vector of `fmt::Display`.
21+ pub fn from_displayable < E : fmt:: Display , I : IntoIterator < Item = E > > ( items : I ) -> Self {
2522 Self {
26- listbox : Listbox :: from_iter ( iter) ,
23+ listbox : Listbox :: from_displayable ( items) ,
24+ picked : HashSet :: new ( ) ,
25+ }
26+ }
27+
28+ /// Creates a new `Checkbox` from a vector of `StyledGraphemes`.
29+ pub fn from_styled_graphemes ( items : Vec < StyledGraphemes > ) -> Self {
30+ Self {
31+ listbox : Listbox :: from_styled_graphemes ( items) ,
2732 picked : HashSet :: new ( ) ,
2833 }
2934 }
30- }
3135
32- impl Checkbox {
3336 /// Creates a `Checkbox` from an iterator of tuples where the first element
3437 /// implements the `Display` trait and the second element is a bool indicating
3538 /// if the item is picked (selected).
@@ -61,7 +64,7 @@ impl Checkbox {
6164 . collect :: < HashSet < usize > > ( ) ;
6265
6366 Self {
64- listbox : Listbox :: from_iter ( listbox_items) ,
67+ listbox : Listbox :: from_displayable ( listbox_items) ,
6568 picked : picked_indices,
6669 }
6770 }
0 commit comments