TypedGridView

Struct TypedGridView 

Source
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: GridView

The internal grid view.

§selection_model: S

The internal selection model.

Implementations§

Source§

impl<T, S> TypedGridView<T, S>

Source

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>

Source

pub fn new() -> Self

Create a new, empty TypedGridView.

Examples found in repository?
relm4/examples/message_from_grid_view.rs (line 150)
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
Hide additional examples
relm4/examples/typed_grid_view.rs (line 145)
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    }
Source

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?
relm4/examples/typed_grid_view.rs (line 148)
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    }
Source

pub fn filters_len(&self) -> usize

Returns the amount of filters that were added.

Source

pub fn set_filter_status(&mut self, idx: usize, active: bool) -> bool

Set a certain filter as active or inactive.

Examples found in repository?
relm4/examples/typed_grid_view.rs (line 149)
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    }
Source

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.

Source

pub fn pop_filter(&mut self)

Remove the last filter.

Source

pub fn clear_filters(&mut self)

Remove all filters.

Source

pub fn append(&mut self, value: T)

Add a new item at the end of the list.

Examples found in repository?
relm4/examples/message_from_grid_view.rs (line 165)
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
Hide additional examples
relm4/examples/typed_grid_view.rs (line 169)
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    }
Source

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.

Source

pub fn find<F: FnMut(&T) -> bool>(&self, equal_func: F) -> Option<u32>

Available on crate feature gnome_43 only.

Find the index of the first item that matches a certain function.

Source

pub fn is_empty(&self) -> bool

Returns true if the list is empty.

Source

pub fn len(&self) -> u32

Returns the length of the list (without filters).

Source

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?
relm4/examples/typed_grid_view.rs (line 177)
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    }
Source

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.

Source

pub fn insert(&mut self, position: u32, value: T)

Insert an item at a specific position.

Source

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.

Source

pub fn remove(&mut self, position: u32)

Remove an item at a specific position.

Examples found in repository?
relm4/examples/typed_grid_view.rs (line 184)
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    }
Source

pub fn clear(&mut self)

Remove all items.

Source

pub fn iter(&self) -> TypedIterator<'_, TypedGridView<T, S>>

Returns an iterator that allows modifying each TypedListItem.

Examples found in repository?
relm4/examples/typed_grid_view.rs (line 173)
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    }

Trait Implementations§

Source§

impl<T: Debug, S: Debug> Debug for TypedGridView<T, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, S> Default for TypedGridView<T, S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, S> Freeze for TypedGridView<T, S>
where S: Freeze,

§

impl<T, S> RefUnwindSafe for TypedGridView<T, S>

§

impl<T, S> !Send for TypedGridView<T, S>

§

impl<T, S> !Sync for TypedGridView<T, S>

§

impl<T, S> Unpin for TypedGridView<T, S>
where S: Unpin,

§

impl<T, S> UnwindSafe for TypedGridView<T, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<C> AsyncPosition<()> for C

Source§

fn position(_index: usize)

Returns the position. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<C, I> Position<(), I> for C

Source§

fn position(&self, _index: &I)

Returns the position. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more