Skip to main content

ferroui_base/controls/
i_resource_node.rs

1use super::ResourceKey;
2use crate::styling::ThemeVariant;
3use crate::BoxedValue;
4
5/// The value of a resource. `None` is a resource that is present with a null
6/// value.
7pub type ResourceValue = Option<BoxedValue>;
8
9/// Represents a resource provider in a tree.
10pub trait IResourceNode {
11    /// Whether the resource node has resources.
12    fn has_resources(&self) -> bool;
13
14    /// Tries to find a resource within the node.
15    ///
16    /// Returns `Some` with the resource if it was found. See the theme
17    /// dictionaries of a resource dictionary for how `theme` is used.
18    fn try_get_resource(&self, key: &ResourceKey, theme: Option<&ThemeVariant>) -> Option<ResourceValue>;
19
20    /// The identity of the node, used for reference equality: the address
21    /// of the object the node is, whichever adapter it is seen through.
22    #[doc(hidden)]
23    fn reference_id(&self) -> *const () {
24        self as *const Self as *const ()
25    }
26}
27
28/// Handles compare by identity (reference equality): two handles are equal
29/// when they refer to the same object, whichever adapter they were made
30/// from.
31impl PartialEq for dyn IResourceNode {
32    #[inline]
33    fn eq(&self, other: &Self) -> bool {
34        self.reference_id() == other.reference_id()
35    }
36}