-
-
Notifications
You must be signed in to change notification settings - Fork 238
RichElementImage - Add support for scaling #801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RichElementImage - Add support for scaling #801
Conversation
What about implement html standard |
Check @halx99 |
core/ui/UIRichText.cpp
Outdated
@@ -471,13 +471,29 @@ MyXMLVisitor::MyXMLVisitor(RichText* richText) : _fontElements(20), _richText(ri | |||
it = tagAttrValueMap.find("height"); | |||
if (it != tagAttrValueMap.end()) | |||
{ | |||
height = it->second.asInt(); | |||
auto str = it->second.asStringRef(); | |||
if (str[str.length() - 1] == '%') |
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.
It's best to check if the string is empty before attempting to do a [length - 1]
, because this will definitely cause a crash if the string is like this: height=""
. Same goes for the width
.
You could also use this instead if (str.back() == '%')
, but you would still need to check if the string is empty beforehand.
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.
Then again, there doesn't seem to be much (if any) validation code in the RichText implementation for all the other fields either, so perhaps the assumption is that they will always be valid. This could lead to problems if the text is added dynamically (such as based on user-input), but if the text is hard-coded, then any issues will most likely show up in development.
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.
And all find and try get value could use: ax::optValue(valueMap, "key"sv).asXXX
instead.
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.
@rh101, Yeah we can add empty check but as you said, there is no validation anyways so I didn't think it was needed. I will add it.
@halx99 optValue is extremely slow. You should profile it. I have already removed it from my fork as it was slowing down plist loading for particle effects as well as spriteframes. I suspect it has something to do with the custom string_hash & equal_to functions you have written for string_view for use with robin_map (to support both string & string_view interchangeably, right?), although I was not able to figure out the exact cause.
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.
Check does the latest commit solve the performance issue:
d8c9a88
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.
Cool. I will profile and get back to you.
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.
Cool. I will profile and get back to you.
Maybe the Optick profiler #845 is helping you?
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 PROJECT IS IN DEVELOPMENT MODE. Any pull requests should merge to branch
dev
, otherwise will be rejected immediately.Describe your changes
Added support for "scaleX", "scaleY" and "scale" tags for rich text
tag.
Added support for width/height in percentage. E.g.
<img width="150%" />
Also fixed a bug with the url attribute. Even if you didn't put a url in your img, it will still call openUrl() for some reason.
Checklist before requesting a review