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,

source

pub fn new() -> Self

Create a new, empty TypedColumnView.

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

pub fn append_column<C>(&mut self)
where C: RelmColumn<Item = T>,

Append column to this typed view

Examples found in repository?
examples/typed_column_view.rs (line 150)
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 }
    }
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?
examples/typed_column_view.rs (line 155)
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 }
    }
source

pub fn get_columns(&self) -> &HashMap<&'static str, ColumnViewColumn>

Get columns currently associated with this view.

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?
examples/typed_column_view.rs (line 156)
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);
            }
        }
    }
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?
examples/typed_column_view.rs (line 176)
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);
            }
        }
    }
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?
examples/typed_column_view.rs (line 180)
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);
            }
        }
    }
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>(&self, value: T, compare_func: F) -> u32
where F: FnMut(&T, &T) -> Ordering,

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?
examples/typed_column_view.rs (line 187)
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);
            }
        }
    }
source

pub fn clear(&mut self)

Remove all items.

Trait Implementations§

source§

impl<T, S> Debug for TypedColumnView<T, S>
where T: Debug, S: Debug,

source§

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

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

impl<T, S> Default for TypedColumnView<T, S>
where T: Any, S: RelmSelectionExt,

source§

fn default() -> Self

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

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, S> UnwindSafe for TypedColumnView<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>,

§

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>,

§

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