Commit d9834633 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

separate LayoutState and LayoutInfo

parent 9f261235
Loading
Loading
Loading
Loading
+21 −28
Original line number Diff line number Diff line
@@ -38,82 +38,75 @@ ReturnCode layout_compute(
    const LayoutSettings& config,
    double bbox_w,
    double bbox_h,
    LayoutState* parent_layout,
    LayoutState* layout) {
  layout->content_box = layout->bounding_box;
    LayoutState* state,
    Rectangle* bbox) {
  auto width = config.width;
  auto width_min = width.value_or(from_unit(bbox_w));
  auto width_max = width.value_or(from_unit(parent_layout->content_box.w));
  auto width_max = width.value_or(from_unit(state->content_box.w));

  auto height = config.height;
  auto height_min = height.value_or(from_unit(bbox_h));
  auto height_max = height.value_or(from_unit(parent_layout->content_box.h));
  auto height_max = height.value_or(from_unit(state->content_box.h));

  double extent[4] = {0, 0, 0, 0};
  switch (config.position) {

    case Position::RELATIVE:
      layout->bounding_box = Rectangle(
          parent_layout->content_box.x,
          parent_layout->content_box.y,
      *bbox = Rectangle(
          state->content_box.x,
          state->content_box.y,
          width_max,
          height_max);

      layout->content_box = layout->bounding_box;
      break;

    case Position::TOP: {
      layout->bounding_box = Rectangle(
          parent_layout->content_box.x,
          parent_layout->content_box.y,
      *bbox = Rectangle(
          state->content_box.x,
          state->content_box.y,
          width_max,
          height_min);

      layout->content_box = layout->bounding_box;
      extent[0] = height_min;
      break;
    }

    case Position::RIGHT: {
      layout->bounding_box = Rectangle(
          parent_layout->content_box.x + parent_layout->content_box.w - width_min,
          parent_layout->content_box.y,
      *bbox = Rectangle(
          state->content_box.x + state->content_box.w - width_min,
          state->content_box.y,
          width_min,
          height_max);

      layout->content_box = layout->bounding_box;
      extent[1] = width_min;
      break;
    }

    case Position::BOTTOM: {
      layout->bounding_box = Rectangle(
          parent_layout->content_box.x,
          parent_layout->content_box.y + parent_layout->content_box.h - height_min,
      *bbox = Rectangle(
          state->content_box.x,
          state->content_box.y + state->content_box.h - height_min,
          width_max,
          height_min);

      layout->content_box = layout->bounding_box;
      extent[2] = height_min;
      break;
    }

    case Position::LEFT: {
      layout->bounding_box = Rectangle(
          parent_layout->content_box.x,
          parent_layout->content_box.y,
      *bbox = Rectangle(
          state->content_box.x,
          state->content_box.y,
          width_min,
          height_max);

      layout->content_box = layout->bounding_box;
      extent[3] = width_min;
      break;
    }

  }

  parent_layout->content_box = layout_margin_box(
      parent_layout->content_box,
  state->content_box = layout_margin_box(
      state->content_box,
      extent[0],
      extent[1],
      extent[2],
+20 −6
Original line number Diff line number Diff line
@@ -40,11 +40,6 @@ namespace plotfx {

struct LayoutState {

  /**
   * The elements bounding box
   */
  Rectangle bounding_box;

  /**
   * If set to true, constrain the size of the bounding box in the (x, y)
   * dimension, i.e. disallow it from growing
@@ -74,12 +69,31 @@ struct LayoutSettings {
  std::optional<Measure> height;
};

struct LayoutInfo {

  /**
   * The outer bounding box
   */
  Rectangle bounding_box;

  /**
   * The elements bounding box
   */
  Rectangle content_box;

  /**
   * The inner bounding box
   */
  Rectangle inner_box;

};

ReturnCode layout_compute(
    const LayoutSettings& config,
    double bbox_w,
    double bbox_h,
    LayoutState* parent_layout,
    LayoutState* layout);
    Rectangle* bbox);

} // namespace plotfx
+3 −6
Original line number Diff line number Diff line
@@ -46,21 +46,18 @@ struct Environment;

using plist::PropertyList;

using ElementDrawFn = std::function<ReturnCode (const LayoutState&, Layer*)>;

template <typename T>
using ElementDrawAsFn = std::function<ReturnCode (const T&, const LayoutState&, Layer*)>;

template <typename T>
using ElementConfigureAsFn = std::function<ReturnCode (
    const plist::PropertyList&,
    const Environment&,
    T*)>;

using ElementDrawFn = std::function<ReturnCode (const LayoutInfo&, Layer*)>;

template <typename T>
using ElementDrawAsFn = std::function<ReturnCode (
    const T&,
    const LayoutState&,
    const LayoutInfo&,
    Layer*)>;

using ElementLayoutFn = std::function<ReturnCode (
+3 −3
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ PlotAreaConfig::PlotAreaConfig() :

ReturnCode draw_horizontal(
    PlotAreaConfig config,
    const LayoutState& layout,
    const LayoutInfo& layout,
    Layer* layer) {
  const auto& clip = layout.content_box;

@@ -126,7 +126,7 @@ ReturnCode draw_horizontal(

ReturnCode draw_vertical(
    PlotAreaConfig config,
    const LayoutState& layout,
    const LayoutInfo& layout,
    Layer* layer) {
  const auto& clip = layout.content_box;

@@ -213,7 +213,7 @@ ReturnCode layout(

ReturnCode draw(
    const PlotAreaConfig& config,
    const LayoutState& layout,
    const LayoutInfo& layout,
    Layer* layer) {
  switch (config.direction) {
    case Direction::HORIZONTAL:
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ struct PlotAreaConfig {

ReturnCode draw(
    const PlotAreaConfig& config,
    const LayoutState& layout,
    const LayoutInfo& layout,
    Layer* layer);

ReturnCode layout(
Loading