Struct relm4::typed_view::column::TypedColumnView
source · pub struct TypedColumnView<T, S> {
pub view: ColumnView,
pub selection_model: S,
/* private fields */
}
Expand description
A high-level wrapper around gio::ListStore
,
gtk::SignalListItemFactory
and gtk::ColumnView
.
TypedColumnView
aims at keeping nearly the same functionality and
flexibility of the raw bindings while introducing a more idiomatic
and type-safe interface.
Fields§
§view: ColumnView
The internal list view.
selection_model: S
The internal selection model.
Implementations§
source§impl<T, S> TypedColumnView<T, S>where
T: Any,
S: RelmSelectionExt,
impl<T, S> TypedColumnView<T, S>where
T: Any,
S: RelmSelectionExt,
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new, empty TypedColumnView
.
Examples found in repository?
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// Initialize the ListView wrapper
let mut view_wrapper = TypedColumnView::<MyListItem, gtk::SingleSelection>::new();
view_wrapper.append_column::<Label1Column>();
view_wrapper.append_column::<Label2Column>();
view_wrapper.append_column::<ButtonColumn>();
// Add a filter and disable it
view_wrapper.add_filter(|item| item.value % 2 == 0);
view_wrapper.set_filter_status(0, false);
let model = App {
counter,
view_wrapper,
};
let my_view = &model.view_wrapper.view;
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn append_column<C>(&mut self)where
C: RelmColumn<Item = T>,
pub fn append_column<C>(&mut self)where
C: RelmColumn<Item = T>,
Append column to this typed view
Examples found in repository?
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// Initialize the ListView wrapper
let mut view_wrapper = TypedColumnView::<MyListItem, gtk::SingleSelection>::new();
view_wrapper.append_column::<Label1Column>();
view_wrapper.append_column::<Label2Column>();
view_wrapper.append_column::<ButtonColumn>();
// Add a filter and disable it
view_wrapper.add_filter(|item| item.value % 2 == 0);
view_wrapper.set_filter_status(0, false);
let model = App {
counter,
view_wrapper,
};
let my_view = &model.view_wrapper.view;
let widgets = view_output!();
ComponentParts { model, widgets }
}
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?
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// Initialize the ListView wrapper
let mut view_wrapper = TypedColumnView::<MyListItem, gtk::SingleSelection>::new();
view_wrapper.append_column::<Label1Column>();
view_wrapper.append_column::<Label2Column>();
view_wrapper.append_column::<ButtonColumn>();
// Add a filter and disable it
view_wrapper.add_filter(|item| item.value % 2 == 0);
view_wrapper.set_filter_status(0, false);
let model = App {
counter,
view_wrapper,
};
let my_view = &model.view_wrapper.view;
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn get_columns(&self) -> &HashMap<&'static str, ColumnViewColumn>
pub fn get_columns(&self) -> &HashMap<&'static str, ColumnViewColumn>
Get columns currently associated with this view.
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?
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn init(
counter: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
// Initialize the ListView wrapper
let mut view_wrapper = TypedColumnView::<MyListItem, gtk::SingleSelection>::new();
view_wrapper.append_column::<Label1Column>();
view_wrapper.append_column::<Label2Column>();
view_wrapper.append_column::<ButtonColumn>();
// Add a filter and disable it
view_wrapper.add_filter(|item| item.value % 2 == 0);
view_wrapper.set_filter_status(0, false);
let model = App {
counter,
view_wrapper,
};
let my_view = &model.view_wrapper.view;
let widgets = view_output!();
ComponentParts { model, widgets }
}
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.view_wrapper.set_filter_status(0, show_only_even);
}
}
}
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?
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.view_wrapper.set_filter_status(0, show_only_even);
}
}
}
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?
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.view_wrapper.set_filter_status(0, show_only_even);
}
}
}
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>(&self, value: T, compare_func: F) -> u32
pub fn insert_sorted<F>(&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?
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
fn update(&mut self, msg: Self::Input, _sender: ComponentSender<Self>) {
match msg {
Msg::Append => {
// Add 10 items
for _ in 0..10 {
self.counter = self.counter.wrapping_add(1);
self.view_wrapper.append(MyListItem::new(self.counter));
}
// Count up the first item
let first_item = self.view_wrapper.get(0).unwrap();
let first_binding = &mut first_item.borrow_mut().binding;
let mut guard = first_binding.guard();
*guard += 1;
}
Msg::Remove => {
// Remove the second item
self.view_wrapper.remove(1);
}
Msg::OnlyShowEven(show_only_even) => {
// Disable or enable the first filter
self.view_wrapper.set_filter_status(0, show_only_even);
}
}
}