Skip to content
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

Fix hiDPI scaling for dynamic options + empty value triggering suggestions #2077

Merged
merged 4 commits into from
Feb 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 43 additions & 9 deletions addons/dialogic/Editor/Events/Fields/field_options_dynamic.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ var resource_icon: Texture = null:
var current_value: String
var current_selected := 0

## SUGGESTIONS ITEM LIST
var _v_separation := 0
var _h_separation := 0
var _icon_margin := 0
var _line_height := 24
var _max_height := 200 * DialogicUtil.get_editor_scale()


#region FIELD METHODS
################################################################################

func _set_value(value:Variant, text:String = '') -> void:
func _set_value(value:Variant) -> void:
if value == null or value.is_empty():
%Search.text = empty_text
else:
Expand Down Expand Up @@ -82,6 +89,11 @@ func _ready() -> void:
%Suggestions.hide()
%Suggestions.item_selected.connect(suggestion_selected)
%Suggestions.item_clicked.connect(suggestion_selected)
%Suggestions.fixed_icon_size = Vector2i(16, 16) * DialogicUtil.get_editor_scale()

_v_separation = %Suggestions.get_theme_constant("v_separation")
_h_separation = %Suggestions.get_theme_constant("h_separation")
_icon_margin = %Suggestions.get_theme_constant("icon_margin")

if resource_icon == null:
self.resource_icon = null
Expand Down Expand Up @@ -115,34 +127,56 @@ func _on_Search_text_changed(new_text:String, just_update:bool = false) -> void:

var suggestions: Dictionary = get_suggestions_func.call(new_text)

var line_length: int = 0
var line_length = 0
var idx: int = 0
for element in suggestions:
if new_text.is_empty() or new_text.to_lower() in element.to_lower() or new_text.to_lower() in str(suggestions[element].value).to_lower() or new_text.to_lower() in suggestions[element].get('tooltip', '').to_lower():
line_length = max(get_theme_font('font', 'Label').get_string_size(element, HORIZONTAL_ALIGNMENT_LEFT, -1, get_theme_font_size("font_size", 'Label')).x+80, line_length)
var curr_line_length: int = 0
curr_line_length = get_theme_font('font', 'Label').get_string_size(
element, HORIZONTAL_ALIGNMENT_LEFT, -1, get_theme_font_size("font_size", 'Label')
).x

%Suggestions.add_item(element)
if suggestions[element].has('icon'):
%Suggestions.set_item_icon(idx, suggestions[element].icon)
curr_line_length += %Suggestions.fixed_icon_size.x * %Suggestions.get_icon_scale() + _icon_margin * 2 + _h_separation
elif suggestions[element].has('editor_icon'):
%Suggestions.set_item_icon(idx, get_theme_icon(suggestions[element].editor_icon[0],suggestions[element].editor_icon[1]))
curr_line_length += %Suggestions.fixed_icon_size.x * %Suggestions.get_icon_scale() + _icon_margin * 2 + _h_separation

line_length = max(line_length, curr_line_length)

%Suggestions.set_item_tooltip(idx, suggestions[element].get('tooltip', ''))
%Suggestions.set_item_metadata(idx, suggestions[element].value)
idx += 1

if not %Suggestions.visible:
%Suggestions.show()
%Suggestions.global_position = $PanelContainer.global_position+Vector2(0,1)*$PanelContainer.size.y
%Suggestions.size.x = max(%Search.size.x, line_length)
%Suggestions.size.y = min(%Suggestions.get_item_count()*35*DialogicUtil.get_editor_scale(), 200*DialogicUtil.get_editor_scale())

if %Suggestions.get_item_count():
if %Suggestions.item_count:
%Suggestions.select(0)
current_selected = 0
else:
current_selected = -1

%Search.grab_focus()

var total_height: int = 0
for item in %Suggestions.item_count:
total_height += _line_height * DialogicUtil.get_editor_scale() + _v_separation
total_height += _v_separation * 2
if total_height > _max_height:
line_length += %Suggestions.get_v_scroll_bar().get_minimum_size().x

%Suggestions.size.x = max(%PanelContainer.size.x, line_length)
%Suggestions.size.y = min(total_height, _max_height)

# Defer setting width to give PanelContainer
# time to update it's size
await get_tree().process_frame
await get_tree().process_frame

%Suggestions.size.x = max(%PanelContainer.size.x, line_length)


func suggestion_selected(index : int, position:=Vector2(), button_index:=MOUSE_BUTTON_LEFT) -> void:
Expand Down Expand Up @@ -215,7 +249,7 @@ func _on_search_gui_input(event: InputEvent) -> void:


func _on_search_focus_entered() -> void:
if %Search.text == "" or current_value == "":
if %Search.text == "":
_on_Search_text_changed("")
%Search.call_deferred('select_all')
%Focus.show()
Expand Down
13 changes: 7 additions & 6 deletions addons/dialogic/Editor/Events/Fields/field_options_dynamic.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_vennf"]

[sub_resource type="Image" id="Image_kg01j"]
[sub_resource type="Image" id="Image_suu7e"]
data = {
"data": PackedByteArray(255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 94, 94, 127, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 231, 255, 94, 94, 54, 255, 94, 94, 57, 255, 93, 93, 233, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 93, 93, 41, 255, 255, 255, 0, 255, 255, 255, 0, 255, 97, 97, 42, 255, 93, 93, 233, 255, 93, 93, 232, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 44, 255, 255, 255, 0, 255, 97, 97, 42, 255, 97, 97, 42, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 96, 96, 45, 255, 93, 93, 235, 255, 94, 94, 234, 255, 95, 95, 43, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 93, 93, 235, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 233, 255, 95, 95, 59, 255, 96, 96, 61, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 93, 93, 255, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0, 255, 255, 255, 0),
"format": "RGBA8",
Expand All @@ -15,10 +15,10 @@ data = {
"width": 16
}

[sub_resource type="ImageTexture" id="ImageTexture_j8aof"]
image = SubResource("Image_kg01j")
[sub_resource type="ImageTexture" id="ImageTexture_1y2ty"]
image = SubResource("Image_suu7e")

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_raavq"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_vb8g2"]
content_margin_left = 4.0
content_margin_top = 4.0
content_margin_right = 4.0
Expand Down Expand Up @@ -107,6 +107,7 @@ auto_translate = false
focus_neighbor_top = NodePath("..")
max_text_lines = 3
item_count = 1
fixed_icon_size = Vector2i(24, 24)
item_0/text = "Hello"

[node name="SelectButton" type="Button" parent="PanelContainer/MarginContainer/HBoxContainer"]
Expand All @@ -115,14 +116,14 @@ layout_mode = 2
focus_mode = 0
toggle_mode = true
shortcut_in_tooltip = false
icon = SubResource("ImageTexture_j8aof")
icon = SubResource("ImageTexture_1y2ty")
flat = true

[node name="Focus" type="Panel" parent="PanelContainer"]
unique_name_in_owner = true
layout_mode = 2
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_raavq")
theme_override_styles/panel = SubResource("StyleBoxFlat_vb8g2")
metadata/_edit_use_anchors_ = true

[connection signal="focus_entered" from="." to="." method="_on_focus_entered"]
Expand Down
17 changes: 9 additions & 8 deletions addons/dialogic/Editor/Images/Resources/portrait.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading