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

add support for multiple root elements

parent 5217607d
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -50,6 +50,26 @@ ReturnCode element_build(
  return elem_iter->second(expr_next(expr), elem);
}

ReturnCode element_build_all(
    const ElementMap& factory,
    const Expr* expr,
    std::vector<ElementRef>* elems) {
  for (; expr; expr = expr_next(expr)) {
    if (!expr_is_list(expr)) {
      return ReturnCode::error("EARG", "expected an element list");
    }

    ElementRef elem;
    if (auto rc = element_build(factory, expr_get_list(expr), &elem); !rc) {
      return rc;
    }

    elems->emplace_back(std::move(elem));
  }

  return OK;
}

void element_bind(
    ElementMap* factory,
    const std::string& name,
+5 −0
Original line number Diff line number Diff line
@@ -44,6 +44,11 @@ ReturnCode element_build(
    const Expr* expr,
    ElementRef* elem);

ReturnCode element_build_all(
    const ElementMap& factory,
    const Expr* expr,
    std::vector<ElementRef>* elems);

void element_bind(
    ElementMap* factory,
    const std::string& name,
+11 −3
Original line number Diff line number Diff line
@@ -117,10 +117,18 @@ int plotfx_render_to(plotfx_t* ctx, void* backend) {
  //plot::PlotConfig root;
  //root.margins = {from_px(20), from_px(20), from_px(20), from_px(20)};

  ElementRef root;
  std::vector<ElementRef> roots;
  auto rc = try_chain({
    [&] { return element_build(ctx->elements, ctx->expr.get(), &root); },
    [&] { return root->draw(ctx->env, layer); },
    [&] { return element_build_all(ctx->elements, ctx->expr.get(), &roots); },
    [&] () -> ReturnCode {
      for (const auto& e : roots) {
        if (auto rc = e->draw(ctx->env, layer); !rc) {
          return rc;
        }
      }

      return OK;
    },
    [&] { return layer_submit(layer); },
  });