pub struct TypedGridView<T, S> {
pub view: GridView,
pub selection_model: S,
/* private fields */
}Expand description
A high-level wrapper around gio::ListStore,
gtk::SignalListItemFactory and gtk::GridView.
TypedGridView aims at keeping nearly the same functionality and
flexibility of the raw bindings while introducing a more idiomatic
and type-safe interface.
Fields§
§view: GridViewThe internal grid view.
selection_model: SThe internal selection model.
Implementations§
Source§impl<T, S> TypedGridView<T, S>
impl<T, S> TypedGridView<T, S>
Sourcepub fn with_sorting() -> Self
pub fn with_sorting() -> Self
Create a new TypedGridView that sorts the items
based on the Ord trait.
Source§impl<T, S> TypedGridView<T, S>where
T: RelmGridItem,
S: RelmSelectionExt,
impl<T, S> TypedGridView<T, S>where
T: RelmGridItem,
S: RelmSelectionExt,
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty TypedGridView.
Examples found in repository?
144 fn init(
145 _: Self::Init,
146 root: Self::Root,
147 sender: ComponentSender<Self>,
148 ) -> ComponentParts<Self> {
149 // Initialize the GridView
150 let grid_view: TypedGridView<MyGridItem, gtk::NoSelection> = TypedGridView::new();
151
152 let model = App { grid_view };
153
154 let my_view = &model.grid_view.view;
155
156 let widgets = view_output!();
157
158 ComponentParts { model, widgets }
159 }More examples
138 fn init(
139 counter: Self::Init,
140 root: Self::Root,
141 sender: ComponentSender<Self>,
142 ) -> ComponentParts<Self> {
143 // Initialize the GridView wrapper
144 let mut grid_view_wrapper: TypedGridView<MyGridItem, gtk::SingleSelection> =
145 TypedGridView::new();
146
147 // Add a filter and disable it
148 grid_view_wrapper.add_filter(|item| item.value % 2 == 0);
149 grid_view_wrapper.set_filter_status(0, false);
150
151 let model = App {
152 counter,
153 grid_view_wrapper,
154 };
155
156 let my_view = &model.grid_view_wrapper.view;
157
158 let widgets = view_output!();
159
160 ComponentParts { model, widgets }
161 }Sourcepub fn add_filter<F: Fn(&T) -> bool + 'static>(&mut self, f: F)
pub fn add_filter<F: Fn(&T) -> bool + 'static>(&mut self, f: F)
Add a function to filter the stored items.
Returning false will simply hide the item.
Note that several filters can be added on top of each other.
Examples found in repository?
138 fn init(
139 counter: Self::Init,
140 root: Self::Root,
141 sender: ComponentSender<Self>,
142 ) -> ComponentParts<Self> {
143 // Initialize the GridView wrapper
144 let mut grid_view_wrapper: TypedGridView<MyGridItem, gtk::SingleSelection> =
145 TypedGridView::new();
146
147 // Add a filter and disable it
148 grid_view_wrapper.add_filter(|item| item.value % 2 == 0);
149 grid_view_wrapper.set_filter_status(0, false);
150
151 let model = App {
152 counter,
153 grid_view_wrapper,
154 };
155
156 let my_view = &model.grid_view_wrapper.view;
157
158 let widgets = view_output!();
159
160 ComponentParts { model, widgets }
161 }Sourcepub fn filters_len(&self) -> usize
pub fn filters_len(&self) -> usize
Returns the amount of filters that were added.
Sourcepub fn set_filter_status(&mut self, idx: usize, active: bool) -> bool
pub fn set_filter_status(&mut self, idx: usize, active: bool) -> bool
Set a certain filter as active or inactive.
Examples found in repository?
138 fn init(
139 counter: Self::Init,
140 root: Self::Root,
141 sender: ComponentSender<Self>,
142 ) -> ComponentParts<Self> {
143 // Initialize the GridView wrapper
144 let mut grid_view_wrapper: TypedGridView<MyGridItem, gtk::SingleSelection> =
145 TypedGridView::new();
146
147 // Add a filter and disable it
148 grid_view_wrapper.add_filter(|item| item.value % 2 == 0);
149 grid_view_wrapper.set_filter_status(0, false);
150
151 let model = App {
152 counter,
153 grid_view_wrapper,
154 };
155
156 let my_view = &model.grid_view_wrapper.view;
157
158 let widgets = view_output!();
159
160 ComponentParts { model, widgets }
161 }
162
163 fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164 match msg {
165 Msg::Append => {
166 // Add 10 items
167 for _ in 0..10 {
168 self.counter = self.counter.wrapping_add(1);
169 self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170 }
171
172 self.grid_view_wrapper
173 .iter()
174 .for_each(|row| println!("item {}", row.borrow().value));
175
176 // Count up the first item
177 let first_item = self.grid_view_wrapper.get(0).unwrap();
178 let first_binding = &mut first_item.borrow_mut().binding;
179 let mut guard = first_binding.guard();
180 *guard += 1;
181 }
182 Msg::Remove => {
183 // Remove the second item
184 self.grid_view_wrapper.remove(1);
185 }
186 Msg::OnlyShowEven(show_only_even) => {
187 // Disable or enable the first filter
188 self.grid_view_wrapper.set_filter_status(0, show_only_even);
189 }
190 }
191 }Sourcepub fn notify_filter_changed(&self, idx: usize) -> bool
pub fn notify_filter_changed(&self, idx: usize) -> bool
Notify that a certain filter has changed. This causes the filter expression to be re-evaluated.
Returns true if a filter was notified.
Sourcepub fn pop_filter(&mut self)
pub fn pop_filter(&mut self)
Remove the last filter.
Sourcepub fn clear_filters(&mut self)
pub fn clear_filters(&mut self)
Remove all filters.
Sourcepub fn append(&mut self, value: T)
pub fn append(&mut self, value: T)
Add a new item at the end of the list.
Examples found in repository?
161 fn update(&mut self, msg: Self::Input, sender: ComponentSender<Self>) {
162 match msg {
163 Msg::Add => {
164 for _ in 0..10 {
165 self.grid_view.append(MyGridItem::new(sender.clone()));
166 }
167 }
168 Msg::Print(name) => {
169 println!("Name: {:?}", name)
170 }
171 }
172 }More examples
163 fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164 match msg {
165 Msg::Append => {
166 // Add 10 items
167 for _ in 0..10 {
168 self.counter = self.counter.wrapping_add(1);
169 self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170 }
171
172 self.grid_view_wrapper
173 .iter()
174 .for_each(|row| println!("item {}", row.borrow().value));
175
176 // Count up the first item
177 let first_item = self.grid_view_wrapper.get(0).unwrap();
178 let first_binding = &mut first_item.borrow_mut().binding;
179 let mut guard = first_binding.guard();
180 *guard += 1;
181 }
182 Msg::Remove => {
183 // Remove the second item
184 self.grid_view_wrapper.remove(1);
185 }
186 Msg::OnlyShowEven(show_only_even) => {
187 // Disable or enable the first filter
188 self.grid_view_wrapper.set_filter_status(0, show_only_even);
189 }
190 }
191 }Sourcepub fn extend_from_iter<I: IntoIterator<Item = T>>(&mut self, init: I)
pub fn extend_from_iter<I: IntoIterator<Item = T>>(&mut self, init: I)
Add new items from an iterator the the end of the list.
Sourcepub fn find<F: FnMut(&T) -> bool>(&self, equal_func: F) -> Option<u32>
Available on crate feature gnome_43 only.
pub fn find<F: FnMut(&T) -> bool>(&self, equal_func: F) -> Option<u32>
gnome_43 only.Find the index of the first item that matches a certain function.
Sourcepub fn get(&self, position: u32) -> Option<TypedListItem<T>>
pub fn get(&self, position: u32) -> Option<TypedListItem<T>>
Get the TypedListItem at the specified position.
Returns None if the position is invalid.
Examples found in repository?
163 fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164 match msg {
165 Msg::Append => {
166 // Add 10 items
167 for _ in 0..10 {
168 self.counter = self.counter.wrapping_add(1);
169 self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170 }
171
172 self.grid_view_wrapper
173 .iter()
174 .for_each(|row| println!("item {}", row.borrow().value));
175
176 // Count up the first item
177 let first_item = self.grid_view_wrapper.get(0).unwrap();
178 let first_binding = &mut first_item.borrow_mut().binding;
179 let mut guard = first_binding.guard();
180 *guard += 1;
181 }
182 Msg::Remove => {
183 // Remove the second item
184 self.grid_view_wrapper.remove(1);
185 }
186 Msg::OnlyShowEven(show_only_even) => {
187 // Disable or enable the first filter
188 self.grid_view_wrapper.set_filter_status(0, show_only_even);
189 }
190 }
191 }Sourcepub fn get_visible(&self, position: u32) -> Option<TypedListItem<T>>
pub fn get_visible(&self, position: u32) -> Option<TypedListItem<T>>
Get the visible TypedListItem at the specified position,
(the item at the given position after filtering and sorting).
Returns None if the position is invalid.
Sourcepub fn insert_sorted<F: FnMut(&T, &T) -> Ordering>(
&self,
value: T,
compare_func: F,
) -> u32
pub fn insert_sorted<F: FnMut(&T, &T) -> Ordering>( &self, value: T, compare_func: F, ) -> u32
Insert an item into the list and calculate its position from a sorting function.
Sourcepub fn remove(&mut self, position: u32)
pub fn remove(&mut self, position: u32)
Remove an item at a specific position.
Examples found in repository?
163 fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164 match msg {
165 Msg::Append => {
166 // Add 10 items
167 for _ in 0..10 {
168 self.counter = self.counter.wrapping_add(1);
169 self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170 }
171
172 self.grid_view_wrapper
173 .iter()
174 .for_each(|row| println!("item {}", row.borrow().value));
175
176 // Count up the first item
177 let first_item = self.grid_view_wrapper.get(0).unwrap();
178 let first_binding = &mut first_item.borrow_mut().binding;
179 let mut guard = first_binding.guard();
180 *guard += 1;
181 }
182 Msg::Remove => {
183 // Remove the second item
184 self.grid_view_wrapper.remove(1);
185 }
186 Msg::OnlyShowEven(show_only_even) => {
187 // Disable or enable the first filter
188 self.grid_view_wrapper.set_filter_status(0, show_only_even);
189 }
190 }
191 }Sourcepub fn iter(&self) -> TypedIterator<'_, TypedGridView<T, S>> ⓘ
pub fn iter(&self) -> TypedIterator<'_, TypedGridView<T, S>> ⓘ
Returns an iterator that allows modifying each TypedListItem.
Examples found in repository?
163 fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
164 match msg {
165 Msg::Append => {
166 // Add 10 items
167 for _ in 0..10 {
168 self.counter = self.counter.wrapping_add(1);
169 self.grid_view_wrapper.append(MyGridItem::new(self.counter));
170 }
171
172 self.grid_view_wrapper
173 .iter()
174 .for_each(|row| println!("item {}", row.borrow().value));
175
176 // Count up the first item
177 let first_item = self.grid_view_wrapper.get(0).unwrap();
178 let first_binding = &mut first_item.borrow_mut().binding;
179 let mut guard = first_binding.guard();
180 *guard += 1;
181 }
182 Msg::Remove => {
183 // Remove the second item
184 self.grid_view_wrapper.remove(1);
185 }
186 Msg::OnlyShowEven(show_only_even) => {
187 // Disable or enable the first filter
188 self.grid_view_wrapper.set_filter_status(0, show_only_even);
189 }
190 }
191 }