summaryrefslogtreecommitdiff
path: root/platform/darwin/src/MGLStyleAttributeFunction.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-08-18 12:19:47 -0700
committerMinh Nguyễn <mxn@1ec5.org>2016-08-19 15:45:14 -0700
commit0a4f0e40ec6820a052ae8c68b3d58b1b300bb900 (patch)
tree18087731fc875e444ac24243e143bab78f05dd05 /platform/darwin/src/MGLStyleAttributeFunction.mm
parent7f1b325b0c8424d82a3de209a9bdee7a8602b1e0 (diff)
downloadqtlocation-mapboxgl-0a4f0e40ec6820a052ae8c68b3d58b1b300bb900.tar.gz
[ios, macos] Offsets as vectors, padding as edge insets
An offset style attribute is now exposed publicly as an NSValue representing a CGVector instead of an NSArray of NSNumbers. A padding style attribute is now exposed publicly as an NSValue representing an NSEdgeInsets or UIEdgeInsets instead of an NSArray of NSNumbers. This change also fixes round-tripping of padding values due to a difference between the style specification and Foundation regarding the order of edges around a box. Used a designated initializer on NSEdgeInsets/UIEdgeInsets to ensure correct order when converting from C++ to Objective-C. Fixes #5947, fixes #6065.
Diffstat (limited to 'platform/darwin/src/MGLStyleAttributeFunction.mm')
-rw-r--r--platform/darwin/src/MGLStyleAttributeFunction.mm22
1 files changed, 7 insertions, 15 deletions
diff --git a/platform/darwin/src/MGLStyleAttributeFunction.mm b/platform/darwin/src/MGLStyleAttributeFunction.mm
index 5216e32d97..46fa3ec6a7 100644
--- a/platform/darwin/src/MGLStyleAttributeFunction.mm
+++ b/platform/darwin/src/MGLStyleAttributeFunction.mm
@@ -93,14 +93,9 @@
- (mbgl::style::PropertyValue<std::array<float, 4> >)mbgl_paddingPropertyValue
{
__block std::vector<std::pair<float, std::array<float, 4>>> stops;
- [self.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSArray * _Nonnull padding, BOOL * _Nonnull stop) {
- NSAssert([padding isKindOfClass:[NSArray class]], @"Stops should be NSArray");
- NSNumber *top = padding[0];
- NSNumber *left = padding[1];
- NSNumber *bottom = padding[2];
- NSNumber *right = padding[2];
- auto pad = std::array<float, 4>({{top.floatValue, left.floatValue, bottom.floatValue, right.floatValue}});
- stops.emplace_back(zoomKey.floatValue, pad);
+ [self.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSValue * _Nonnull padding, BOOL * _Nonnull stop) {
+ NSAssert([padding isKindOfClass:[NSArray class]], @"Stops should be NSValue");
+ stops.emplace_back(zoomKey.floatValue, padding.mgl_paddingArrayValue);
}];
return mbgl::style::Function<std::array<float, 4>>({{stops}}, _base.floatValue);
}
@@ -108,12 +103,9 @@
- (mbgl::style::PropertyValue<std::array<float, 2> >)mbgl_offsetPropertyValue
{
__block std::vector<std::pair<float, std::array<float, 2>>> stops;
- [self.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSArray * _Nonnull offset, BOOL * _Nonnull stop) {
- NSAssert([offset isKindOfClass:[NSArray class]], @"Stops should be NSArray");
- NSNumber *dx = offset[0];
- NSNumber *dy = offset[1];
- auto off = std::array<float, 2>({{dx.floatValue, dy.floatValue}});
- stops.emplace_back(zoomKey.floatValue, off);
+ [self.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, NSValue * _Nonnull offset, BOOL * _Nonnull stop) {
+ NSAssert([offset isKindOfClass:[NSValue class]], @"Stops should be NSValue");
+ stops.emplace_back(zoomKey.floatValue, offset.mgl_offsetArrayValue);
}];
return mbgl::style::Function<std::array<float, 2>>({{stops}}, _base.floatValue);
}
@@ -176,7 +168,7 @@
auto stops = property.getStops();
NSMutableDictionary *convertedStops = [NSMutableDictionary dictionaryWithCapacity:stops.size()];
for (auto stop : stops) {
- convertedStops[@(stop.first)] = @[@(stop.second[0]), @(stop.second[1])];
+ convertedStops[@(stop.first)] = [NSValue mgl_valueWithOffsetArray:stop.second];
}
function.base = @(property.getBase());
function.stops = convertedStops;