forked from maplibre/maplibre-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add array support for icon-padding (maplibre#2845)
- Loading branch information
1 parent
58dd529
commit 9d553c2
Showing
56 changed files
with
902 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#pragma once | ||
|
||
#include <mbgl/util/feature.hpp> | ||
#include <array> | ||
#include <span> | ||
|
||
namespace mbgl { | ||
|
||
// A set of four numbers representing padding around a box. | ||
struct Padding { | ||
// Empty/zero padding on all sides. | ||
Padding() = default; | ||
|
||
// Same padding on all sides. | ||
Padding(float value) | ||
: top(value), | ||
right(value), | ||
bottom(value), | ||
left(value) {} | ||
|
||
Padding(float t_, float r_, float b_, float l_) | ||
: top(t_), | ||
right(r_), | ||
bottom(b_), | ||
left(l_) {} | ||
|
||
// Padding values are in CSS order: top, right, bottom, left. | ||
Padding(const std::span<const float>& values) { | ||
switch (values.size()) { | ||
case 1: | ||
top = right = bottom = left = values[0]; | ||
break; | ||
case 2: | ||
top = bottom = values[0]; | ||
right = left = values[1]; | ||
break; | ||
case 3: | ||
top = values[0]; | ||
left = right = values[1]; | ||
bottom = values[2]; | ||
break; | ||
case 4: | ||
top = values[0]; | ||
right = values[1]; | ||
bottom = values[2]; | ||
left = values[3]; | ||
break; | ||
default: | ||
throw std::invalid_argument("Padding must have between 1 and 4 elements"); | ||
} | ||
} | ||
|
||
float top = 0; | ||
float right = 0; | ||
float bottom = 0; | ||
float left = 0; | ||
|
||
explicit operator bool() const { return top != 0 || right != 0 || bottom != 0 || left != 0; } | ||
|
||
bool operator==(const Padding&) const = default; | ||
|
||
std::array<float, 4> toArray() const; | ||
|
||
// Used by ValueFactory<Padding>::make() | ||
mbgl::Value serialize() const; | ||
}; | ||
|
||
inline Padding operator*(const Padding& padding, float scale) { | ||
return {padding.top * scale, padding.right * scale, padding.bottom * scale, padding.left * scale}; | ||
} | ||
|
||
} // namespace mbgl |
Binary file added
BIN
+3.04 KB
metrics/integration/render-tests/icon-padding/databind/expected-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
metrics/integration/render-tests/icon-padding/databind/style.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"collisionDebug": true, | ||
"width": 240, | ||
"height": 100 | ||
} | ||
}, | ||
"sources": { | ||
"geojson": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"properties": { }, | ||
"geometry": { "type": "Point", "coordinates": [-60, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { "padding": 5 }, | ||
"geometry": { "type": "Point", "coordinates": [-30, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { "padding": [-20, -5] }, | ||
"geometry": { "type": "Point", "coordinates": [-0, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { "padding": [2, 2, -10] }, | ||
"geometry": { "type": "Point", "coordinates": [30, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { "padding": [2, 10, -20, 2] }, | ||
"geometry": { "type": "Point", "coordinates": [60, 0] } | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"sprite": "local://sprites/2x", | ||
"layers": [{ | ||
"id": "bg", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "#ccc" | ||
} | ||
}, { | ||
"id": "symbolA", | ||
"type": "symbol", | ||
"source": "geojson", | ||
"layout": { | ||
"icon-image": "icon", | ||
"icon-padding": ["coalesce", ["get", "padding"], ["literal", [2]]] | ||
} | ||
} | ||
] | ||
} |
Binary file added
BIN
+3.69 KB
metrics/integration/render-tests/icon-padding/default/expected-mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions
58
metrics/integration/render-tests/icon-padding/default/style.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"collisionDebug": true, | ||
"width": 240, | ||
"height": 100 | ||
} | ||
}, | ||
"sources": { | ||
"geojson": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [{ | ||
"type": "Feature", | ||
"properties": { }, | ||
"geometry": { "type": "Point", "coordinates": [-60, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { }, | ||
"geometry": { "type": "Point", "coordinates": [-40, 0] } | ||
}, { | ||
"type": "Feature", | ||
"properties": { }, | ||
"geometry": { "type": "Point", "coordinates": [-20, 0] } | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"sprite": "local://sprites/2x", | ||
"layers": [{ | ||
"id": "bg", | ||
"type": "background", | ||
"paint": { | ||
"background-color": "#ccc" | ||
} | ||
}, { | ||
"id": "symbolA", | ||
"type": "symbol", | ||
"source": "geojson", | ||
"layout": { | ||
"icon-image": "icon", | ||
"icon-padding": [10] | ||
} | ||
}, { | ||
"id": "symbolB", | ||
"type": "symbol", | ||
"source": "geojson", | ||
"layout": { | ||
"icon-image": "icon", | ||
"icon-padding": [2, 2, -20], | ||
"icon-offset": [120, 0] | ||
} | ||
} | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
metrics/linux-gcc8-release/render-tests/icon-padding/databind/metrics.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"network": [ | ||
[ | ||
"probeNetwork - default - end", | ||
2, | ||
2094 | ||
], | ||
[ | ||
"probeNetwork - default - start", | ||
0, | ||
0 | ||
] | ||
] | ||
} |
14 changes: 14 additions & 0 deletions
14
metrics/linux-gcc8-release/render-tests/icon-padding/default/metrics.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"network": [ | ||
[ | ||
"probeNetwork - default - end", | ||
2, | ||
2094 | ||
], | ||
[ | ||
"probeNetwork - default - start", | ||
0, | ||
0 | ||
] | ||
] | ||
} |
Oops, something went wrong.