-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Conversation
Solution to above issues will require introducing a |
5712099
to
80014cb
Compare
928056e
to
3d9515b
Compare
0fc0825
to
0b1466e
Compare
a267ad1
to
56e58b9
Compare
This PR introduces Expression fields returned by Follow up work needed after this PR lands is exposing |
* Text is required to be a string literal, font-scale a number literal and text-font an array literal that holds | ||
* names of main and backup fonts. | ||
* All of them are required to be passed, but font-scale and text-font can be nullified | ||
* and will default to 1.0 and an empty array respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"default to 1.0 and an empty array respectively."
Instead of describing the defaults in implementation terms here, I think it would be better to describe the conceptual effect, which is that if "font-scale" or "text-font" are not set, the section will use the base "text-size" or "text-font (respectively) defined for the symbol.
* and accepts unlimited numbers of formatted sections. | ||
* <p> | ||
* Each sections consist of 3 elements, in this order: text, font-scale and text-font. | ||
* Text is required to be a string literal, font-scale a number literal and text-font an array literal that holds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"text-font" is required to be an array literal. "text" only requires an expression that returns a string and "font-scale" requires an expression that returns a number.
* "format" expressions can be used, for example, with the {@link PropertyFactory#textField(Expression)} | ||
* and accepts unlimited numbers of formatted sections. | ||
* <p> | ||
* Each sections consist of 3 elements, in this order: text, font-scale and text-font. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hard would it be to make the Java interface conform to the underlying expression format of using an array of text/option pairs? The problem with expanding the current "options" argument into two separate arguments here is that it will break backwards compatibility when/if we add support for further options (there are several that could conceivably be added, the immediate one we have a request for is to add "text-color" as a format option).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up! I'll try to future-proof the builder.
...rm/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/layers/layer.java.ejs
Show resolved
Hide resolved
@@ -62,7 +62,7 @@ public Expression getExpression() { | |||
? Expression.Converter.convert((JsonArray) value) | |||
: (Expression) value; | |||
} else { | |||
Logger.w(TAG, "not a expression, try value"); | |||
Logger.w(TAG, "not an expression, try value"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me a moment to understand "try value"/"try expression" -- would it read easier to say "try getValue()"/"getExpression()"?
@@ -133,7 +131,6 @@ public class <%- camelize(type) %>LayerTest extends BaseActivityTest { | |||
}); | |||
} | |||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This makes the diff bigger than it needs to be.
auto section = value.sections.at(i); | ||
auto text = jni::Make<jni::String>(env, section.text); | ||
|
||
auto fontScale = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: auto
here is hard to read (although not technically ambiguous obviously since the compiler can figure it out). I would prefer explicitly declaring the type as double
. There's a rule of thumb that you should restrict using auto
to cases where the type is visible on the same line -- we definitely don't live up to that rule, but it's good to keep in the back of your mind! Basically, auto
is good when it saves lots of repetitive typing, but it's bad when it prevents you from having to think about what type you're working with.
...roid/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/types/FormattedSection.java
Show resolved
Hide resolved
fontScale = section.fontScale.value(); | ||
} | ||
|
||
auto fontStack = jni::Array<jni::String>::New(env, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I saw FormattedSection::getFontStack()
above and saw that it was nullable, I assumed that "null" was being used to represent "not set". But it looks here (and now I notice in the tests) that text-font: null
will cause getFontStack()
to return new String[] {}
. That doesn't seem right -- an empty array would signify "use this FontStack that doesn't have any fonts in it" instead of "use the default font stack".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'm going to return null
instead of an empty array for un-set stack.
} | ||
}; | ||
Object[] actual = format( | ||
literal("test"), null, literal("awesome"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"awesome"
should be new String[]{"awesome"}
same applies for other occurrences of font-stack in the unit tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch!
Thanks for running with this @LukasPaczos and @ChrisLoer for the thorough review and great insights! Took the code for a spin and seems to be working well: Above is the a the expression copied from the unit test with some valid fonts (+ putting them in an array)
An idea to improve the ease of use of this API we could expose format specific expression:
This makes it slightly easier to integrate and would remove the necessity of adding null values such an improvement can be done as tail work. I'm 👍 on this PR, will leave it to @ChrisLoer for the actual 👍. |
b032b38
to
fc71883
Compare
a4ac85b
to
5ed3c05
Compare
For converting to Java types, flatten 'text-field' back to a string.
659afbb
to
923dfa7
Compare
This one is ready for another round @tobrun @ChrisLoer. I addressed the comments and opted for a more typed builder with |
923dfa7 also updates the local style that we are using for testing which was causing issues when setting a |
923dfa7
to
edcca60
Compare
8395a5c renames format options to avoid a clash with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me! Will defer to @tobrun on final review.
* formatFontScale(2.0), | ||
* formatTextFont(new String[] {"DIN Offc Pro Regular", "Arial Unicode MS Regular"}) | ||
* ), | ||
* formatEntry(concat(literal("\n"), get("description_property")), formatFontScale(1.5)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code example looks like it abruptly ends after formatFontScale(1.5)),
, is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch 👍
@@ -31,5 +31,5 @@ float Position::getPolarAngle(jni::JNIEnv& env, const jni::Object<Position>& pos | |||
return position.Get(env, field); | |||
} | |||
|
|||
} // namespace andr[oid |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆
...droidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/testapp/style/SymbolLayerTest.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
6607d5b
to
219c370
Compare
219c370
to
4b0d51e
Compare
Refs #12624, exposes
format
expression on Android.Setting the
text-field
using the expression, or plain text, works as expected, however, getting thetext-field
property back from core reveals a couple of issues:format
, is returned wrapped byformat
expression. This includes tokens (which are beforehand converted from plain text to expressions and this is expected).format
expression, it's being returned asString
, which is expected because of this implementation.Currently, above issues cause a bunch of tests to fail.
/cc @ChrisLoer