Commit 9f261235 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

compute the minimum element bounding box

parent 00ee229b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ ReturnCode environment_configure(
    return rc;
  }

  static const ParserDefinitions pdefs = {
  ParserDefinitions pdefs = {
    {"width", bind(&configure_measure, _1, &env->screen_width)},
    {"height", bind(&configure_measure, _1, &env->screen_height)},
  };
+4 −2
Original line number Diff line number Diff line
@@ -36,15 +36,17 @@ LayoutSettings::LayoutSettings() : position(Position::RELATIVE) {}

ReturnCode layout_compute(
    const LayoutSettings& config,
    double bbox_w,
    double bbox_h,
    LayoutState* parent_layout,
    LayoutState* layout) {
  layout->content_box = layout->bounding_box;
  auto width = config.width;
  auto width_min = width.value_or(from_unit(0));
  auto width_min = width.value_or(from_unit(bbox_w));
  auto width_max = width.value_or(from_unit(parent_layout->content_box.w));

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

  double extent[4] = {0, 0, 0, 0};
+2 −0
Original line number Diff line number Diff line
@@ -76,6 +76,8 @@ struct LayoutSettings {

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

+17 −3
Original line number Diff line number Diff line
@@ -58,12 +58,26 @@ using ElementConfigureAsFn = std::function<ReturnCode (
    T*)>;

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

using ElementLayoutFn = std::function<ReturnCode (const Layer&, LayoutState*)>;
using ElementLayoutFn = std::function<ReturnCode (
    const Layer&,
    const std::optional<double> max_width,
    const std::optional<double> max_height,
    double* min_width,
    double* min_height)>;

template <typename T>
using ElementLayoutAsFn = std::function<ReturnCode (const T&, const Layer&, LayoutState*)>;
using ElementLayoutAsFn = std::function<ReturnCode (
    const T&,
    const Layer&,
    const std::optional<double> max_width,
    const std::optional<double> max_height,
    double* min_width,
    double* min_height)>;

struct Element {
  virtual ~Element() = default;
+1 −1
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ ElementBuilder elem_builder(
      return rc;
    }

    e->layout = bind(layout_fn, e->config, _1, _2);
    e->layout = bind(layout_fn, e->config, _1, _2, _3, _4, _5);
    e->draw = bind(draw_fn, e->config, _1, _2);
    *elem = std::move(e);
    return OK;
Loading