Commit 7f48decd authored by Paul Asmuth's avatar Paul Asmuth
Browse files

make Element::reflow optional

parent 02b28a3b
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ ReturnCode layout_elements(
    double bbox_w = 0.0;
    double bbox_h = 0.0;

    if (e.element->reflow) {
      if (auto rc =
            e.element->reflow(
                layer,
@@ -145,6 +146,7 @@ ReturnCode layout_elements(
            !rc.isSuccess()) {
        return rc;
      }
    }

    if (auto rc =
          layout_element(
+0 −6
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ static std::unordered_map<std::string, ElementBuilder> elems = {
    "areas",
    elem_builder<plot::area::PlotAreaConfig>(
        &plot::area::configure,
        &plot::area::reflow,
        &plot::area::draw)
  },
  {
@@ -60,21 +59,18 @@ static std::unordered_map<std::string, ElementBuilder> elems = {
    "bars",
    elem_builder<plot::bars::PlotBarsConfig>(
        &plot::bars::configure,
        &plot::bars::reflow,
        &plot::bars::draw)
  },
  {
    "box",
    elem_builder<box::BoxConfig>(
        &box::configure,
        &box::reflow,
        &box::draw)
  },
  {
    "gridlines",
    elem_builder<gridlines::GridlineDefinition>(
        &gridlines::configure,
        &gridlines::reflow,
        &gridlines::draw)
  },
  {
@@ -88,14 +84,12 @@ static std::unordered_map<std::string, ElementBuilder> elems = {
    "lines",
    elem_builder<plot::lines::PlotLinesConfig>(
        &plot::lines::configure,
        &plot::lines::reflow,
        &plot::lines::draw)
  },
  {
    "points",
    elem_builder<plot::points::PlotPointsConfig>(
        &plot::points::configure,
        &plot::points::reflow,
        &plot::points::draw)
  },
};
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,11 @@ using ElementBuilder = std::function<ReturnCode (
    const Environment&,
    ElementRef* elem)>;

template <typename T>
ElementBuilder elem_builder(
    ElementConfigureAsFn<T> config_fn,
    ElementDrawAsFn<T> draw_fn);

template <typename T>
ElementBuilder elem_builder(
    ElementConfigureAsFn<T> config_fn,
+11 −2
Original line number Diff line number Diff line
@@ -31,6 +31,13 @@

namespace plotfx {

template <typename T>
ElementBuilder elem_builder(
    ElementConfigureAsFn<T> config_fn,
    ElementDrawAsFn<T> draw_fn) {
  return elem_builder(config_fn, ElementReflowAsFn<T>(nullptr), draw_fn);
}

template <typename T>
ElementBuilder elem_builder(
    ElementConfigureAsFn<T> config_fn,
@@ -48,12 +55,14 @@ ElementBuilder elem_builder(
      return rc;
    }

    e->reflow = bind(reflow_fn, e->config, _1, _2, _3, _4, _5);
    e->draw = bind(draw_fn, e->config, _1, _2);
    e->reflow = reflow_fn ? 
        bind(reflow_fn, e->config, _1, _2, _3, _4, _5) :
        ElementReflowFn(nullptr);

    *elem = std::move(e);
    return OK;
  };

}

} // namespace plotfx
+0 −11
Original line number Diff line number Diff line
@@ -200,17 +200,6 @@ ReturnCode draw_vertical(
  return OK;
}

ReturnCode reflow(
    const PlotAreaConfig& config,
    const Layer& layer,
    const std::optional<double> max_width,
    const std::optional<double> max_height,
    double* min_width,
    double* min_height) {
  /* nothing to do */
  return OK;
}

ReturnCode draw(
    const PlotAreaConfig& config,
    const LayoutInfo& layout,
Loading