-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Implement dynamic scaling of the LineEdit right icon based on control size and scale factor #95817
base: master
Are you sure you want to change the base?
Conversation
965d970
to
28bbc19
Compare
Right Icon Scale has no effect when Expand Icon is off. It should be disabled in that case. |
This changes the default behavior of the right icon. It will scale to text, while previously it would use original size. |
d067c5d
to
533d0b9
Compare
533d0b9
to
3e65518
Compare
b53077d
to
6bd198e
Compare
icon_max_width = MAX(icon_max_width, theme_cache.clear_icon->get_width()); | ||
Point2 right_icon_size = _get_right_icon_size(theme_cache.clear_icon); | ||
min_size.height = MAX(min_size.height, right_icon_size.height); | ||
icon_max_width = MAX(icon_max_width, right_icon_size.width); |
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.
If right icon is bigger, the minimum size will fit to the right icon, even if it's not used when clear button is enabled.
It's a pre-existing bug, so you don't need to fix it now.
scene/gui/line_edit.cpp
Outdated
@@ -2523,6 +2566,31 @@ Ref<Texture2D> LineEdit::get_right_icon() { | |||
return right_icon; | |||
} | |||
|
|||
void LineEdit::set_icon_expand_mode(ExpandMode p_mode) { | |||
if (icon_expand_mode != p_mode) { |
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.
if (icon_expand_mode != p_mode) { | |
if (icon_expand_mode = p_mode) { | |
return; | |
} |
Early returns are preferred. Same below.
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.
Overall looks good now.
scene/gui/line_edit.h
Outdated
enum ExpandMode { | ||
EXPAND_MODE_ORIGINAL_SIZE, | ||
EXPAND_MODE_FIT_TO_TEXT, | ||
EXPAND_MODE_FIT_TO_LINE_EDIT |
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.
EXPAND_MODE_FIT_TO_LINE_EDIT | |
EXPAND_MODE_FIT_TO_LINE_EDIT, |
scene/gui/line_edit.cpp
Outdated
@@ -2962,6 +3040,11 @@ void LineEdit::_bind_methods() { | |||
ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override"); | |||
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options"); | |||
|
|||
ADD_GROUP("Icon", ""); | |||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_right_icon", "get_right_icon"); | |||
ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_expand_mode", PROPERTY_HINT_ENUM, "Original, Fit to Text, Fit to LineEdit"), "set_icon_expand_mode", "get_icon_expand_mode"); |
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.
ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_expand_mode", PROPERTY_HINT_ENUM, "Original, Fit to Text, Fit to LineEdit"), "set_icon_expand_mode", "get_icon_expand_mode"); | |
ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_expand_mode", PROPERTY_HINT_ENUM, "Original,Fit to Text,Fit to LineEdit"), "set_icon_expand_mode", "get_icon_expand_mode"); |
scene/gui/line_edit.cpp
Outdated
@@ -2873,6 +2944,10 @@ void LineEdit::_bind_methods() { | |||
ClassDB::bind_method(D_METHOD("is_drag_and_drop_selection_enabled"), &LineEdit::is_drag_and_drop_selection_enabled); | |||
ClassDB::bind_method(D_METHOD("set_right_icon", "icon"), &LineEdit::set_right_icon); | |||
ClassDB::bind_method(D_METHOD("get_right_icon"), &LineEdit::get_right_icon); | |||
ClassDB::bind_method(D_METHOD("set_icon_expand_mode", "mode"), &LineEdit::set_icon_expand_mode); | |||
ClassDB::bind_method(D_METHOD("get_icon_expand_mode"), &LineEdit::get_icon_expand_mode); | |||
ClassDB::bind_method(D_METHOD("set_right_icon_scale", "p_ratio"), &LineEdit::set_right_icon_scale); |
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.
ClassDB::bind_method(D_METHOD("set_right_icon_scale", "p_ratio"), &LineEdit::set_right_icon_scale); | |
ClassDB::bind_method(D_METHOD("set_right_icon_scale", "scale"), &LineEdit::set_right_icon_scale); |
scene/gui/line_edit.h
Outdated
void set_icon_expand_mode(ExpandMode p_mode); | ||
ExpandMode get_icon_expand_mode() const; | ||
|
||
void set_right_icon_scale(float p_ratio); |
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.
void set_right_icon_scale(float p_ratio); | |
void set_right_icon_scale(float p_scale); |
scene/gui/line_edit.cpp
Outdated
return icon_expand_mode; | ||
} | ||
|
||
void LineEdit::set_right_icon_scale(float p_ratio) { |
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.
void LineEdit::set_right_icon_scale(float p_ratio) { | |
void LineEdit::set_right_icon_scale(float p_scale) { |
6bd198e
to
c906768
Compare
e2993b3
to
c951d12
Compare
c951d12
to
4c0caa5
Compare
… size and scale factor The implementation allows the LineEdit node to scale the right icon to match the font size first. Then, when the `expand_icon` option is enabled, the icon will expand to the full height of the node. The scale of the icon can then be controlled using the scale factor. Co-authored-by: Tomasz Chabora <[email protected]> Co-authored-by: A Thousand Ships <[email protected]>
4c0caa5
to
69e27d9
Compare
Close: godotengine/godot-proposals#10493
The implementation allows the LineEdit node to scale the right icon to match the font size first. Then, when the
expand_icon
option is enabled, the icon will expand to the full height of the node. The scale of the icon can then be controlled using the scale factor.Screen.Recording.2024-08-20.020245.mp4