11// Explicit specializations for JSON conversion
22JSON_ENUM_MAPPER (CursorStyle)
33{
4- // Possible values for Cursor Shape
5- static constexpr std::string_view CursorShapeVintage{ " vintage" };
6- static constexpr std::string_view CursorShapeBar{ " bar" };
7- static constexpr std::string_view CursorShapeUnderscore{ " underscore" };
8- static constexpr std::string_view CursorShapeFilledbox{ " filledBox" };
9- static constexpr std::string_view CursorShapeEmptybox{ " emptyBox" };
10-
114 static constexpr std::array<pair_type, 5 > mappings = {
12- pair_type{ CursorShapeBar , CursorStyle::Bar },
13- pair_type{ CursorShapeVintage , CursorStyle::Vintage },
14- pair_type{ CursorShapeUnderscore , CursorStyle::Underscore },
15- pair_type{ CursorShapeFilledbox , CursorStyle::FilledBox },
16- pair_type{ CursorShapeEmptybox , CursorStyle::EmptyBox }
5+ pair_type{ " bar " , CursorStyle::Bar },
6+ pair_type{ " vintage " , CursorStyle::Vintage },
7+ pair_type{ " underscore " , CursorStyle::Underscore },
8+ pair_type{ " filledBox " , CursorStyle::FilledBox },
9+ pair_type{ " emptyBox " , CursorStyle::EmptyBox }
1710 };
1811};
1912
2013JSON_ENUM_MAPPER (Media::Stretch)
2114{
22- // Possible values for Image Stretch Mode
23- static constexpr std::string_view ImageStretchModeNone{ " none" };
24- static constexpr std::string_view ImageStretchModeFill{ " fill" };
25- static constexpr std::string_view ImageStretchModeUniform{ " uniform" };
26- static constexpr std::string_view ImageStretchModeUniformToFill{ " uniformToFill" };
27-
2815 static constexpr std::array<pair_type, 4 > mappings = {
29- pair_type{ ImageStretchModeUniformToFill , Media::Stretch::UniformToFill },
30- pair_type{ ImageStretchModeNone , Media::Stretch::None },
31- pair_type{ ImageStretchModeFill , Media::Stretch::Fill },
32- pair_type{ ImageStretchModeUniform , Media::Stretch::Uniform }
16+ pair_type{ " uniformToFill " , Media::Stretch::UniformToFill },
17+ pair_type{ " none " , Media::Stretch::None },
18+ pair_type{ " fill " , Media::Stretch::Fill },
19+ pair_type{ " uniform " , Media::Stretch::Uniform }
3320 };
3421};
3522
3623JSON_ENUM_MAPPER (ScrollbarState)
3724{
38- // Possible values for Scrollbar state
39- static constexpr std::string_view AlwaysVisible{ " visible" };
40- static constexpr std::string_view AlwaysHide{ " hidden" };
41-
4225 static constexpr std::array<pair_type, 2 > mappings = {
43- pair_type{ AlwaysVisible , ScrollbarState::Visible },
44- pair_type{ AlwaysHide , ScrollbarState::Hidden }
26+ pair_type{ " visible " , ScrollbarState::Visible },
27+ pair_type{ " hidden " , ScrollbarState::Hidden }
4528 };
4629};
4730
4831JSON_ENUM_MAPPER (std::tuple<HorizontalAlignment, VerticalAlignment>)
4932{
50- // Possible values for Image Alignment
51- static constexpr std::string_view ImageAlignmentCenter{ " center" };
52- static constexpr std::string_view ImageAlignmentLeft{ " left" };
53- static constexpr std::string_view ImageAlignmentTop{ " top" };
54- static constexpr std::string_view ImageAlignmentRight{ " right" };
55- static constexpr std::string_view ImageAlignmentBottom{ " bottom" };
56- static constexpr std::string_view ImageAlignmentTopLeft{ " topLeft" };
57- static constexpr std::string_view ImageAlignmentTopRight{ " topRight" };
58- static constexpr std::string_view ImageAlignmentBottomLeft{ " bottomLeft" };
59- static constexpr std::string_view ImageAlignmentBottomRight{ " bottomRight" };
60-
6133 static constexpr std::array<pair_type, 9 > mappings = {
62- pair_type{ ImageAlignmentCenter , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Center) },
63- pair_type{ ImageAlignmentTopLeft , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Top) },
64- pair_type{ ImageAlignmentBottomLeft , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Bottom) },
65- pair_type{ ImageAlignmentLeft , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Center) },
66- pair_type{ ImageAlignmentTopRight , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Top) },
67- pair_type{ ImageAlignmentBottomRight , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Bottom) },
68- pair_type{ ImageAlignmentRight , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Center) },
69- pair_type{ ImageAlignmentTop , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Top) },
70- pair_type{ ImageAlignmentBottom , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Bottom) }
34+ pair_type{ " center " , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Center) },
35+ pair_type{ " topLeft " , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Top) },
36+ pair_type{ " bottomLeft " , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Bottom) },
37+ pair_type{ " left " , std::make_tuple (HorizontalAlignment::Left, VerticalAlignment::Center) },
38+ pair_type{ " topRight " , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Top) },
39+ pair_type{ " bottomRight " , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Bottom) },
40+ pair_type{ " right " , std::make_tuple (HorizontalAlignment::Right, VerticalAlignment::Center) },
41+ pair_type{ " top " , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Top) },
42+ pair_type{ " bottom " , std::make_tuple (HorizontalAlignment::Center, VerticalAlignment::Bottom) }
7143 };
7244};
7345
7446JSON_ENUM_MAPPER (TextAntialiasingMode)
7547{
76- // Possible values for TextAntialiasingMode
77- static constexpr std::string_view AntialiasingModeGrayscale{ " grayscale" };
78- static constexpr std::string_view AntialiasingModeCleartype{ " cleartype" };
79- static constexpr std::string_view AntialiasingModeAliased{ " aliased" };
80-
8148 static constexpr std::array<pair_type, 3 > mappings = {
82- pair_type{ AntialiasingModeGrayscale , TextAntialiasingMode::Grayscale },
83- pair_type{ AntialiasingModeCleartype , TextAntialiasingMode::Cleartype },
84- pair_type{ AntialiasingModeAliased , TextAntialiasingMode::Aliased }
49+ pair_type{ " grayscale " , TextAntialiasingMode::Grayscale },
50+ pair_type{ " cleartype " , TextAntialiasingMode::Cleartype },
51+ pair_type{ " aliased " , TextAntialiasingMode::Aliased }
8552 };
8653};
8754
@@ -93,15 +60,10 @@ JSON_ENUM_MAPPER(TextAntialiasingMode)
9360// - The corresponding enum value which maps to the string provided by the user
9461JSON_ENUM_MAPPER (CloseOnExitMode)
9562{
96- // Possible values for closeOnExit
97- static constexpr std::string_view CloseOnExitAlways{ " always" };
98- static constexpr std::string_view CloseOnExitGraceful{ " graceful" };
99- static constexpr std::string_view CloseOnExitNever{ " never" };
100-
10163 JSON_MAPPINGS (3 ) = {
102- pair_type{ CloseOnExitAlways , CloseOnExitMode::Always },
103- pair_type{ CloseOnExitGraceful , CloseOnExitMode::Graceful },
104- pair_type{ CloseOnExitNever , CloseOnExitMode::Never },
64+ pair_type{ " always " , CloseOnExitMode::Always },
65+ pair_type{ " graceful " , CloseOnExitMode::Graceful },
66+ pair_type{ " never " , CloseOnExitMode::Never },
10567 };
10668
10769 // Override mapping parser to add boolean parsing
@@ -120,36 +82,26 @@ JSON_ENUM_MAPPER(CloseOnExitMode)
12082 }
12183};
12284
85+ // This specialization isn't using JSON_ENUM_MAPPER because we need to have a different
86+ // value type (unsinged int) and return type (FontWeight struct). JSON_ENUM_MAPPER
87+ // expects that the value type _is_ the return type.
12388template <>
12489struct JsonUtils ::ConversionTrait<winrt::Windows::UI::Text::FontWeight> : public JsonUtils::EnumMapper<unsigned int , JsonUtils::ConversionTrait<winrt::Windows::UI::Text::FontWeight>>
12590{
126- // Possible values for Font Weight
127- static constexpr std::string_view FontWeightThin{ " thin" };
128- static constexpr std::string_view FontWeightExtraLight{ " extra-light" };
129- static constexpr std::string_view FontWeightLight{ " light" };
130- static constexpr std::string_view FontWeightSemiLight{ " semi-light" };
131- static constexpr std::string_view FontWeightNormal{ " normal" };
132- static constexpr std::string_view FontWeightMedium{ " medium" };
133- static constexpr std::string_view FontWeightSemiBold{ " semi-bold" };
134- static constexpr std::string_view FontWeightBold{ " bold" };
135- static constexpr std::string_view FontWeightExtraBold{ " extra-bold" };
136- static constexpr std::string_view FontWeightBlack{ " black" };
137- static constexpr std::string_view FontWeightExtraBlack{ " extra-black" };
138-
13991 // The original parser used the font weight getters Bold(), Normal(), etc.
14092 // They were both ugly and *not constant expressions*
14193 JSON_MAPPINGS (11 ) = {
142- pair_type{ FontWeightThin , 100u },
143- pair_type{ FontWeightExtraLight , 200u },
144- pair_type{ FontWeightLight , 300u },
145- pair_type{ FontWeightSemiLight , 350u },
146- pair_type{ FontWeightNormal , 400u },
147- pair_type{ FontWeightMedium , 500u },
148- pair_type{ FontWeightSemiBold , 600u },
149- pair_type{ FontWeightBold , 700u },
150- pair_type{ FontWeightExtraBold , 800u },
151- pair_type{ FontWeightBlack , 900u },
152- pair_type{ FontWeightExtraBlack , 950u },
94+ pair_type{ " thin " , 100u },
95+ pair_type{ " extra-light " , 200u },
96+ pair_type{ " light " , 300u },
97+ pair_type{ " semi-light " , 350u },
98+ pair_type{ " normal " , 400u },
99+ pair_type{ " medium " , 500u },
100+ pair_type{ " semi-bold " , 600u },
101+ pair_type{ " bold " , 700u },
102+ pair_type{ " extra-bold " , 800u },
103+ pair_type{ " black " , 900u },
104+ pair_type{ " extra-black " , 950u },
153105 };
154106
155107 // Override mapping parser to add boolean parsing
@@ -162,7 +114,7 @@ struct JsonUtils::ConversionTrait<winrt::Windows::UI::Text::FontWeight> : public
162114 }
163115 else
164116 {
165- value = EnumMapper ::FromJson (json);
117+ value = BaseEnumMapper ::FromJson (json);
166118 }
167119
168120 winrt::Windows::UI::Text::FontWeight weight{
@@ -173,6 +125,6 @@ struct JsonUtils::ConversionTrait<winrt::Windows::UI::Text::FontWeight> : public
173125
174126 bool CanConvert (const Json::Value& json)
175127 {
176- return EnumMapper ::CanConvert (json) || json.isUInt ();
128+ return BaseEnumMapper ::CanConvert (json) || json.isUInt ();
177129 }
178130};
0 commit comments