Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] symbol layer - recalculate style on icon/text size changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ivovandongen committed Nov 11, 2016
1 parent 1beb28e commit c2af994
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 48 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"lodash": "^4.16.4",
"mapbox-gl-shaders": "mapbox/mapbox-gl-shaders#7f1c3bef3692f1d044035a22e65c8758b7630333",
"mapbox-gl-style-spec": "mapbox/mapbox-gl-style-spec#7f62a4fc9f21e619824d68abbc4b03cbc1685572",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#8d2d9cb86a7b4a15bc5a59bab531cd102257918d",
"mapbox-gl-test-suite": "mapbox/mapbox-gl-test-suite#af9ee275f19e81f839a2733e6906c3fac272620e",
"mkdirp": "^0.5.1",
"node-cmake": "^1.2.1",
"request": "^2.72.0",
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/layer_observer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class LayerObserver {
virtual void onLayerFilterChanged(Layer&) {}
virtual void onLayerVisibilityChanged(Layer&) {}
virtual void onLayerPaintPropertyChanged(Layer&) {}
virtual void onLayerLayoutPropertyChanged(Layer&) {}
virtual void onLayerLayoutPropertyChanged(Layer&, const char *) {}
};

} // namespace style
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/layers/layer.cpp.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void <%- camelize(type) %>Layer::set<%- camelize(property.name) %>(PropertyValue
if (value == get<%- camelize(property.name) %>())
return;
impl->layout.<%- camelizeWithLeadingLowercase(property.name) %>.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "<%- property.name %>");
}
<% } -%>
Expand Down
8 changes: 4 additions & 4 deletions src/mbgl/style/layers/line_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void LineLayer::setLineCap(PropertyValue<LineCapType> value) {
if (value == getLineCap())
return;
impl->layout.lineCap.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "line-cap");
}
PropertyValue<LineJoinType> LineLayer::getDefaultLineJoin() {
return { LineJoinType::Miter };
Expand All @@ -85,7 +85,7 @@ void LineLayer::setLineJoin(PropertyValue<LineJoinType> value) {
if (value == getLineJoin())
return;
impl->layout.lineJoin.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "line-join");
}
PropertyValue<float> LineLayer::getDefaultLineMiterLimit() {
return { 2 };
Expand All @@ -99,7 +99,7 @@ void LineLayer::setLineMiterLimit(PropertyValue<float> value) {
if (value == getLineMiterLimit())
return;
impl->layout.lineMiterLimit.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "line-miter-limit");
}
PropertyValue<float> LineLayer::getDefaultLineRoundLimit() {
return { 1 };
Expand All @@ -113,7 +113,7 @@ void LineLayer::setLineRoundLimit(PropertyValue<float> value) {
if (value == getLineRoundLimit())
return;
impl->layout.lineRoundLimit.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "line-round-limit");
}

// Paint properties
Expand Down
68 changes: 34 additions & 34 deletions src/mbgl/style/layers/symbol_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void SymbolLayer::setSymbolPlacement(PropertyValue<SymbolPlacementType> value) {
if (value == getSymbolPlacement())
return;
impl->layout.symbolPlacement.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-placement");
}
PropertyValue<float> SymbolLayer::getDefaultSymbolSpacing() {
return { 250 };
Expand All @@ -85,7 +85,7 @@ void SymbolLayer::setSymbolSpacing(PropertyValue<float> value) {
if (value == getSymbolSpacing())
return;
impl->layout.symbolSpacing.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-spacing");
}
PropertyValue<bool> SymbolLayer::getDefaultSymbolAvoidEdges() {
return { false };
Expand All @@ -99,7 +99,7 @@ void SymbolLayer::setSymbolAvoidEdges(PropertyValue<bool> value) {
if (value == getSymbolAvoidEdges())
return;
impl->layout.symbolAvoidEdges.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "symbol-avoid-edges");
}
PropertyValue<bool> SymbolLayer::getDefaultIconAllowOverlap() {
return { false };
Expand All @@ -113,7 +113,7 @@ void SymbolLayer::setIconAllowOverlap(PropertyValue<bool> value) {
if (value == getIconAllowOverlap())
return;
impl->layout.iconAllowOverlap.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-allow-overlap");
}
PropertyValue<bool> SymbolLayer::getDefaultIconIgnorePlacement() {
return { false };
Expand All @@ -127,7 +127,7 @@ void SymbolLayer::setIconIgnorePlacement(PropertyValue<bool> value) {
if (value == getIconIgnorePlacement())
return;
impl->layout.iconIgnorePlacement.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-ignore-placement");
}
PropertyValue<bool> SymbolLayer::getDefaultIconOptional() {
return { false };
Expand All @@ -141,7 +141,7 @@ void SymbolLayer::setIconOptional(PropertyValue<bool> value) {
if (value == getIconOptional())
return;
impl->layout.iconOptional.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-optional");
}
PropertyValue<AlignmentType> SymbolLayer::getDefaultIconRotationAlignment() {
return { AlignmentType::Auto };
Expand All @@ -155,7 +155,7 @@ void SymbolLayer::setIconRotationAlignment(PropertyValue<AlignmentType> value) {
if (value == getIconRotationAlignment())
return;
impl->layout.iconRotationAlignment.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotation-alignment");
}
PropertyValue<float> SymbolLayer::getDefaultIconSize() {
return { 1 };
Expand All @@ -169,7 +169,7 @@ void SymbolLayer::setIconSize(PropertyValue<float> value) {
if (value == getIconSize())
return;
impl->layout.iconSize.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-size");
}
PropertyValue<IconTextFitType> SymbolLayer::getDefaultIconTextFit() {
return { IconTextFitType::None };
Expand All @@ -183,7 +183,7 @@ void SymbolLayer::setIconTextFit(PropertyValue<IconTextFitType> value) {
if (value == getIconTextFit())
return;
impl->layout.iconTextFit.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit");
}
PropertyValue<std::array<float, 4>> SymbolLayer::getDefaultIconTextFitPadding() {
return { {{ 0, 0, 0, 0 }} };
Expand All @@ -197,7 +197,7 @@ void SymbolLayer::setIconTextFitPadding(PropertyValue<std::array<float, 4>> valu
if (value == getIconTextFitPadding())
return;
impl->layout.iconTextFitPadding.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-text-fit-padding");
}
PropertyValue<std::string> SymbolLayer::getDefaultIconImage() {
return { "" };
Expand All @@ -211,7 +211,7 @@ void SymbolLayer::setIconImage(PropertyValue<std::string> value) {
if (value == getIconImage())
return;
impl->layout.iconImage.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-image");
}
PropertyValue<float> SymbolLayer::getDefaultIconRotate() {
return { 0 };
Expand All @@ -225,7 +225,7 @@ void SymbolLayer::setIconRotate(PropertyValue<float> value) {
if (value == getIconRotate())
return;
impl->layout.iconRotate.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-rotate");
}
PropertyValue<float> SymbolLayer::getDefaultIconPadding() {
return { 2 };
Expand All @@ -239,7 +239,7 @@ void SymbolLayer::setIconPadding(PropertyValue<float> value) {
if (value == getIconPadding())
return;
impl->layout.iconPadding.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-padding");
}
PropertyValue<bool> SymbolLayer::getDefaultIconKeepUpright() {
return { false };
Expand All @@ -253,7 +253,7 @@ void SymbolLayer::setIconKeepUpright(PropertyValue<bool> value) {
if (value == getIconKeepUpright())
return;
impl->layout.iconKeepUpright.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-keep-upright");
}
PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultIconOffset() {
return { {{ 0, 0 }} };
Expand All @@ -267,7 +267,7 @@ void SymbolLayer::setIconOffset(PropertyValue<std::array<float, 2>> value) {
if (value == getIconOffset())
return;
impl->layout.iconOffset.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "icon-offset");
}
PropertyValue<AlignmentType> SymbolLayer::getDefaultTextPitchAlignment() {
return { AlignmentType::Auto };
Expand All @@ -281,7 +281,7 @@ void SymbolLayer::setTextPitchAlignment(PropertyValue<AlignmentType> value) {
if (value == getTextPitchAlignment())
return;
impl->layout.textPitchAlignment.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-pitch-alignment");
}
PropertyValue<AlignmentType> SymbolLayer::getDefaultTextRotationAlignment() {
return { AlignmentType::Auto };
Expand All @@ -295,7 +295,7 @@ void SymbolLayer::setTextRotationAlignment(PropertyValue<AlignmentType> value) {
if (value == getTextRotationAlignment())
return;
impl->layout.textRotationAlignment.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotation-alignment");
}
PropertyValue<std::string> SymbolLayer::getDefaultTextField() {
return { "" };
Expand All @@ -309,7 +309,7 @@ void SymbolLayer::setTextField(PropertyValue<std::string> value) {
if (value == getTextField())
return;
impl->layout.textField.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-field");
}
PropertyValue<std::vector<std::string>> SymbolLayer::getDefaultTextFont() {
return { { "Open Sans Regular", "Arial Unicode MS Regular" } };
Expand All @@ -323,7 +323,7 @@ void SymbolLayer::setTextFont(PropertyValue<std::vector<std::string>> value) {
if (value == getTextFont())
return;
impl->layout.textFont.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-font");
}
PropertyValue<float> SymbolLayer::getDefaultTextSize() {
return { 16 };
Expand All @@ -337,7 +337,7 @@ void SymbolLayer::setTextSize(PropertyValue<float> value) {
if (value == getTextSize())
return;
impl->layout.textSize.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-size");
}
PropertyValue<float> SymbolLayer::getDefaultTextMaxWidth() {
return { 10 };
Expand All @@ -351,7 +351,7 @@ void SymbolLayer::setTextMaxWidth(PropertyValue<float> value) {
if (value == getTextMaxWidth())
return;
impl->layout.textMaxWidth.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-width");
}
PropertyValue<float> SymbolLayer::getDefaultTextLineHeight() {
return { 1.2 };
Expand All @@ -365,7 +365,7 @@ void SymbolLayer::setTextLineHeight(PropertyValue<float> value) {
if (value == getTextLineHeight())
return;
impl->layout.textLineHeight.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-line-height");
}
PropertyValue<float> SymbolLayer::getDefaultTextLetterSpacing() {
return { 0 };
Expand All @@ -379,7 +379,7 @@ void SymbolLayer::setTextLetterSpacing(PropertyValue<float> value) {
if (value == getTextLetterSpacing())
return;
impl->layout.textLetterSpacing.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-letter-spacing");
}
PropertyValue<TextJustifyType> SymbolLayer::getDefaultTextJustify() {
return { TextJustifyType::Center };
Expand All @@ -393,7 +393,7 @@ void SymbolLayer::setTextJustify(PropertyValue<TextJustifyType> value) {
if (value == getTextJustify())
return;
impl->layout.textJustify.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-justify");
}
PropertyValue<TextAnchorType> SymbolLayer::getDefaultTextAnchor() {
return { TextAnchorType::Center };
Expand All @@ -407,7 +407,7 @@ void SymbolLayer::setTextAnchor(PropertyValue<TextAnchorType> value) {
if (value == getTextAnchor())
return;
impl->layout.textAnchor.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-anchor");
}
PropertyValue<float> SymbolLayer::getDefaultTextMaxAngle() {
return { 45 };
Expand All @@ -421,7 +421,7 @@ void SymbolLayer::setTextMaxAngle(PropertyValue<float> value) {
if (value == getTextMaxAngle())
return;
impl->layout.textMaxAngle.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-max-angle");
}
PropertyValue<float> SymbolLayer::getDefaultTextRotate() {
return { 0 };
Expand All @@ -435,7 +435,7 @@ void SymbolLayer::setTextRotate(PropertyValue<float> value) {
if (value == getTextRotate())
return;
impl->layout.textRotate.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-rotate");
}
PropertyValue<float> SymbolLayer::getDefaultTextPadding() {
return { 2 };
Expand All @@ -449,7 +449,7 @@ void SymbolLayer::setTextPadding(PropertyValue<float> value) {
if (value == getTextPadding())
return;
impl->layout.textPadding.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-padding");
}
PropertyValue<bool> SymbolLayer::getDefaultTextKeepUpright() {
return { true };
Expand All @@ -463,7 +463,7 @@ void SymbolLayer::setTextKeepUpright(PropertyValue<bool> value) {
if (value == getTextKeepUpright())
return;
impl->layout.textKeepUpright.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-keep-upright");
}
PropertyValue<TextTransformType> SymbolLayer::getDefaultTextTransform() {
return { TextTransformType::None };
Expand All @@ -477,7 +477,7 @@ void SymbolLayer::setTextTransform(PropertyValue<TextTransformType> value) {
if (value == getTextTransform())
return;
impl->layout.textTransform.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-transform");
}
PropertyValue<std::array<float, 2>> SymbolLayer::getDefaultTextOffset() {
return { {{ 0, 0 }} };
Expand All @@ -491,7 +491,7 @@ void SymbolLayer::setTextOffset(PropertyValue<std::array<float, 2>> value) {
if (value == getTextOffset())
return;
impl->layout.textOffset.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-offset");
}
PropertyValue<bool> SymbolLayer::getDefaultTextAllowOverlap() {
return { false };
Expand All @@ -505,7 +505,7 @@ void SymbolLayer::setTextAllowOverlap(PropertyValue<bool> value) {
if (value == getTextAllowOverlap())
return;
impl->layout.textAllowOverlap.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-allow-overlap");
}
PropertyValue<bool> SymbolLayer::getDefaultTextIgnorePlacement() {
return { false };
Expand All @@ -519,7 +519,7 @@ void SymbolLayer::setTextIgnorePlacement(PropertyValue<bool> value) {
if (value == getTextIgnorePlacement())
return;
impl->layout.textIgnorePlacement.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-ignore-placement");
}
PropertyValue<bool> SymbolLayer::getDefaultTextOptional() {
return { false };
Expand All @@ -533,7 +533,7 @@ void SymbolLayer::setTextOptional(PropertyValue<bool> value) {
if (value == getTextOptional())
return;
impl->layout.textOptional.set(value);
impl->observer->onLayerLayoutPropertyChanged(*this);
impl->observer->onLayerLayoutPropertyChanged(*this, "text-optional");
}

// Paint properties
Expand Down
12 changes: 10 additions & 2 deletions src/mbgl/style/style.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,17 @@ void Style::onLayerPaintPropertyChanged(Layer&) {
observer->onUpdate(Update::RecalculateStyle | Update::Classes);
}

void Style::onLayerLayoutPropertyChanged(Layer& layer) {
void Style::onLayerLayoutPropertyChanged(Layer& layer, const char * property) {
layer.accept(QueueSourceReloadVisitor { updateBatch });
observer->onUpdate(Update::Layout);

auto update = Update::Layout;

//Recalculate the style for certain properties
bool needsRecalculation = strcmp(property, "icon-size") == 0 || strcmp(property, "text-size") == 0;
if (needsRecalculation) {
update |= Update::RecalculateStyle;
}
observer->onUpdate(update);
}

void Style::dumpDebugLogs() const {
Expand Down
2 changes: 1 addition & 1 deletion src/mbgl/style/style.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class Style : public GlyphAtlasObserver,
void onLayerFilterChanged(Layer&) override;
void onLayerVisibilityChanged(Layer&) override;
void onLayerPaintPropertyChanged(Layer&) override;
void onLayerLayoutPropertyChanged(Layer&) override;
void onLayerLayoutPropertyChanged(Layer&, const char *) override;

Observer nullObserver;
Observer* observer = &nullObserver;
Expand Down
Loading

0 comments on commit c2af994

Please sign in to comment.