pub trait Extension {
type NodeData: Sized;
type Value: Clone + PartialEq + Sized;
fn new_data() -> Self::NodeData;
fn style_properties<'a, F>(prop: F)
where
F: FnMut(StaticKey) + 'a;
fn update_data(
styles: &Styles<Self>,
nc: &NodeChain<'_, Self>,
rule: &Rule<Self>,
data: &mut Self::NodeData
) -> DirtyFlags
where
Self: Sized;
fn reset_unset_data(
used_keys: &FnvHashSet<StaticKey>,
data: &mut Self::NodeData
) -> DirtyFlags;
fn check_flags(_data: &mut Self::NodeData, _flags: DirtyFlags) { ... }
}
Expand description
Extensions extend stylish to allow custom style properties to be added
Required Associated Types§
Required Methods§
sourcefn style_properties<'a, F>(prop: F)where
F: FnMut(StaticKey) + 'a,
fn style_properties<'a, F>(prop: F)where
F: FnMut(StaticKey) + 'a,
Called to add new style keys that can be used by style rules
Example
static MY_PROP: StaticKey = StaticKey("my_prop");
// ...
fn style_properties<'a, F>(mut prop: F)
where F: FnMut(StaticKey) + 'a
{
prop(MY_PROP);
}
sourcefn update_data(
styles: &Styles<Self>,
nc: &NodeChain<'_, Self>,
rule: &Rule<Self>,
data: &mut Self::NodeData
) -> DirtyFlagswhere
Self: Sized,
fn update_data(
styles: &Styles<Self>,
nc: &NodeChain<'_, Self>,
rule: &Rule<Self>,
data: &mut Self::NodeData
) -> DirtyFlagswhere
Self: Sized,
Called to apply a given style rule on a node
Its recomended to use the eval!
macro to check for relevant properties
as it also skips ones that have already been set by a another rule.
Example
fn update_child_data(&mut self, styles: &Styles<E>, nc: &NodeChain<E>, rule: &Rule<E>, data: &mut Self::ChildData) -> DirtyFlags {
let mut flags = DirtyFlags::empty();
eval!(styles, nc, rule.X => val => {
let new = val.convert();
if data.x != new {
data.x = new;
flags |= DirtyFlags::POSITION;
}
});
flags
}
sourcefn reset_unset_data(
used_keys: &FnvHashSet<StaticKey>,
data: &mut Self::NodeData
) -> DirtyFlags
fn reset_unset_data(
used_keys: &FnvHashSet<StaticKey>,
data: &mut Self::NodeData
) -> DirtyFlags
Called after applying all relevant rules to reset any properties that weren’t set.
This is needed because a node could have a property set previously and
then later (e.g. when a property is changed) no longer have it set.
Due to it no longer being set update_data
would not be called for
that property leaving it stuck with its previous value.
used_keys
will contain every property key that was used by rules
in this update, if the key isn’t in this set it should be reset.
Provided Methods§
sourcefn check_flags(_data: &mut Self::NodeData, _flags: DirtyFlags)
fn check_flags(_data: &mut Self::NodeData, _flags: DirtyFlags)
Called with the flags of a node to allow the data to be updated based on the dirty state of the node.
This is useful to marking a node as needing a redraw when it moves.