Skip to content

Commit

Permalink
Implement repeat group logic for point based styles
Browse files Browse the repository at this point in the history
- fix: repeat group should only be applied when repeat distance is > 0
- alter repeat group application for text based styles to accomodate inheritance logic from parent
point style
- implement repeat group and repeat distance parsing for point based styles
  • Loading branch information
tallytalwar committed Jan 13, 2017
1 parent 8919f13 commit f31cb17
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 18 deletions.
8 changes: 6 additions & 2 deletions core/src/scene/styleParam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const std::map<std::string, StyleParamKey> s_StyleParamMap = {
{"placement_spacing", StyleParamKey::placement_spacing},
{"placement_min_length_ratio", StyleParamKey::placement_min_length_ratio},
{"priority", StyleParamKey::priority},
{"repeat_distance", StyleParamKey::text_repeat_distance},
{"repeat_group", StyleParamKey::text_repeat_group},
{"repeat_distance", StyleParamKey::repeat_distance},
{"repeat_group", StyleParamKey::repeat_group},
{"size", StyleParamKey::size},
{"sprite", StyleParamKey::sprite},
{"sprite_default", StyleParamKey::sprite_default},
Expand Down Expand Up @@ -234,6 +234,7 @@ StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string&
case StyleParamKey::sprite_default:
case StyleParamKey::style:
case StyleParamKey::outline_style:
case StyleParamKey::repeat_group:
case StyleParamKey::text_repeat_group:
return _value;
case StyleParamKey::text_font_size: {
Expand Down Expand Up @@ -290,6 +291,7 @@ StyleParam::Value StyleParam::parseString(StyleParamKey key, const std::string&

return Width(placementSpacing);
}
case StyleParamKey::repeat_distance:
case StyleParamKey::text_repeat_distance: {
ValueUnitPair repeatDistance;
repeatDistance.unit = Unit::pixel;
Expand Down Expand Up @@ -385,6 +387,7 @@ std::string StyleParam::toString() const {
auto p = value.get<glm::vec2>();
return k + "(" + std::to_string(p.x) + "px, " + std::to_string(p.y) + "px)";
}
case StyleParamKey::repeat_group:
case StyleParamKey::transition_hide_time:
case StyleParamKey::text_transition_hide_time:
case StyleParamKey::transition_show_time:
Expand Down Expand Up @@ -433,6 +436,7 @@ std::string StyleParam::toString() const {
case StyleParamKey::color:
case StyleParamKey::outline_color:
case StyleParamKey::outline_style:
case StyleParamKey::repeat_distance:
case StyleParamKey::text_font_fill:
case StyleParamKey::text_font_stroke_color:
case StyleParamKey::text_repeat_distance:
Expand Down
2 changes: 2 additions & 0 deletions core/src/scene/styleParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ enum class StyleParamKey : uint8_t {
placement_spacing,
placement_min_length_ratio,
priority,
repeat_distance,
repeat_group,
text_order,
text_priority,
text_repeat_distance,
Expand Down
21 changes: 21 additions & 0 deletions core/src/style/pointStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ auto PointStyleBuilder::applyRule(const DrawRule& _rule, const Properties& _prop
_rule.get(StyleParamKey::offset, p.labelOptions.offset);

uint32_t priority;
size_t repeatGroupHash = 0;
std::string repeatGroup;
StyleParam::Width repeatDistance;

if (_rule.get(StyleParamKey::priority, priority)) {
p.labelOptions.priority = (float)priority;
}
Expand All @@ -135,6 +139,23 @@ auto PointStyleBuilder::applyRule(const DrawRule& _rule, const Properties& _prop
_rule.get(StyleParamKey::flat, p.labelOptions.flat);
_rule.get(StyleParamKey::anchor, p.labelOptions.anchors);

if (_rule.get(StyleParamKey::repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}

p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
}

if (p.labelOptions.anchors.count == 0) {
p.labelOptions.anchors.anchor = { {LabelProperty::Anchor::center} };
p.labelOptions.anchors.count = 1;
Expand Down
56 changes: 40 additions & 16 deletions core/src/style/textStyleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,10 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
_rule.get(StyleParamKey::transition_show_time, p.labelOptions.showTransition.time);

uint32_t priority;
size_t repeatGroupHash = 0;
std::string repeatGroup;
StyleParam::Width repeatDistance;

if (_iconText) {

if (_rule.get(StyleParamKey::text_priority, priority)) {
Expand All @@ -348,6 +352,24 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
p.labelOptions.anchors.count = 4;
}

// child text's repeat group params
if (_rule.get(StyleParamKey::text_repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::text_repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) { //inherit from parent point
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}
}


_rule.get(StyleParamKey::text_transition_hide_time, p.labelOptions.hideTransition.time);
_rule.get(StyleParamKey::text_transition_selected_time, p.labelOptions.selectTransition.time);
_rule.get(StyleParamKey::text_transition_show_time, p.labelOptions.showTransition.time);
Expand All @@ -366,28 +388,30 @@ TextStyle::Parameters TextStyleBuilder::applyRule(const DrawRule& _rule,
p.labelOptions.anchors.anchor = { {LabelProperty::Anchor::center} };
p.labelOptions.anchors.count = 1;
}
}

_rule.get(StyleParamKey::text_wrap, p.maxLineWidth);
if (_rule.get(StyleParamKey::repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
}

if (p.labelOptions.repeatDistance > 0.f) {
if (_rule.get(StyleParamKey::repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}
}

size_t repeatGroupHash = 0;
std::string repeatGroup;
if (_rule.get(StyleParamKey::text_repeat_group, repeatGroup)) {
hash_combine(repeatGroupHash, repeatGroup);
} else {
repeatGroupHash = _rule.getParamSetHash();
}

StyleParam::Width repeatDistance;
if (_rule.get(StyleParamKey::text_repeat_distance, repeatDistance)) {
p.labelOptions.repeatDistance = repeatDistance.value;
} else {
p.labelOptions.repeatDistance = View::s_pixelsPerTile;
if (p.labelOptions.repeatDistance > 0.f) {
hash_combine(repeatGroupHash, p.text);
p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
}

hash_combine(repeatGroupHash, p.text);
p.labelOptions.repeatGroup = repeatGroupHash;
p.labelOptions.repeatDistance *= m_style.pixelScale();
_rule.get(StyleParamKey::text_wrap, p.maxLineWidth);

if (auto* transform = _rule.get<std::string>(StyleParamKey::text_transform)) {
TextLabelProperty::transform(*transform, p.transform);
Expand Down

0 comments on commit f31cb17

Please sign in to comment.