Struct winsafe::gui::spec::ListViewItems

source ·
pub struct ListViewItems<'a, T: 'static> { /* private fields */ }
Available on crate feature gui only.
Expand description

Exposes item methods of a ListView control.

You cannot directly instantiate this object, it is created internally by the control.

Implementations§

source§

impl<'a, T> ListViewItems<'a, T>

source

pub fn add( &self, texts: &[impl AsRef<str>], icon_index: Option<u32>, data: T ) -> ListViewItem<'a, T>

Appends a new item by sending an lvm::InsertItem message, and returns the newly added item.

The texts are relative to each column.

§Panics

Panics if texts is empty, or if the number of texts is greater than the number of columns.

§Examples
use winsafe::{self as w, prelude::*, gui};

let my_list: gui::ListView; // initialized somewhere

let new_item = my_list.items().add(
    &[
        "First column text",
        "Second column text",
    ],
    None, // no icon; requires a previous set_image_list()
    (),   // no object data; requires specifying the generic `ListView` type
);
source

pub fn count(&self) -> u32

Retrieves the total number of items by sending an lvm::GetItemCount message.

source

pub fn delete_all(&self)

Deletes all items by sending an lvm::DeleteAllItems message.

source

pub fn delete_selected(&self)

Deletes all selected items by sending lvm::DeleteItem messages.

source

pub fn find(&self, text: &str) -> Option<ListViewItem<'a, T>>

Searches for an item with the given text, case-insensitive, by sending an lvm::FindItem message.

source

pub fn focused(&self) -> Option<ListViewItem<'a, T>>

Retrieves the focused item by sending an lvm::GetNextItem message.

source

pub const fn get(&self, index: u32) -> ListViewItem<'a, T>

Retrieves the item at the given zero-based position.

Note: This method is cheap – even if index is beyond the range of existing items, an object will still be returned. However, operations upon this object will produce no effect.

source

pub fn hit_test(&self, coords: POINT) -> Option<ListViewItem<'a, T>>

Retrieves the item at the specified position by sending an lvm::HitTest message.

coords must be relative to the list view.

source

pub fn iter(&self) -> impl Iterator<Item = ListViewItem<'a, T>> + 'a

Returns an iterator over all items.

§Examples
use winsafe::{self as w, prelude::*, gui};

let my_list: gui::ListView; // initialized somewhere

for item in my_list.items().iter() {
    println!("Item {}, text of the first column: {}",
        item.index(), item.text(0));
}
source

pub fn iter_selected(&self) -> impl Iterator<Item = ListViewItem<'a, T>> + 'a

Returns an iterator over the selected items.

§Examples
use winsafe::{self as w, prelude::*, gui};

let my_list: gui::ListView; // initialized somewhere

for item in my_list.items().iter_selected() {
    println!("Selected item {}, text of the first column: {}",
        item.index(), item.text(0));
}
source

pub fn map_id_to_index(&self, item_id: u32) -> ListViewItem<'a, T>

Retrieves the item of the unique ID by sending an lvm::MapIdToIndex message.

If the item of the given unique ID doesn’t exist anymore, returns None.

§Panics

Panics if the given ID doesn’t exist among the items.

source

pub fn select_all(&self, set: bool)

Sets or remove the selection for all items by sending an lvm::SetItemState message.

source

pub fn selected_count(&self) -> u32

Retrieves the number of selected items by sending an lvm::GetSelectedCount message.

source

pub fn set_count(&self, count: u32, behavior: Option<LVSICF>)

Sets the number of items in a virtual list view – that is, a list view created with LVS::OWNERDATA style – by sending an lvm::SetItemCount message.

source

pub fn sort<F>(&self, func: F)
where F: FnMut(ListViewItem<'_>, ListViewItem<'_>) -> Ordering,

Sorts the items according to a callback by sending an lvm::SortItemsEx message.

The callback receives the two items to be compared.

§Examples

Sorting by the text of the first column:

use winsafe::{self as w, prelude::*, gui};

let my_list: gui::ListView; // initialized somewhere

my_list.items().sort(|itemA, itemB| -> std::cmp::Ordering {
    itemA.text(0).cmp( &itemB.text(0) )
});

Auto Trait Implementations§

§

impl<'a, T> Freeze for ListViewItems<'a, T>

§

impl<'a, T> !RefUnwindSafe for ListViewItems<'a, T>

§

impl<'a, T> !Send for ListViewItems<'a, T>

§

impl<'a, T> !Sync for ListViewItems<'a, T>

§

impl<'a, T> Unpin for ListViewItems<'a, T>

§

impl<'a, T> !UnwindSafe for ListViewItems<'a, T>

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