pub trait LayoutTreeNode: Sized {
type Length: LengthNum;
type LengthCustom: PartialEq;
type TreeVisitor: LayoutTreeVisitor<Self>;
type Style: LayoutStyle<Self::Length, Self::LengthCustom>;
type InlineUnit: InlineUnit<Self, Env = Self::Env>;
type InlineMeasure: InlineMeasure<Self, InlineUnit = Self::InlineUnit, Env = Self::Env>;
type Env: ScreenQuery<Self::Length>;
// Required methods
fn layout_node(&self) -> &LayoutNode<Self>;
fn tree_visitor(&self) -> &Self::TreeVisitor;
fn style(&self) -> &Self::Style;
fn resolve_custom_length(
&self,
custom: &Self::LengthCustom,
owner: Self::Length,
) -> Self::Length;
fn should_measure(&self, env: &mut Self::Env) -> bool;
fn measure_block_size(
&self,
env: &mut Self::Env,
req_size: OptionSize<Self::Length>,
min: Size<Self::Length>,
max: Size<Self::Length>,
max_content: OptionSize<Self::Length>,
update_position: bool,
) -> MeasureResult<Self::Length>;
fn measure_inline_unit(
&self,
env: &mut Self::Env,
req_size: OptionSize<Self::Length>,
min: Size<Self::Length>,
max: Size<Self::Length>,
max_content: OptionSize<Self::Length>,
) -> MeasureResult<Self::Length>;
// Provided method
fn size_updated(
&self,
_env: &mut Self::Env,
_size: Size<Self::Length>,
_computed_style: &ComputedStyle<Self::Length>,
) { ... }
}
Expand description
The main tree node type.
It should be implemented by a tree implementation and then the layout algorithms can run on it.
Required Associated Types§
Sourcetype Length: LengthNum
type Length: LengthNum
The main length type.
It can simply be an f32
.
Sometimes float-point is not accurate enough. You can use the fixed-point types provided by the fixed
crate.
Sourcetype LengthCustom: PartialEq
type LengthCustom: PartialEq
A custem length type used in DefLength::Custom
.
If you do not need it, simply use i32
.
Sourcetype TreeVisitor: LayoutTreeVisitor<Self>
type TreeVisitor: LayoutTreeVisitor<Self>
A helper type for tree traversal.
Hint: consider implement LayoutTreeVisitor
for Self
if the Self
type can do tree traversal.
Sourcetype Style: LayoutStyle<Self::Length, Self::LengthCustom>
type Style: LayoutStyle<Self::Length, Self::LengthCustom>
The layout styles of the current node.
Sourcetype InlineUnit: InlineUnit<Self, Env = Self::Env>
type InlineUnit: InlineUnit<Self, Env = Self::Env>
A helper type to represent the current node as an inline node.
This type is intended to be used in the text layout engine. You can write a void implementation if you do not need inline layout.
Sourcetype InlineMeasure: InlineMeasure<Self, InlineUnit = Self::InlineUnit, Env = Self::Env>
type InlineMeasure: InlineMeasure<Self, InlineUnit = Self::InlineUnit, Env = Self::Env>
A helper type to measure inline node.
This type is intended to be used in the text layout engine. You can write a void implementation if you do not need inline layout.
Sourcetype Env: ScreenQuery<Self::Length>
type Env: ScreenQuery<Self::Length>
Some custom environment data.
Required Methods§
Sourcefn layout_node(&self) -> &LayoutNode<Self>
fn layout_node(&self) -> &LayoutNode<Self>
Get a reference to the LayoutNode
of the current tree node.
Sourcefn tree_visitor(&self) -> &Self::TreeVisitor
fn tree_visitor(&self) -> &Self::TreeVisitor
Get a helper for tree traversal.
Sourcefn resolve_custom_length(
&self,
custom: &Self::LengthCustom,
owner: Self::Length,
) -> Self::Length
fn resolve_custom_length( &self, custom: &Self::LengthCustom, owner: Self::Length, ) -> Self::Length
Resolve a Length::Custom
value.
If you do not use Length::Custom
values, simply unreachable!()
.
Sourcefn should_measure(&self, env: &mut Self::Env) -> bool
fn should_measure(&self, env: &mut Self::Env) -> bool
Returns if the node is a “measure” node.
This means this node has a dedicated way to calculate its size (normally true
for leaf nodes).
For example, images has a natural width/height -
its size should be calculated from the image natural size.
In this case, the LayoutTreeNode::measure_block_size
will be called.
Sourcefn measure_block_size(
&self,
env: &mut Self::Env,
req_size: OptionSize<Self::Length>,
min: Size<Self::Length>,
max: Size<Self::Length>,
max_content: OptionSize<Self::Length>,
update_position: bool,
) -> MeasureResult<Self::Length>
fn measure_block_size( &self, env: &mut Self::Env, req_size: OptionSize<Self::Length>, min: Size<Self::Length>, max: Size<Self::Length>, max_content: OptionSize<Self::Length>, update_position: bool, ) -> MeasureResult<Self::Length>
Measure a size for the current tree node.
Only be called if the node is a “measure” node, a.k.a. LayoutTreeNode::should_measure
returns true
.
The env
is the one passed from the Layoutnode::update*
call.
If update_position
is set, then the returned result will be used as the new layout result.
Sourcefn measure_inline_unit(
&self,
env: &mut Self::Env,
req_size: OptionSize<Self::Length>,
min: Size<Self::Length>,
max: Size<Self::Length>,
max_content: OptionSize<Self::Length>,
) -> MeasureResult<Self::Length>
fn measure_inline_unit( &self, env: &mut Self::Env, req_size: OptionSize<Self::Length>, min: Size<Self::Length>, max: Size<Self::Length>, max_content: OptionSize<Self::Length>, ) -> MeasureResult<Self::Length>
Convert the current node to a Self::InlineUnit
.
The returned value will be passed to InlineMeasure::block_size
.
This is intended for the text layout engine.
Provided Methods§
Sourcefn size_updated(
&self,
_env: &mut Self::Env,
_size: Size<Self::Length>,
_computed_style: &ComputedStyle<Self::Length>,
)
fn size_updated( &self, _env: &mut Self::Env, _size: Size<Self::Length>, _computed_style: &ComputedStyle<Self::Length>, )
A notifier that the layout size of itself (or any node in the subtree) has been re-evaluated.
Note that the position is the combination of size and origin. This call indicates that the size may be changed and the origin is still undetermined.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.