添加了搜索框

更改了UI样式
添加了标识搜索框
This commit is contained in:
CortexCore
2023-07-09 00:48:08 +08:00
parent 36a4309730
commit 10c90cee9a
17 changed files with 555 additions and 102 deletions

View File

@@ -0,0 +1,68 @@
using Godot;
using System;
using System.Linq;
using System.Threading.Tasks;
using BITKit;
using Cysharp.Threading.Tasks;
namespace BITFactory;
public partial class IDIS_SearchService : Node
{
[ExportCategory("Service")]
[Export] private IDIS_Service service;
[ExportCategory("UI 绑定 ")]
[Export] private LineEdit searchEdit;
[Export] private Control searchCandidateContainer;
[Export] private StringResource searchButtonVariation;
public override void _Ready()
{
MathNode.RemoveAllChild(searchCandidateContainer);
searchEdit.TextChanged += Search;
//searchEdit.FocusExited += Clear;
}
private void Search(string word)
{
MathNode.RemoveAllChild(searchCandidateContainer);
if (service.TrySearch(word, out var queries) is false) return;
if(queries.Length is 1 && queries.First().Handle == word)return;
foreach (var query in queries)
{
var button = new Button();
button.Flat = true;
searchCandidateContainer.AddChild(button);
button.Text = query.Handle;
button.Pressed+=OnButtonOnPressed;
button.ThemeTypeVariation = searchButtonVariation.Value;
void OnButtonOnPressed()
{
searchEdit.Text = query.Handle;
Search(query.Handle);
}
}
}
private async void Clear()
{
await Task.Delay(100);
MathNode.RemoveAllChild(searchCandidateContainer);
}
}