Trait fungui::Extension

source ·
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§

The type of the data that will be stored on every node

Can be acccessed via the .ext field on NodeInner

The type of the extra Values that will be used to extend the fungui Value in ExtValue type.

This is normally an enum

Required Methods§

Creates a new empty NodeData to be stored on a Node.

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);
}

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
}

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§

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.

Implementors§