1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 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 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
// This file was generated by gir (https://github.com/gtk-rs/gir) // from gir-files (https://github.com/gtk-rs/gir-files) // DO NOT EDIT use crate::ListModel; use glib::object::Cast; use glib::object::IsA; use glib::translate::*; use glib::StaticType; use glib::ToValue; use std::fmt; #[cfg(any(feature = "v2_64", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_64")))] use std::mem; glib::wrapper! { /// [`ListStore`][crate::ListStore] is a simple implementation of [`ListModel`][crate::ListModel] that stores all /// items in memory. /// /// It provides insertions, deletions, and lookups in logarithmic time /// with a fast path for the common case of iterating the list linearly. /// /// # Implements /// /// [`trait@glib::ObjectExt`], [`ListModelExt`][trait@crate::prelude::ListModelExt], [`ListStoreExtManual`][trait@crate::prelude::ListStoreExtManual] #[doc(alias = "GListStore")] pub struct ListStore(Object<ffi::GListStore, ffi::GListStoreClass>) @implements ListModel; match fn { type_ => || ffi::g_list_store_get_type(), } } impl ListStore { /// Creates a new [`ListStore`][crate::ListStore] with items of type `item_type`. `item_type` /// must be a subclass of [`glib::Object`][crate::glib::Object]. /// ## `item_type` /// the `GType` of items in the list /// /// # Returns /// /// a new [`ListStore`][crate::ListStore] #[doc(alias = "g_list_store_new")] pub fn new(item_type: glib::types::Type) -> ListStore { unsafe { from_glib_full(ffi::g_list_store_new(item_type.into_glib())) } } // rustdoc-stripper-ignore-next /// Creates a new builder-pattern struct instance to construct [`ListStore`] objects. /// /// This method returns an instance of [`ListStoreBuilder`] which can be used to create [`ListStore`] objects. pub fn builder() -> ListStoreBuilder { ListStoreBuilder::default() } /// Appends `item` to `self`. `item` must be of type `property::ListStore::item-type`. /// /// This function takes a ref on `item`. /// /// Use [`splice()`][Self::splice()] to append multiple items at the same time /// efficiently. /// ## `item` /// the new item #[doc(alias = "g_list_store_append")] pub fn append<P: IsA<glib::Object>>(&self, item: &P) { unsafe { ffi::g_list_store_append(self.to_glib_none().0, item.as_ref().to_glib_none().0); } } /// Looks up the given `item` in the list store by looping over the items until /// the first occurrence of `item`. If `item` was not found, then `position` will /// not be set, and this method will return [`false`]. /// /// If you need to compare the two items with a custom comparison function, use /// `g_list_store_find_with_equal_func()` with a custom `GEqualFunc` instead. /// ## `item` /// an item /// /// # Returns /// /// Whether `self` contains `item`. If it was found, `position` will be /// set to the position where `item` occurred for the first time. /// /// ## `position` /// the first position of `item`, if it was found. #[cfg(any(feature = "v2_64", feature = "dox"))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v2_64")))] #[doc(alias = "g_list_store_find")] pub fn find<P: IsA<glib::Object>>(&self, item: &P) -> Option<u32> { unsafe { let mut position = mem::MaybeUninit::uninit(); let ret = from_glib(ffi::g_list_store_find( self.to_glib_none().0, item.as_ref().to_glib_none().0, position.as_mut_ptr(), )); let position = position.assume_init(); if ret { Some(position) } else { None } } } //#[cfg(any(feature = "v2_64", feature = "dox"))] //#[cfg_attr(feature = "dox", doc(cfg(feature = "v2_64")))] //#[doc(alias = "g_list_store_find_with_equal_func")] //pub fn find_with_equal_func<P: IsA<glib::Object>>(&self, item: &P, equal_func: /*Unimplemented*/FnMut(/*Unimplemented*/Option<Fundamental: Pointer>, /*Unimplemented*/Option<Fundamental: Pointer>) -> bool) -> Option<u32> { // unsafe { TODO: call ffi:g_list_store_find_with_equal_func() } //} /// Inserts `item` into `self` at `position`. `item` must be of type /// `property::ListStore::item-type` or derived from it. `position` must be smaller /// than the length of the list, or equal to it to append. /// /// This function takes a ref on `item`. /// /// Use [`splice()`][Self::splice()] to insert multiple items at the same time /// efficiently. /// ## `position` /// the position at which to insert the new item /// ## `item` /// the new item #[doc(alias = "g_list_store_insert")] pub fn insert<P: IsA<glib::Object>>(&self, position: u32, item: &P) { unsafe { ffi::g_list_store_insert( self.to_glib_none().0, position, item.as_ref().to_glib_none().0, ); } } /// Removes the item from `self` that is at `position`. `position` must be /// smaller than the current length of the list. /// /// Use [`splice()`][Self::splice()] to remove multiple items at the same time /// efficiently. /// ## `position` /// the position of the item that is to be removed #[doc(alias = "g_list_store_remove")] pub fn remove(&self, position: u32) { unsafe { ffi::g_list_store_remove(self.to_glib_none().0, position); } } /// Removes all items from `self`. #[doc(alias = "g_list_store_remove_all")] pub fn remove_all(&self) { unsafe { ffi::g_list_store_remove_all(self.to_glib_none().0); } } /// Changes `self` by removing `n_removals` items and adding `n_additions` /// items to it. `additions` must contain `n_additions` items of type /// `property::ListStore::item-type`. [`None`] is not permitted. /// /// This function is more efficient than [`insert()`][Self::insert()] and /// [`remove()`][Self::remove()], because it only emits /// `signal::ListModel::items-changed` once for the change. /// /// This function takes a ref on each item in `additions`. /// /// The parameters `position` and `n_removals` must be correct (ie: /// `position` + `n_removals` must be less than or equal to the length of /// the list at the time this function is called). /// ## `position` /// the position at which to make the change /// ## `n_removals` /// the number of items to remove /// ## `additions` /// the items to add #[doc(alias = "g_list_store_splice")] pub fn splice(&self, position: u32, n_removals: u32, additions: &[glib::Object]) { let n_additions = additions.len() as u32; unsafe { ffi::g_list_store_splice( self.to_glib_none().0, position, n_removals, additions.to_glib_none().0, n_additions, ); } } } #[derive(Clone, Default)] // rustdoc-stripper-ignore-next /// A [builder-pattern] type to construct [`ListStore`] objects. /// /// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html pub struct ListStoreBuilder { item_type: Option<glib::types::Type>, } impl ListStoreBuilder { // rustdoc-stripper-ignore-next /// Create a new [`ListStoreBuilder`]. pub fn new() -> Self { Self::default() } // rustdoc-stripper-ignore-next /// Build the [`ListStore`]. pub fn build(self) -> ListStore { let mut properties: Vec<(&str, &dyn ToValue)> = vec![]; if let Some(ref item_type) = self.item_type { properties.push(("item-type", item_type)); } glib::Object::new::<ListStore>(&properties) .expect("Failed to create an instance of ListStore") } /// The type of items contained in this list store. Items must be /// subclasses of [`glib::Object`][crate::glib::Object]. pub fn item_type(mut self, item_type: glib::types::Type) -> Self { self.item_type = Some(item_type); self } } impl fmt::Display for ListStore { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("ListStore") } }