[core] Add image sections to format expression

This commit is contained in:
Alexander Shalamov
2019-11-12 22:21:12 +02:00
parent 5e3ef2e9e0
commit a01ecc92a0
8 changed files with 153 additions and 94 deletions

View File

@@ -8,12 +8,16 @@ 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;
explicit FormatExpressionSection(std::unique_ptr<Expression> content_);
void setTextSectionOptions(optional<std::unique_ptr<Expression>> fontScale_,
optional<std::unique_ptr<Expression>> textFont_,
optional<std::unique_ptr<Expression>> textColor_);
// Content can be expression that evaluates to String or Image.
std::shared_ptr<Expression> content;
// Text related section options.
optional<std::shared_ptr<Expression>> fontScale;
optional<std::shared_ptr<Expression>> textFont;
optional<std::shared_ptr<Expression>> textColor;

View File

@@ -1,6 +1,7 @@
#pragma once
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/expression/image.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/optional.hpp>
@@ -17,17 +18,19 @@ extern const char* const kFormattedSectionTextFont;
extern const char* const kFormattedSectionTextColor;
struct FormattedSection {
FormattedSection(std::string text_,
optional<double> fontScale_,
optional<FontStack> fontStack_,
optional<Color> textColor_)
: text(std::move(text_))
, fontScale(std::move(fontScale_))
, fontStack(std::move(fontStack_))
, textColor(std::move(textColor_))
{}
explicit FormattedSection(std::string text_,
optional<double> fontScale_,
optional<FontStack> fontStack_,
optional<Color> textColor_)
: text(std::move(text_)),
fontScale(std::move(fontScale_)),
fontStack(std::move(fontStack_)),
textColor(std::move(textColor_)) {}
explicit FormattedSection(Image image_) : image(std::move(image_)) {}
std::string text;
optional<Image> image;
optional<double> fontScale;
optional<FontStack> fontStack;
optional<Color> textColor;
@@ -50,10 +53,8 @@ public:
std::string toString() const;
mbgl::Value toObject() const;
bool empty() const {
return sections.empty() || sections.at(0).text.empty();
}
bool empty() const;
std::vector<FormattedSection> sections;
};