添加了搜索框
更改了UI样式 添加了标识搜索框
This commit is contained in:
68
Mods/工业数据采集与分析应用分享/Scripts/IDIS_SearchService.cs
Normal file
68
Mods/工业数据采集与分析应用分享/Scripts/IDIS_SearchService.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user