MapLibre Native Core
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
formatted.hpp
Go to the documentation of this file.
1 #pragma once
2 
5 #include <mbgl/util/color.hpp>
7 
8 #include <vector>
9 #include <string>
10 #include <optional>
11 
12 namespace mbgl {
13 namespace style {
14 namespace expression {
15 
16 extern const char* const kFormattedSectionFontScale;
17 extern const char* const kFormattedSectionTextFont;
18 extern const char* const kFormattedSectionTextColor;
19 
21  explicit FormattedSection(std::string text_,
22  std::optional<double> fontScale_,
23  std::optional<FontStack> fontStack_,
24  std::optional<Color> textColor_)
25  : text(std::move(text_)),
26  fontScale(std::move(fontScale_)),
27  fontStack(std::move(fontStack_)),
28  textColor(std::move(textColor_)) {}
29 
30  explicit FormattedSection(Image image_) : image(std::move(image_)) {}
31 
33  std::optional<Image> image;
34  std::optional<double> fontScale;
35  std::optional<FontStack> fontStack;
36  std::optional<Color> textColor;
37 };
38 
39 class Formatted {
40 public:
41  Formatted() = default;
42 
43  Formatted(const char* plainU8String) {
44  sections.emplace_back(std::string(plainU8String), std::nullopt, std::nullopt, std::nullopt);
45  }
46 
47  Formatted(std::vector<FormattedSection> sections_)
48  : sections(std::move(sections_))
49  {}
50 
51  bool operator==(const Formatted& ) const;
52 
55 
56  bool empty() const;
57 
58  std::vector<FormattedSection> sections;
59 };
60 
61 } // namespace expression
62 
63 namespace conversion {
64 
65 template <>
66 struct Converter<expression::Formatted> {
67 public:
68  std::optional<expression::Formatted> operator()(const Convertible& value, Error& error) const;
69 };
70 
71 template <>
72 struct ValueFactory<expression::Formatted> {
73  static Value make(const expression::Formatted& formatted) { return formatted.toObject(); }
74 };
75 
76 } // namespace conversion
77 
78 } // namespace style
79 } // namespace mbgl
bool operator==(const Formatted &) const
Formatted(const char *plainU8String)
Definition: formatted.hpp:43
Formatted(std::vector< FormattedSection > sections_)
Definition: formatted.hpp:47
std::vector< FormattedSection > sections
Definition: formatted.hpp:58
std::unique_ptr< Expression > error(std::string)
std::unique_ptr< Expression > string(std::unique_ptr< Expression >, std::unique_ptr< Expression > def=nullptr)
constexpr FormattedType Formatted
Definition: type.hpp:91
const char *const kFormattedSectionTextColor
const char *const kFormattedSectionFontScale
const char *const kFormattedSectionTextFont
Definition: actor.hpp:15
mapbox::base::Value Value
Definition: feature.hpp:11
Definition: tile_id.hpp:256
std::optional< expression::Formatted > operator()(const Convertible &value, Error &error) const
static Value make(const expression::Formatted &formatted)
Definition: formatted.hpp:73
std::optional< FontStack > fontStack
Definition: formatted.hpp:35
FormattedSection(std::string text_, std::optional< double > fontScale_, std::optional< FontStack > fontStack_, std::optional< Color > textColor_)
Definition: formatted.hpp:21