summaryrefslogtreecommitdiff
path: root/test/text
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-10-30 11:06:59 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-11-17 15:13:38 -0800
commit38fcbe21d48186c4630a3b8a76d1b20e156faadd (patch)
tree098f73bfea98deb5202fe1c13b1277e43e322755 /test/text
parentd4fc66af3924805d40576989c1e139ddafcc4670 (diff)
downloadqtlocation-mapboxgl-38fcbe21d48186c4630a3b8a76d1b20e156faadd.tar.gz
[core] Convert style properties to a tuple-based approach
This converts the style property classes (CirclePaintProperties and so on) to the same tuple-based approach as gl::Attribute and gl::Uniform. The approach is outlined in https://github.com/mapbox/cpp/blob/master/C%2B%2B%20Structural%20Metaprogramming.md. The main advantage of this approach is it allows writing algorithms that work on sets of style properties, without resorting to code generation or manually repetitive code. This lets us iterate on approaches to data-driven properties more easily. Another advantage is that the cascading, unevaluated, and evaluated states of a set of properties exist as independent structures, instead of individual properties holding their own state. This is a more functional approach that makes data flow clearer and reduces state.
Diffstat (limited to 'test/text')
-rw-r--r--test/text/quads.test.cpp96
1 files changed, 48 insertions, 48 deletions
diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp
index 421d2f362d..c20218a82f 100644
--- a/test/text/quads.test.cpp
+++ b/test/text/quads.test.cpp
@@ -10,7 +10,7 @@ using namespace mbgl;
using namespace mbgl::style;
TEST(getIconQuads, normal) {
- SymbolLayoutProperties layout;
+ SymbolLayoutProperties::Evaluated layout;
Anchor anchor(2.0, 3.0, 0.0, 0.5f, 0);
SpriteAtlasElement image = {
Rect<uint16_t>( 0, 0, 15, 11 ),
@@ -58,7 +58,7 @@ TEST(getIconQuads, style) {
// none
{
- SymbolLayoutProperties layout;
+ SymbolLayoutProperties::Evaluated layout;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -80,9 +80,9 @@ TEST(getIconQuads, style) {
// width
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(24.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 24.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Width;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -98,9 +98,9 @@ TEST(getIconQuads, style) {
// width x textSize
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Width;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -116,13 +116,13 @@ TEST(getIconQuads, style) {
// width x textSize + padding
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Width);
- layout.iconTextFitPadding.value[0] = 5.0f;
- layout.iconTextFitPadding.value[1] = 10.0f;
- layout.iconTextFitPadding.value[2] = 5.0f;
- layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Width;
+ layout.get<IconTextFitPadding>()[0] = 5.0f;
+ layout.get<IconTextFitPadding>()[1] = 10.0f;
+ layout.get<IconTextFitPadding>()[2] = 5.0f;
+ layout.get<IconTextFitPadding>()[3] = 10.0f;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -138,9 +138,9 @@ TEST(getIconQuads, style) {
// height
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(24.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 24.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Height;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -156,9 +156,9 @@ TEST(getIconQuads, style) {
// height x textSize
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Height;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -174,13 +174,13 @@ TEST(getIconQuads, style) {
// height x textSize + padding
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Height);
- layout.iconTextFitPadding.value[0] = 5.0f;
- layout.iconTextFitPadding.value[1] = 10.0f;
- layout.iconTextFitPadding.value[2] = 5.0f;
- layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Height;
+ layout.get<IconTextFitPadding>()[0] = 5.0f;
+ layout.get<IconTextFitPadding>()[1] = 10.0f;
+ layout.get<IconTextFitPadding>()[2] = 5.0f;
+ layout.get<IconTextFitPadding>()[3] = 10.0f;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -196,9 +196,9 @@ TEST(getIconQuads, style) {
// both
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(24.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 24.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Both;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -214,9 +214,9 @@ TEST(getIconQuads, style) {
// both x textSize
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Both;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -232,13 +232,13 @@ TEST(getIconQuads, style) {
// both x textSize + padding
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- layout.iconTextFitPadding.value[0] = 5.0f;
- layout.iconTextFitPadding.value[1] = 10.0f;
- layout.iconTextFitPadding.value[2] = 5.0f;
- layout.iconTextFitPadding.value[3] = 10.0f;
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Both;
+ layout.get<IconTextFitPadding>()[0] = 5.0f;
+ layout.get<IconTextFitPadding>()[1] = 10.0f;
+ layout.get<IconTextFitPadding>()[2] = 5.0f;
+ layout.get<IconTextFitPadding>()[3] = 10.0f;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);
@@ -254,13 +254,13 @@ TEST(getIconQuads, style) {
// both x textSize + padding t/r/b/l
{
- SymbolLayoutProperties layout;
- layout.textSize = LayoutProperty<float>(12.0f);
- layout.iconTextFit = LayoutProperty<IconTextFitType>(IconTextFitType::Both);
- layout.iconTextFitPadding.value[0] = 0.0f;
- layout.iconTextFitPadding.value[1] = 5.0f;
- layout.iconTextFitPadding.value[2] = 10.0f;
- layout.iconTextFitPadding.value[3] = 15.0f;
+ SymbolLayoutProperties::Evaluated layout;
+ layout.get<TextSize>() = 12.0f;
+ layout.get<IconTextFit>() = IconTextFitType::Both;
+ layout.get<IconTextFitPadding>()[0] = 0.0f;
+ layout.get<IconTextFitPadding>()[1] = 5.0f;
+ layout.get<IconTextFitPadding>()[2] = 10.0f;
+ layout.get<IconTextFitPadding>()[3] = 15.0f;
SymbolQuads quads =
getIconQuads(anchor, shapedIcon, line, layout, SymbolPlacementType::Point, shapedText);