Trait fungui::LayoutEngine
source · pub trait LayoutEngine<E>where
E: Extension,{
type ChildData: 'static;
Show 13 methods
fn name() -> &'static str;
fn style_properties<'a, F>(prop: F)
where
F: FnMut(StaticKey) + 'a;
fn new_child_data() -> Self::ChildData;
fn update_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>
) -> DirtyFlags { ... }
fn update_child_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>,
_data: &mut Self::ChildData
) -> DirtyFlags { ... }
fn reset_unset_data(
&mut self,
_used_keys: &FnvHashSet<StaticKey>
) -> DirtyFlags { ... }
fn reset_unset_child_data(
&mut self,
_used_keys: &FnvHashSet<StaticKey>,
_data: &mut Self::ChildData
) -> DirtyFlags { ... }
fn check_parent_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags { ... }
fn check_child_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags { ... }
fn start_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect { ... }
fn do_layout(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect { ... }
fn do_layout_end(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect { ... }
fn finish_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect { ... }
}
Expand description
Used to position an element within another element.
The order of method calls during layout is as followed
parent_layout.do_layout(...);
current_layout.start_layout(...);
for child in children {
current_layout.do_layout(...);
child_layout.start_layout(...);
// repeat for children
child_layout.finish_layout(...);
current_layout.do_layout_end(...);
}
current_layout.finish_layout(...);
parent_layout.do_layout_end(...);
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 register the properties used by the layout.
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 new_child_data() -> Self::ChildData
fn new_child_data() -> Self::ChildData
Creates a new child data to be stored on a node
Provided Methods§
sourcefn update_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>
) -> DirtyFlags
fn update_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>
) -> DirtyFlags
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_data(&mut self, styles: &Styles<E>, nc: &NodeChain<E>, rule: &Rule<E>) -> DirtyFlags {
let mut flags = DirtyFlags::empty();
eval!(styles, nc, rule.X => val => {
let new = val.convert();
if self.x != new {
self.x = new;
flags |= DirtyFlags::POSITION;
}
});
flags
}
sourcefn update_child_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>,
_data: &mut Self::ChildData
) -> DirtyFlags
fn update_child_data(
&mut self,
_styles: &Styles<E>,
_nc: &NodeChain<'_, E>,
_rule: &Rule<E>,
_data: &mut Self::ChildData
) -> DirtyFlags
Called to apply a given style rule on a child 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(&mut self, _used_keys: &FnvHashSet<StaticKey>) -> DirtyFlags
fn reset_unset_data(&mut self, _used_keys: &FnvHashSet<StaticKey>) -> 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.
sourcefn reset_unset_child_data(
&mut self,
_used_keys: &FnvHashSet<StaticKey>,
_data: &mut Self::ChildData
) -> DirtyFlags
fn reset_unset_child_data(
&mut self,
_used_keys: &FnvHashSet<StaticKey>,
_data: &mut Self::ChildData
) -> DirtyFlags
Called after applying all relevant rules to a child 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.
sourcefn check_parent_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags
fn check_parent_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags
Called to check the parent node’s dirty flags to update its own dirty flags
sourcefn check_child_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags
fn check_child_flags(&mut self, _flags: DirtyFlags) -> DirtyFlags
Called to check the child nodes’ dirty flags to update its own dirty flags
sourcefn start_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect
fn start_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect
Begins the layout for this node
Called after the parent node’s layout has called its do_layout
method
sourcefn do_layout(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect
fn do_layout(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect
Begins the layout for a child node of this layout
Called before the child node’s layout’s start_layout
method
sourcefn do_layout_end(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect
fn do_layout_end(
&mut self,
_value: &NodeValue<E>,
_ext: &mut E::NodeData,
_data: &mut Self::ChildData,
current: Rect,
_flags: DirtyFlags
) -> Rect
Ends the layout for this child node
Called after all the child nodes have had their layout called
sourcefn finish_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect
fn finish_layout(
&mut self,
_ext: &mut E::NodeData,
current: Rect,
_flags: DirtyFlags,
_children: ChildAccess<'_, Self, E>
) -> Rect
Ends the layout for this node
Called after all the child nodes have had do_layout(_end)
called