Commit 02b28a3b authored by Paul Asmuth's avatar Paul Asmuth
Browse files

rename Element::layout -> Element::reflow

parent a00d30d1
Loading
Loading
Loading
Loading
+4 −37
Original line number Diff line number Diff line
@@ -62,11 +62,11 @@ more complex than they are!
### Virtual Box Model

Each elements specifies its preferred 'placement'. The placement describes how
the element wishes to be placed with relation to a parent bounding box. It can
take the two values `LAYER` or `BLOCK`.
the element wishes to be placed with relation to a parent bounding box.

To understand what these values mean consider the following "virtual" box. The
virtual box is divided into concentric regions:
The placement parameter can take six different values with correspond to the six
(partially) overlapping sections of the parent bounding box shown in the illustration
below.

    [figure]

@@ -94,35 +94,6 @@ of the element tree. At each step all sibling elements are placed into the
bounding box of their parent element. Note that the placement process assumes
that an absolute document size is already known.

Let's first consider the simple case where the element tree has a depth of one,
i.e. it contains the virtual root node and a list of sibling elements which
descend from the root node.

The initial parent bounding box is by definition set to the size of the screen. To
find the bounding boxes for the elements, we first consider all children that
have requested BLOCK placement. For each element, we reserve a sub-region of
the current parent bounding box for the element and then remove the sub-region
from the parent bounding box. This is done in the order in which the block elements
were defined.

Once we have placed all BLOCK elements using this method, we simply copy the
remaining parent bounding box to children that have requested `LAYER` placement.

In other words:
  - Initialize the parent bounding box to the size of the parent element
  - For each element with block placement, subtract the element box from the
    parent bounding box
  - Once all block elements are placed, assign the remaining parent bounding
    box to all layer elements.

This process continues recursively for nested elements (i.e. elements that have
children). Note that while each element has to respect the layout rules described
above when placing its children it is free to use any parent bounding that is a
sub-region of it's own bounding box. It is also allowed to use a different parent
bounding box for each child element. This is required to implement layout container
elements such as `grid` or `legend`.


### Finding the document size

Illustrations usually have a fixed desired output size, so in most cases the
@@ -131,10 +102,6 @@ document size is simply defined by the user.
FIXME: describe how we come up with auto width/height


### Alignment with the inner bounding box



### Difference to CSS

Most readers will know CSS so it might be useful to point out the similarities
+1 −1
Original line number Diff line number Diff line
@@ -136,7 +136,7 @@ ReturnCode layout_elements(
    double bbox_h = 0.0;

    if (auto rc =
          e.element->layout(
          e.element->reflow(
              layer,
              layout_state.content_box.w,
              layout_state.content_box.h,
+3 −3
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ using ElementDrawAsFn = std::function<ReturnCode (
    const LayoutInfo&,
    Layer*)>;

using ElementLayoutFn = std::function<ReturnCode (
using ElementReflowFn = std::function<ReturnCode (
    const Layer&,
    const std::optional<double> max_width,
    const std::optional<double> max_height,
@@ -69,7 +69,7 @@ using ElementLayoutFn = std::function<ReturnCode (
    double* min_height)>;

template <typename T>
using ElementLayoutAsFn = std::function<ReturnCode (
using ElementReflowAsFn = std::function<ReturnCode (
    const T&,
    const Layer&,
    const std::optional<double> max_width,
@@ -81,7 +81,7 @@ struct Element {
  virtual ~Element() = default;
  virtual const LayoutSettings& layout_settings() const = 0;
  int32_t z_index() const;
  ElementLayoutFn layout;
  ElementReflowFn reflow;
  ElementDrawFn draw;
};

+8 −8
Original line number Diff line number Diff line
@@ -46,56 +46,56 @@ static std::unordered_map<std::string, ElementBuilder> elems = {
    "areas",
    elem_builder<plot::area::PlotAreaConfig>(
        &plot::area::configure,
        &plot::area::layout,
        &plot::area::reflow,
        &plot::area::draw)
  },
  {
    "axis",
    elem_builder<AxisDefinition>(
        &axis::configure,
        &axis::layout,
        &axis::reflow,
        &axis::draw)
  },
  {
    "bars",
    elem_builder<plot::bars::PlotBarsConfig>(
        &plot::bars::configure,
        &plot::bars::layout,
        &plot::bars::reflow,
        &plot::bars::draw)
  },
  {
    "box",
    elem_builder<box::BoxConfig>(
        &box::configure,
        &box::layout,
        &box::reflow,
        &box::draw)
  },
  {
    "gridlines",
    elem_builder<gridlines::GridlineDefinition>(
        &gridlines::configure,
        &gridlines::layout,
        &gridlines::reflow,
        &gridlines::draw)
  },
  {
    "legend",
    elem_builder<LegendConfig>(
        &legend::configure,
        &legend::layout,
        &legend::reflow,
        &legend::draw)
  },
  {
    "lines",
    elem_builder<plot::lines::PlotLinesConfig>(
        &plot::lines::configure,
        &plot::lines::layout,
        &plot::lines::reflow,
        &plot::lines::draw)
  },
  {
    "points",
    elem_builder<plot::points::PlotPointsConfig>(
        &plot::points::configure,
        &plot::points::layout,
        &plot::points::reflow,
        &plot::points::draw)
  },
};
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ using ElementBuilder = std::function<ReturnCode (
template <typename T>
ElementBuilder elem_builder(
    ElementConfigureAsFn<T> config_fn,
    ElementLayoutAsFn<T> layout_fn,
    ElementReflowAsFn<T> layout_fn,
    ElementDrawAsFn<T> draw_fn);

ReturnCode buildElement(
Loading