Files
MapLibreParticleLab/include/mbgl/style/expression/format_expression.hpp
Alexander Shalamov 8be135231d [core] Add possibility of overriding paint properties inside format expression #14062
* [core] Add format override expression and formatted section to evaluation context

* [core] Add textColor to TaggedString's formatted section

* [core] Add FormatSectionOverrides and introduce overridable properties

* [core] Populate symbol layer paint properties for text sections

* [core] Add benchmark for style that uses text-color override

* [core] Add unit test for FormatOverrideExpression

* [core] Add unit test for FormatSectionOverrides
2019-03-13 17:14:53 +02:00

50 lines
1.7 KiB
C++

#pragma once
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/parsing_context.hpp>
namespace mbgl {
namespace style {
namespace expression {
struct FormatExpressionSection {
FormatExpressionSection(std::unique_ptr<Expression> text_,
optional<std::unique_ptr<Expression>> fontScale_,
optional<std::unique_ptr<Expression>> textFont_,
optional<std::unique_ptr<Expression>> textColor_);
std::shared_ptr<Expression> text;
optional<std::shared_ptr<Expression>> fontScale;
optional<std::shared_ptr<Expression>> textFont;
optional<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 mbgl::style::conversion::Convertible&, ParsingContext&);
void eachChild(const std::function<void(const Expression&)>&) const override;
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override {
// Technically the combinatoric set of all children
// Usually, this.text will be undefined anyway
return { nullopt };
}
const std::vector<FormatExpressionSection>& getSections() const { return sections; }
mbgl::Value serialize() const override;
std::string getOperator() const override { return "format"; }
private:
std::vector<FormatExpressionSection> sections;
};
} // namespace expression
} // namespace style
} // namespace mbgl