[−][src]Trait gtk_liststore_item::ListStoreItem
A trait to ease interraction with a ListStore using an intermediate struct.
If we want to interact with a table defined this way:
number | name | type |
---|---|---|
0 | name | gchararray |
1 | value | guint32 |
We can create a struct that represent the columns in the order that they appear, and then implement this trait to interact with the table's entries.
Automatic implementation
use gtk::prelude::*; use gtk_liststore_item::ListStoreItem; #[derive(ListStoreItem)] struct Item { name: String, value: u32, }
Manual implementation
use gtk::prelude::*; use gtk_liststore_item::ListStoreItem; struct Item { name: String, value: u32, } impl ListStoreItem for Item { fn from_liststore_iter<S>(list_store: S, iter: >k::TreeIter) -> Option<Self> where S: TreeModelExt { Some(Item { name: list_store.get_value(&iter, 0).get::<String>().ok()??, value: list_store.get_value(&iter, 1).get::<u32>().ok()??, }) } // from_liststore_path is already implemented to call from_liststore_iter fn insert_into_liststore<S>(&self, list_store: S) -> gtk::TreeIter where S: GtkListStoreExtManual { list_store.insert_with_values( None, &[0, 1], &[&self.name, &self.value]) } }
Required methods
fn from_liststore_iter<S>(list_store: S, iter: &TreeIter) -> Option<Self> where
S: TreeModelExt,
Self: Sized,
S: TreeModelExt,
Self: Sized,
fn insert_into_liststore<S>(&self, list_store: S) -> TreeIter where
S: GtkListStoreExtManual,
S: GtkListStoreExtManual,
Instert an item into a ListStore
as a new entry.
Provided methods
fn from_liststore_path<S>(list_store: S, tp: &TreePath) -> Option<Self> where
S: TreeModelExt,
Self: Sized,
S: TreeModelExt,
Self: Sized,
Construct an item from a ListStore
and a TreePath
.
The ListStore
is where the data is stored, and the TreePath
is a pointer to the
location of the data in the table.