2023-07-12 15:27:27 +08:00
|
|
|
using System;
|
2023-07-12 12:11:10 +08:00
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using Godot;
|
|
|
|
|
|
|
|
namespace BITKit;
|
|
|
|
|
|
|
|
public static class LabelExtensions
|
|
|
|
{
|
|
|
|
public static async void SetTextAsync(this Label self, string text)
|
|
|
|
{
|
|
|
|
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
2023-07-12 15:27:27 +08:00
|
|
|
if (self is not null)
|
|
|
|
self.Text = text;
|
2023-07-12 12:11:10 +08:00
|
|
|
}
|
2023-07-12 15:27:27 +08:00
|
|
|
|
|
|
|
public static async void SetTextAsync(this RichTextLabel self, string text)
|
2023-07-12 12:11:10 +08:00
|
|
|
{
|
2023-07-12 15:27:27 +08:00
|
|
|
var path = self.SceneFilePath;
|
2023-07-12 12:11:10 +08:00
|
|
|
await UniTask.SwitchToSynchronizationContext(BITApp.SynchronizationContext);
|
2023-07-12 15:27:27 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
self.Text = text;
|
|
|
|
}
|
2023-07-17 04:10:14 +08:00
|
|
|
catch (Exception)
|
2023-07-12 15:27:27 +08:00
|
|
|
{
|
2023-08-18 11:03:06 +08:00
|
|
|
BIT4Log.Warning(path);
|
2023-07-12 15:27:27 +08:00
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2023-07-12 12:11:10 +08:00
|
|
|
}
|
|
|
|
}
|