Struct nannou::ui::prelude::image::Map [−][src]
A type used to map the widget::Id
of Image
widgets to their associated Img
data.
The image::Map
type is usually instantiated and loaded during the "setup" stage of the
application before the main loop begins. A macro is provided to simplify the construction of
maps with multiple images.
let image_map = image_map! { (RUST_LOGO, image::open("rust-logo.png")?), (CAT_PIC, image::open("floof.jpeg")?), };
Fields
trigger_redraw: Cell<bool>
Whether or not the image::Map
will trigger a redraw the next time Ui::draw
is called.
This is automatically set to true
when any method that takes &mut self
is called.
Methods
impl<Img> Map<Img>
[src]
impl<Img> Map<Img>
pub fn new() -> Map<Img>
[src]
pub fn new() -> Map<Img>
Construct a new, empty image::Map
.
pub fn get_mut(&mut self, id: Id) -> Option<&mut Img>
[src]
pub fn get_mut(&mut self, id: Id) -> Option<&mut Img>
Uniquely borrow the Img
associated with the given widget.
Note: Calling this will trigger a redraw the next time Ui::draw_if_changed
is called.
pub fn insert(&mut self, img: Img) -> Id
[src]
pub fn insert(&mut self, img: Img) -> Id
Inserts the given image into the map, returning its associated image::Id
. The user must
store the returned image::Id
in order to use, modify or remove the inserted image.
Note: Calling this will trigger a redraw the next time Ui::draw_if_changed
is called.
pub fn replace(&mut self, id: Id, img: Img) -> Option<Img>
[src]
pub fn replace(&mut self, id: Id, img: Img) -> Option<Img>
Replaces the given image in the map if it exists. Returns the image or None.
Note: Calling this will trigger a redraw the next time Ui::draw_if_changed
is called.
pub fn remove(&mut self, id: Id) -> Option<Img>
[src]
pub fn remove(&mut self, id: Id) -> Option<Img>
Removes the given image from the map if it exists. Returns the image or None.
Any future use of the given image::Id
will be invalid.
Note: Calling this will trigger a redraw the next time Ui::draw_if_changed
is called.
ⓘImportant traits for NewIdspub fn extend<I>(&mut self, images: I) -> NewIds where
I: IntoIterator<Item = Img>,
[src]
pub fn extend<I>(&mut self, images: I) -> NewIds where
I: IntoIterator<Item = Img>,
Insert each of the images yielded by the given iterator and produce an iterator yielding
their generated Ids
in the same order.
Note: Calling this will trigger a redraw the next time Ui::draw_if_changed
is called.
Methods from Deref<Target = HashMap<Id, Img, BuildHasherDefault<FnvHasher>>>
ⓘImportant traits for &'a mut Rpub fn hasher(&self) -> &S
1.9.0[src]
pub fn hasher(&self) -> &S
Returns a reference to the map's BuildHasher
.
Examples
use std::collections::HashMap; use std::collections::hash_map::RandomState; let hasher = RandomState::new(); let map: HashMap<i32, i32> = HashMap::with_hasher(hasher); let hasher: &RandomState = map.hasher();
pub fn capacity(&self) -> usize
1.0.0[src]
pub fn capacity(&self) -> usize
Returns the number of elements the map can hold without reallocating.
This number is a lower bound; the HashMap<K, V>
might be able to hold
more, but is guaranteed to be able to hold at least this many.
Examples
use std::collections::HashMap; let map: HashMap<i32, i32> = HashMap::with_capacity(100); assert!(map.capacity() >= 100);
ⓘImportant traits for Keys<'a, K, V>pub fn keys(&self) -> Keys<K, V>
1.0.0[src]
pub fn keys(&self) -> Keys<K, V>
An iterator visiting all keys in arbitrary order.
The iterator element type is &'a K
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for key in map.keys() { println!("{}", key); }
ⓘImportant traits for Values<'a, K, V>pub fn values(&self) -> Values<K, V>
1.0.0[src]
pub fn values(&self) -> Values<K, V>
An iterator visiting all values in arbitrary order.
The iterator element type is &'a V
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for val in map.values() { println!("{}", val); }
ⓘImportant traits for Iter<'a, K, V>pub fn iter(&self) -> Iter<K, V>
1.0.0[src]
pub fn iter(&self) -> Iter<K, V>
An iterator visiting all key-value pairs in arbitrary order.
The iterator element type is (&'a K, &'a V)
.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert("a", 1); map.insert("b", 2); map.insert("c", 3); for (key, val) in map.iter() { println!("key: {} val: {}", key, val); }
pub fn len(&self) -> usize
1.0.0[src]
pub fn len(&self) -> usize
Returns the number of elements in the map.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert_eq!(a.len(), 0); a.insert(1, "a"); assert_eq!(a.len(), 1);
pub fn is_empty(&self) -> bool
1.0.0[src]
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
Examples
use std::collections::HashMap; let mut a = HashMap::new(); assert!(a.is_empty()); a.insert(1, "a"); assert!(!a.is_empty());
pub fn get<Q>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
pub fn get<Q>(&self, k: &Q) -> Option<&V> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get(&1), Some(&"a")); assert_eq!(map.get(&2), None);
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
[src]
pub fn get_key_value<Q>(&self, k: &Q) -> Option<(&K, &V)> where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
map_get_key_value
)Returns the key-value pair corresponding to the supplied key.
The supplied key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
#![feature(map_get_key_value)] use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.get_key_value(&1), Some((&1, &"a"))); assert_eq!(map.get_key_value(&2), None);
pub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
1.0.0[src]
pub fn contains_key<Q>(&self, k: &Q) -> bool where
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
Returns true if the map contains a value for the specified key.
The key may be any borrowed form of the map's key type, but
Hash
and Eq
on the borrowed form must match those for
the key type.
Examples
use std::collections::HashMap; let mut map = HashMap::new(); map.insert(1, "a"); assert_eq!(map.contains_key(&1), true); assert_eq!(map.contains_key(&2), false);