From 0a4f0e40ec6820a052ae8c68b3d58b1b300bb900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguye=CC=82=CC=83n?= Date: Thu, 18 Aug 2016 12:19:47 -0700 Subject: [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. --- platform/darwin/src/MGLStyleAttributeFunction.mm | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'platform/darwin/src/MGLStyleAttributeFunction.mm') 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 >)mbgl_paddingPropertyValue { __block std::vector>> 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({{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>({{stops}}, _base.floatValue); } @@ -108,12 +103,9 @@ - (mbgl::style::PropertyValue >)mbgl_offsetPropertyValue { __block std::vector>> 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({{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>({{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; -- cgit v1.2.1