Implement dynamic scaling of the LineEdit right icon based on control 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 <kobewi4e@gmail.com>
Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
This commit is contained in:
Nông Văn Tình 2024-11-22 21:27:36 +07:00
parent 235a32ad11
commit 270407b20a
3 changed files with 148 additions and 31 deletions

View file

@ -310,6 +310,9 @@
If [code]true[/code], the [LineEdit] doesn't display decoration.
</member>
<member name="focus_mode" type="int" setter="set_focus_mode" getter="get_focus_mode" overrides="Control" enum="Control.FocusMode" default="2" />
<member name="icon_expand_mode" type="int" setter="set_icon_expand_mode" getter="get_icon_expand_mode" enum="LineEdit.ExpandMode" default="0">
Define the scaling behavior of the [member right_icon].
</member>
<member name="keep_editing_on_text_submit" type="bool" setter="set_keep_editing_on_text_submit" getter="is_editing_kept_on_text_submit" default="false">
If [code]true[/code], the [LineEdit] will not exit edit mode when text is submitted by pressing [code]ui_text_submit[/code] action (by default: [kbd]Enter[/kbd] or [kbd]Kp Enter[/kbd]).
</member>
@ -352,6 +355,9 @@
<member name="right_icon" type="Texture2D" setter="set_right_icon" getter="get_right_icon">
Sets the icon that will appear in the right end of the [LineEdit] if there's no [member text], or always, if [member clear_button_enabled] is set to [code]false[/code].
</member>
<member name="right_icon_scale" type="float" setter="set_right_icon_scale" getter="get_right_icon_scale" default="1.0">
Scale ratio of the icon when [member icon_expand_mode] is set to [constant EXPAND_MODE_FIT_TO_LINE_EDIT].
</member>
<member name="secret" type="bool" setter="set_secret" getter="is_secret" default="false">
If [code]true[/code], every character is replaced with the secret character (see [member secret_character]).
</member>
@ -539,6 +545,15 @@
<constant name="KEYBOARD_TYPE_URL" value="7" enum="VirtualKeyboardType">
Virtual keyboard with additional keys to assist with typing URLs.
</constant>
<constant name="EXPAND_MODE_ORIGINAL_SIZE" value="0" enum="ExpandMode">
Use the original size for the right icon.
</constant>
<constant name="EXPAND_MODE_FIT_TO_TEXT" value="1" enum="ExpandMode">
Scale the right icon's size to match the size of the text.
</constant>
<constant name="EXPAND_MODE_FIT_TO_LINE_EDIT" value="2" enum="ExpandMode">
Scale the right icon to fit the LineEdit.
</constant>
</constants>
<theme_items>
<theme_item name="caret_color" data_type="color" type="Color" default="Color(0.95, 0.95, 0.95, 1)">