-
-
Notifications
You must be signed in to change notification settings - Fork 24k
Add option to scale images in RichTextLabel relative to font size #112617
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
base: master
Are you sure you want to change the base?
Conversation
scene/gui/rich_text_label.h
Outdated
| void add_hr(int p_width = 90, int p_height = 2, const Color &p_color = Color(1.0, 1.0, 1.0), HorizontalAlignment p_alignment = HORIZONTAL_ALIGNMENT_LEFT, bool p_width_in_percent = true, bool p_height_in_percent = false); | ||
| void add_image(const Ref<Texture2D> &p_image, int p_width = 0, int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlignment p_alignment = INLINE_ALIGNMENT_CENTER, const Rect2 &p_region = Rect2(), const Variant &p_key = Variant(), bool p_pad = false, const String &p_tooltip = String(), bool p_width_in_percent = false, bool p_height_in_percent = false, const String &p_alt_text = String()); | ||
| void update_image(const Variant &p_key, BitField<ImageUpdateMask> p_mask, const Ref<Texture2D> &p_image, int p_width = 0, int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlignment p_alignment = INLINE_ALIGNMENT_CENTER, const Rect2 &p_region = Rect2(), bool p_pad = false, const String &p_tooltip = String(), bool p_width_in_percent = false, bool p_height_in_percent = false); | ||
| void add_image(const Ref<Texture2D> &p_image, int p_width = 0, int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlignment p_alignment = INLINE_ALIGNMENT_CENTER, const Rect2 &p_region = Rect2(), const Variant &p_key = Variant(), bool p_pad = false, const String &p_tooltip = String(), bool p_width_in_percent = false, bool p_height_in_percent = false, bool p_width_in_em = false, bool p_height_in_em = false, const String &p_alt_text = String()); |
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.
New args should be at the end to keep script code compatibility, but in this case it's probably better to replace it with enums, something like:
enum ImageUnit {
IMAGE_UNIT_PIXEL;
IMAGE_UNIT_PERCENT;
IMAGE_UNIT_EM;
};
...
void add_image(const Ref<Texture2D> &p_image, int p_width = 0, int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), InlineAlignment p_alignment = INLINE_ALIGNMENT_CENTER, const Rect2 &p_region = Rect2(), const Variant &p_key = Variant(), bool p_pad = false, const String &p_tooltip = String(), ImageUnit p_width_unit = IMAGE_UNIT_PIXEL, ImageUnit p_height_unit = IMAGE_UNIT_PIXEL, const String &p_alt_text = String());Binary compatibility is preserved by compat bind, and it's rarely used method, so I think it's justified to break script code compatibility a bit.
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 feedback! This is what I was thinking would ultimately make the most sense for the API, but the compatibility issues had me worried 😅 I'll give this a shot, though!
43c28e8 to
4f9ed1a
Compare
I'm curious if we should go with That said, maybe it's not a relevant distinction here. |
|
If I'm understanding and the theme/default font size for this RichTextLabel is 16px, then the I suppose we could include both |
9b68a8b to
18054ba
Compare
|
The This required changing the width and height values from ints to floats, so now for free the pixel sizes and percentages also support float values! |
a5707c6 to
b56beeb
Compare
c623eb0 to
a157217
Compare
Use base font size Added docs and compatibility methods Fix compatibility methods maybe for real this time???? Please? Make width/height use floats instead of ints, and then make 1em be the height of surrounding text Fix documentation for floats instead of ints Update compatibility # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected # Conflicts: # misc/extension_api_validation/4.5-stable.expected Add compatibility breakages file
a157217 to
2e4a0c7
Compare
Closes godotengine/godot-proposals#13609.
This PR allows
imgtags in RichTextLabels to specifyheightandwidthwith theemsuffix, which makes the values a percentage of the surrounding text's font size.For example, the following text:
Displays like this:
