Files
MapLibreParticleLab/include/mln/style/expression/format_expression.hpp
Bart Louwers 2a8ebc4906 core: rename mbgl directories to mln (#4511)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2026-08-22 20:50:14 +02:00

60 lines
1.9 KiB
C++

#pragma once
#include <mln/style/expression/expression.hpp>
#include <mln/style/expression/parsing_context.hpp>
namespace mln {
namespace style {
namespace expression {
struct FormatExpressionSection {
explicit FormatExpressionSection(std::unique_ptr<Expression> content_);
void setTextSectionOptions(std::unique_ptr<Expression>&& fontScale_,
std::unique_ptr<Expression>&& textFont_,
std::unique_ptr<Expression>&& textColor_);
// Content can be expression that evaluates to String or Image.
std::shared_ptr<Expression> content;
// Text related section options.
std::shared_ptr<Expression> fontScale;
std::shared_ptr<Expression> textFont;
std::shared_ptr<Expression> textColor;
};
class FormatExpression final : public Expression {
public:
explicit FormatExpression(std::vector<FormatExpressionSection> sections);
EvaluationResult evaluate(const EvaluationContext&) const override;
static ParseResult parse(const mln::style::conversion::Convertible&, ParsingContext&);
void eachChild(const std::function<void(const Expression&)>&) const override;
bool operator==(const Expression& e) const noexcept override;
std::vector<std::optional<Value>> possibleOutputs() const noexcept override {
// Technically the combinatoric set of all children
// Usually, this.text will be undefined anyway
return {std::nullopt};
}
const std::vector<FormatExpressionSection>& getSections() const noexcept { return sections; }
mln::Value serialize() const override;
std::string getOperator() const override { return "format"; }
private:
static Dependency depsOfSection(const FormatExpressionSection& s) {
return depsOf(s.content) | depsOf(s.fontScale) | depsOf(s.textFont) | depsOf(s.textColor);
}
private:
std::vector<FormatExpressionSection> sections;
};
} // namespace expression
} // namespace style
} // namespace mln