mirror of
https://github.com/thegatesbrowser/thegates.git
synced 2025-08-18 12:16:33 -04:00
search suggestions
This commit is contained in:
parent
88a2992f84
commit
9c637bbe9e
5 changed files with 110 additions and 21 deletions
48
app/scenes/components/suggestion.tscn
Normal file
48
app/scenes/components/suggestion.tscn
Normal file
|
@ -0,0 +1,48 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://dntnp0igpccdt"]
|
||||
|
||||
[ext_resource type="FontFile" uid="uid://do40418waa8w3" path="res://assets/fonts/Inter-Regular.otf" id="1_ljf2m"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/search/suggestion.gd" id="2_rofb8"]
|
||||
[ext_resource type="Resource" uid="uid://b1xvdym0qh6td" path="res://resources/gate_events.res" id="3_l3ahe"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ix3db"]
|
||||
content_margin_left = 13.0
|
||||
content_margin_top = 6.0
|
||||
content_margin_right = 13.0
|
||||
content_margin_bottom = 6.0
|
||||
bg_color = Color(0.12549, 0.133333, 0.172549, 1)
|
||||
corner_radius_top_left = 15
|
||||
corner_radius_top_right = 15
|
||||
corner_radius_bottom_right = 15
|
||||
corner_radius_bottom_left = 15
|
||||
shadow_color = Color(0.0862745, 0.0901961, 0.117647, 0.784314)
|
||||
shadow_size = 4
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_y60js"]
|
||||
content_margin_left = 13.0
|
||||
content_margin_top = 6.0
|
||||
content_margin_right = 13.0
|
||||
content_margin_bottom = 6.0
|
||||
bg_color = Color(0.32549, 0.14902, 0.8, 1)
|
||||
corner_radius_top_left = 15
|
||||
corner_radius_top_right = 15
|
||||
corner_radius_bottom_right = 15
|
||||
corner_radius_bottom_left = 15
|
||||
shadow_color = Color(0.0862745, 0.0901961, 0.117647, 0.784314)
|
||||
shadow_size = 4
|
||||
|
||||
[node name="Suggestion" type="Button"]
|
||||
custom_minimum_size = Vector2(0, 26)
|
||||
focus_mode = 0
|
||||
mouse_default_cursor_shape = 2
|
||||
theme_override_colors/font_color = Color(0.831373, 0.831373, 0.831373, 1)
|
||||
theme_override_fonts/font = ExtResource("1_ljf2m")
|
||||
theme_override_font_sizes/font_size = 15
|
||||
theme_override_styles/disabled = SubResource("StyleBoxFlat_ix3db")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_y60js")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_ix3db")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_ix3db")
|
||||
text = "suggestion"
|
||||
script = ExtResource("2_rofb8")
|
||||
gate_events = ExtResource("3_l3ahe")
|
||||
|
||||
[connection signal="pressed" from="." to="." method="_on_button_pressed"]
|
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=14 format=3 uid="uid://dh3owgirapji5"]
|
||||
[gd_scene load_steps=15 format=3 uid="uid://dh3owgirapji5"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ui/search/search_results.gd" id="1_bycb5"]
|
||||
[ext_resource type="FontFile" uid="uid://do40418waa8w3" path="res://assets/fonts/Inter-Regular.otf" id="1_mgpxk"]
|
||||
|
@ -7,6 +7,7 @@
|
|||
[ext_resource type="Resource" uid="uid://cjcdum6fm4ta0" path="res://resources/api_settings.tres" id="3_263ma"]
|
||||
[ext_resource type="Script" path="res://scripts/ui/search/search_results_header.gd" id="3_cuw8t"]
|
||||
[ext_resource type="PackedScene" uid="uid://i3lgu2dyypcq" path="res://scenes/components/result.tscn" id="4_yxn4t"]
|
||||
[ext_resource type="PackedScene" uid="uid://dntnp0igpccdt" path="res://scenes/components/suggestion.tscn" id="8_1alsm"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u8k0c"]
|
||||
bg_color = Color(0.113725, 0.117647, 0.14902, 1)
|
||||
|
@ -76,7 +77,7 @@ size_flags_horizontal = 3
|
|||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 0
|
||||
theme_override_constants/margin_top = 0
|
||||
theme_override_constants/margin_right = 899
|
||||
theme_override_constants/margin_right = 0
|
||||
theme_override_constants/margin_bottom = 0
|
||||
script = ExtResource("1_scp2i")
|
||||
limit = Vector2(1015, -1)
|
||||
|
@ -94,29 +95,26 @@ size_flags_horizontal = 3
|
|||
custom_minimum_size = Vector2(850, 0)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Header" type="Control" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 50)
|
||||
[node name="Space" type="Control" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 16)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer/Header"]
|
||||
[node name="Header" type="Label" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
self_modulate = Color(1, 1, 1, 0.6)
|
||||
layout_mode = 1
|
||||
anchors_preset = 4
|
||||
anchor_top = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_top = -9.5
|
||||
offset_right = 205.0
|
||||
offset_bottom = 9.5
|
||||
grow_vertical = 2
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 20
|
||||
label_settings = SubResource("LabelSettings_hqrcd")
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
script = ExtResource("3_cuw8t")
|
||||
gate_events = ExtResource("2_2plpa")
|
||||
header = "Search results for"
|
||||
search_header = "Search results for"
|
||||
suggestion_header = "Your search didn’t match any gates, try this instead"
|
||||
|
||||
[node name="SearchResults" type="VBoxContainer" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
[node name="Space3" type="Control" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 8)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SearchResults" type="VBoxContainer" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer" node_paths=PackedStringArray("header", "suggestions_root")]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
|
@ -125,8 +123,16 @@ script = ExtResource("1_bycb5")
|
|||
gate_events = ExtResource("2_2plpa")
|
||||
api = ExtResource("3_263ma")
|
||||
result_scene = ExtResource("4_yxn4t")
|
||||
header = NodePath("../Header")
|
||||
suggestions_root = NodePath("SearchSuggestions")
|
||||
suggestion_scene = ExtResource("8_1alsm")
|
||||
|
||||
[node name="Space" type="Control" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
[node name="SearchSuggestions" type="HFlowContainer" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer/SearchResults"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/h_separation = 6
|
||||
theme_override_constants/v_separation = 6
|
||||
|
||||
[node name="Space2" type="Control" parent="MarginContainer/ScrollContainer/MaxSizeContainer/HBoxContainer/VBoxContainer"]
|
||||
custom_minimum_size = Vector2(0, 50)
|
||||
layout_mode = 2
|
||||
|
||||
|
|
|
@ -4,9 +4,14 @@ extends VBoxContainer
|
|||
@export var api: ApiSettings
|
||||
@export var result_scene: PackedScene
|
||||
|
||||
@export var header: SearchResultsHeader
|
||||
@export var suggestions_root: Control
|
||||
@export var suggestion_scene: PackedScene
|
||||
|
||||
var result_str: String = "{}"
|
||||
var suggestions_str: String = "{}"
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
search(gate_events.current_search_query)
|
||||
|
||||
|
@ -21,6 +26,9 @@ func search(query: String) -> void:
|
|||
suggestions()
|
||||
return
|
||||
|
||||
header.set_search_header()
|
||||
suggestions_root.visible = false
|
||||
|
||||
for gate in gates:
|
||||
Debug.logr(gate["url"])
|
||||
var result: SearchResult = result_scene.instantiate()
|
||||
|
@ -46,9 +54,14 @@ func suggestions() -> void:
|
|||
if suggs == null or suggs.is_empty():
|
||||
Debug.logclr("No suggestions found", Color.YELLOW)
|
||||
return
|
||||
|
||||
|
||||
for sugg in suggs:
|
||||
Debug.logr(sugg)
|
||||
var suggestion: Suggestion = suggestion_scene.instantiate()
|
||||
suggestion.fill(sugg)
|
||||
suggestions_root.add_child(suggestion)
|
||||
|
||||
header.set_suggestion_header()
|
||||
|
||||
|
||||
func suggestions_request() -> void:
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
extends Label
|
||||
class_name SearchResultsHeader
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var header: String
|
||||
@export var search_header: String
|
||||
@export var suggestion_header: String
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
text = "%s \"%s\"" % [header, gate_events.current_search_query]
|
||||
func set_search_header() -> void:
|
||||
text = "%s \"%s\"" % [search_header, gate_events.current_search_query]
|
||||
|
||||
|
||||
func set_suggestion_header() -> void:
|
||||
text = suggestion_header
|
||||
|
|
16
app/scripts/ui/search/suggestion.gd
Normal file
16
app/scripts/ui/search/suggestion.gd
Normal file
|
@ -0,0 +1,16 @@
|
|||
extends Button
|
||||
class_name Suggestion
|
||||
|
||||
@export var gate_events: GateEvents
|
||||
@export var prompt: String
|
||||
|
||||
|
||||
func fill(_prompt: String) -> void:
|
||||
prompt = _prompt
|
||||
text = _prompt
|
||||
|
||||
|
||||
func _on_button_pressed() -> void:
|
||||
if prompt.is_empty(): return
|
||||
|
||||
gate_events.search_emit(prompt)
|
Loading…
Add table
Add a link
Reference in a new issue