[−][src]Struct druid::Env
An environment passed down through all widget traversals.
All widget methods have access to an environment, and it is passed downwards during traversals.
A widget can retrieve theme parameters (colors, dimensions, etc.). In addition, it can pass custom data down to all descendants. An important example of the latter is setting a value for enabled/disabled status so that an entire subtree can be disabled ("grayed out") with one setting.
EnvScope
can be used to override parts of Env
for its descendants.
Important
It is the programmer's responsibility to ensure that the environment
is used correctly. See Key
for an example.
Implementations
impl Env
[src]
pub const DEBUG_WIDGET: Key<bool>
[src]
A key used to tell widgets to print additional debug information.
This does nothing by default; however you can check this key while debugging a widget to limit println spam.
For convenience, this key can be set with the WidgetExt::debug_widget
method.
Examples
if env.get(Env::DEBUG_WIDGET) { eprintln!("widget {:?} bounds: {:?}", widget_id, my_rect); }
pub fn get<'a, V: ValueType<'a>>(&'a self, key: impl Borrow<Key<V>>) -> V
[src]
Gets a value from the environment, expecting it to be present.
Note that the return value is a reference for "expensive" types such as strings, but an ordinary value for "cheap" types such as numbers and colors.
Panics
Panics if the key is not found, or if it is present with the wrong type.
pub fn try_get<'a, V: ValueType<'a>>(
&'a self,
key: impl Borrow<Key<V>>
) -> Option<V>
[src]
&'a self,
key: impl Borrow<Key<V>>
) -> Option<V>
Gets a value from the environment.
Panics
Panics if the value for the key is found, but has the wrong type.
pub fn get_untyped(&self, key: impl Borrow<Key<()>>) -> &Value
[src]
Gets a value from the environment, in its encapsulated Value
form,
expecting the key to be present.
WARNING: This is not intended for general use, but only for inspecting an Env
e.g.
for debugging, theme editing, and theme loading.
Panics
Panics if the key is not found
Value
: enum.Value.html
pub fn try_get_untyped(&self, key: impl Borrow<Key<()>>) -> Option<&Value>
[src]
Gets a value from the environment, in its encapsulated Value
form,
returning None if a value isn't found.
WARNING: This is not intended for general use, but only for inspecting an Env
e.g.
for debugging, theme editing, and theme loading.
Value
: enum.Value.html
pub fn get_all(&self) -> impl ExactSizeIterator<Item = (&String, &Value)>
[src]
Gets the entire contents of the Env
, in key-value pairs.
WARNING: This is not intended for general use, but only for inspecting an Env
e.g.
for debugging, theme editing, and theme loading.
pub fn adding<'a, V: ValueType<'a>>(
self,
key: Key<V>,
value: impl Into<V::Owned>
) -> Env
[src]
self,
key: Key<V>,
value: impl Into<V::Owned>
) -> Env
Adds a key/value, acting like a builder.
pub fn set<'a, V: ValueType<'a>>(
&'a mut self,
key: Key<V>,
value: impl Into<V::Owned>
)
[src]
&'a mut self,
key: Key<V>,
value: impl Into<V::Owned>
)
Sets a value in an environment.
Panics
Panics if the environment already has a value for the key, but it is of a different type.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Env
impl !Send for Env
impl !Sync for Env
impl Unpin for Env
impl !UnwindSafe for Env
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,