Crate float_pigment_layout

Source
Expand description

Layout engine with common CSS block and flexbox support.

Note: it is not a full web-compatible layout engine because it supports a subset of web layout algorithms.

Supported layout strategies:

  • display: block
  • display: flex
  • display: none
  • position: absolute
  • with an optional external text layout engine:
    • display: inline
    • display: inline-block
    • display: inline-flex

§Basic Usages

This crate does not construct node trees itself. You should firstly:

  • write a node tree struct that implements LayoutTreeNode, each node should owns a LayoutNode inside it;
  • or use the float-pigment-forest crate (the float_pigment_forest::node::Node is a good implementation).

Each tree node has a corresponding LayoutNode. Calls the Layoutnode::update or Layoutnode::update_with_containing_size of tree root node every time you need a new layout result. (The all results in the tree will be updated when Layoutnode::update* is called on the tree root.) Then you can read any result in any node with LayoutNode::result* and LayoutNode::computed_style.

When any property of any node has been updated, calls the LayoutNode::mark_dirty. The next Layoutnode::update* call on the tree root will carefully read the new properties and update the results.

§About Text Layout

Text layout means to compose text glyphs and other structures (images, inline-blocks, etc.) in lines. It is a complex problem and deeply coupled with system environment interfaces.

This crate does not solve text layout problems. Thus by default it does not support display: inline and similar features. However, you are informed the inline layout parts so that you can implement a text layout engine to handle them.

Structs§

ComputedStyle
The computed margin padding border width.
Edge
Four edge lengths.
EdgeOption
Four edge lengths, each edge can be undetermined.
InlineUnitMetadata
Inline unit with some metadata.
LayoutNode
The layout information of a tree node.
MeasureResult
The result of the measure function.
OptionNum
A number or undetermined.

Enums§

DefLength
A length type that can be undefined or auto.

Traits§

InlineMeasure
A helper type to measure inline nodes.
InlineUnit
A helper type as the inline form of a tree node.
LayoutStyle
The styles of a tree node.
LayoutTreeNode
The main tree node type.
LayoutTreeVisitor
A helper type for tree traversal.
ScreenQuery
A type to get screen size.

Functions§

is_independent_positioning
Returns if the node has a special position, e.g. display: none or position: absolute.

Type Aliases§

OptionSize
Size, but each value can be None for undetermined.
Point
Position.
Rect
Position with size.
Size
Size.
Vector
2D Vector.