Repository navigation
Map Darwin style enumerations to mbgl equivalents - #7061
Conversation
|
@boundsj, thanks for your PR! By analyzing the history of the files in this pull request, we identified @1ec5, @incanus and @friedbunny to be potential reviewers. |
| - (MGLStyleValue<NSValue *> *)lineJoin { | ||
| auto propertyValue = self.rawLayer->getLineJoin() ?: self.rawLayer->getDefaultLineJoin(); | ||
| return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *>().toStyleValue(propertyValue); | ||
| auto propertyValue = self.rawLayer->getLineJoin() ?: self.rawLayer->getDefaultLineJoin(); |
|
|
||
| MGLStyleValue<ObjCType> *toLineJoinStyleValue(const mbgl::style::PropertyValue<MBGLType> &mbglValue) { | ||
| auto str = mbgl::Enum<MBGLType>::toString(mbglValue.asConstant()); | ||
| NSString *enumString = [NSString stringWithCString:str encoding:NSUTF8StringEncoding]; |
There was a problem hiding this comment.
Nit: this can be expressed as str.UTF8String.
| auto str = mbgl::Enum<MBGLType>::toString(mbglValue.asConstant()); | ||
| NSString *enumString = [NSString stringWithCString:str encoding:NSUTF8StringEncoding]; | ||
| NSUInteger enumValue; | ||
| if ([enumString isEqualToString:@"miter"]) { |
There was a problem hiding this comment.
Nice! Using mbgl::Enum is a lot cleaner than what I thought we’d have to resort to (the _names macros).
I think we could take further advantage of mbgl::Enum, using MBGL_DEFINE_ENUM() to map e.g. { MGLLineJoinMiter, "miter" } and calling toEnum() on str. (Bogus strings that are used internally to mbgl, such as fakeround, would trip an assertion.) That way, we can avoid the NSString conversion and these if statements, and we can generate everything using the style specification (in a separate file).
There was a problem hiding this comment.
In terms of organization, these MBGL_DEFINE_ENUM()s can go in MGLLineStyleLayer.mm, for instance. We can make this toLineJoinStyleValue() method into a more generic toEnumStyleValue() by adding an ObjCEnumType template argument that we set to MGLLineJoin, for instance.
19af5d1 to
72f009d
Compare
|
@1ec5 thanks for the advice in #7061 (comment). Most of that is implemented now although I did not DRY it up yet with anything like The lookup table in https://github.com/mapbox/mapbox-gl-native/pull/7061/files#diff-01213d8ba02156a3771961755cf10994R12 is sort of unfortunate. But, since the MBGL enums are not generated and because several of them are coalesced into things like Anyway, this is working! |
There was a problem hiding this comment.
Looks like this can be replaced with global.mbglType()
|
This will also fix #5970 (again) |
c964aa9 to
e330840
Compare
|
@1ec5 @frederoni @incanus please review |
|
|
||
| #include <mbgl/style/layers/background_layer.hpp> | ||
|
|
||
| namespace mbgl { |
There was a problem hiding this comment.
Can we get rid of this block if there’s are no symbols to define in this translation unit?
|
|
||
| using namespace style; | ||
|
|
||
|
|
|
|
||
| namespace mbgl { | ||
|
|
||
| using namespace style; |
There was a problem hiding this comment.
Nothing in this block is using the mbgl::style namespace, so this statement can go away.
| } | ||
| id value = [(MGLStyleConstantValue<NSValue *> *)circleTranslateAnchor rawValue]; | ||
| MGLCircleTranslateAnchor circleTranslateAnchorValue; | ||
| [value getValue:&circleTranslateAnchorValue]; |
There was a problem hiding this comment.
In the previous code, if circleTranslateAnchor was nil, we’d reset the value in mbgl to an implicit default value. In this code, if circleTranslateAnchor is nil, circleTranslateAnchorValue will be MGLCircleTranslateAnchorMap, even if the implicit default would’ve been mbgl::style::TranslateAnchorType::Viewport.
| - (void)setCircleTranslateAnchor:(MGLStyleValue<NSValue *> *)circleTranslateAnchor { | ||
| auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *>().toPropertyValue(circleTranslateAnchor); | ||
| self.rawLayer->setCircleTranslateAnchor(mbglValue); | ||
| if ([circleTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) { |
There was a problem hiding this comment.
This code should be brought back into MGLStyleValueTransformer and made generic. Bring back the enumeration specialization of toMGLRawStyleValue(), but add an additional, optional ObjCEnum template parameter to MGLStyleValueTransformer that you can plug into mbgl::Enum. For additional safety, I think you can also make the specialization conditional on ObjCEnum satisfying std::is_enum just like it required MBGLEnum to satisfy std::is_enum.
| */ | ||
| + (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)type; | ||
|
|
||
|
|
There was a problem hiding this comment.
Each factory method should come with a readonly property that converts back into the raw type (example). This way you (and the developer) won’t ever have to use -getValue:.
|
|
||
| @interface NSValue (MGLStyleEnumAttributeAdditions) | ||
|
|
||
| #pragma mark Runtime Styling enumerations |
There was a problem hiding this comment.
A documentation section name (that is, amark in a public header) should describe a task, in title case for consistency:
#pragma mark Working with Style Layer Attribute Values| - (void)styleFilteredLines | ||
| { | ||
|
|
||
| #warning remove this test stub |
There was a problem hiding this comment.
Optional: We currently lack a demo in iosapp that draws a route line. We could add one that sets the line join and line cap to something that looks better than the default.
| 4018B1C91CDC288A00F666AF /* MGLAnnotationView_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C31CDC277F00F666AF /* MGLAnnotationView_Private.h */; }; | ||
| 4018B1CA1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; | ||
| 4018B1CB1CDC288E00F666AF /* MGLAnnotationView.h in Headers */ = {isa = PBXBuildFile; fileRef = 4018B1C51CDC277F00F666AF /* MGLAnnotationView.h */; settings = {ATTRIBUTES = (Public, ); }; }; | ||
| 4032C5BF1DE1FC780062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 4032C5B81DE1EE7D0062E8BD /* NSValue+MGLStyleEnumAttributeAdditions.h */; }; |
There was a problem hiding this comment.
These headers should be public.
| #import "MBXOfflinePacksTableViewController.h" | ||
| #import "MBXAnnotationView.h" | ||
| #import "MBXUserLocationAnnotationView.h" | ||
| #import "NSValue+MGLStyleEnumAttributeAdditions.h" |
There was a problem hiding this comment.
Import this header in both SDKs’ umbrella headers instead of here, since only iosapp and macosapp have this file in their header search paths.
| auto str = mbgl::Enum<MBGLType>::toString(mbglStop.second); | ||
| MGLType mglType; | ||
| mglType = mbgl::Enum<MGLType>::toEnum(str).value_or(mglType); | ||
| stops[@(mbglStop.first)] = [MGLStyleValue valueWithRawValue:[NSValue value:&mglType withObjCType:@encode(NSUInteger)]]; |
There was a problem hiding this comment.
Encode MGLType instead of NSUInteger, if possible.
| #include <array> | ||
|
|
||
| template <typename MBGLType, typename MGLType> | ||
| class MGLStyleEnumerationValueTransformer { |
There was a problem hiding this comment.
Can this method live inside MGLStyleValueTransformer? Use optional template parameters on the class to allow both NSValue * and MGLLineCap to be specific, and use conditional template parameters on the enumeration-specific methods to enable the methods only for enumerations.
Correctly map SDK runtime styling enumerations to mbgl equivalents. Also, add category methods to NSValue so enums can be wrapped up with less of the details of how they are layed out in memory in Objective-C.
10ee43b to
b18b2bc
Compare
|
This will also fix #7153 |
1ec5
left a comment
There was a problem hiding this comment.
Looks good other than a couple nits about whitespace and indentation.
|
|
||
| #include <mbgl/style/layers/background_layer.hpp> | ||
|
|
||
|
|
| auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *>().toPropertyValue(circleTranslateAnchor); | ||
| self.rawLayer->setCircleTranslateAnchor(mbglValue); | ||
| auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, | ||
| NSValue *, |
There was a problem hiding this comment.
Nit: funky indentation. Can this all go on one line?
This fixes an issue where the documentation for all NSValue categories were described as `MGLGeometryAdditions`.
b18b2bc to
5ae966a
Compare
Fixes #6760