Merge pull request #1621 from Soreepeong/fix/fonthandlewrapper

Fix FontHandleWrapper and some docs
This commit is contained in:
goat 2024-01-23 12:21:04 +01:00 committed by GitHub
commit 3cbc689914
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 13 deletions

View file

@ -744,10 +744,12 @@ public sealed class UiBuilder : IDisposable
public event Action<IFontHandle>? ImFontChanged; public event Action<IFontHandle>? ImFontChanged;
public Exception? LoadException => public Exception? LoadException => this.WrappedNotDisposed.LoadException;
this.wrapped!.LoadException ?? new ObjectDisposedException(nameof(FontHandleWrapper));
public bool Available => this.wrapped?.Available ?? false; public bool Available => this.WrappedNotDisposed.Available;
private IFontHandle WrappedNotDisposed =>
this.wrapped ?? throw new ObjectDisposedException(nameof(FontHandleWrapper));
public void Dispose() public void Dispose()
{ {
@ -759,19 +761,17 @@ public sealed class UiBuilder : IDisposable
// Note: do not dispose w; we do not own it // Note: do not dispose w; we do not own it
} }
public IFontHandle.ImFontLocked Lock() => public IFontHandle.ImFontLocked Lock() => this.WrappedNotDisposed.Lock();
this.wrapped?.Lock() ?? throw new ObjectDisposedException(nameof(FontHandleWrapper));
public IDisposable Push() => public IDisposable Push() => this.WrappedNotDisposed.Push();
this.wrapped?.Push() ?? throw new ObjectDisposedException(nameof(FontHandleWrapper));
public void Pop() => this.wrapped?.Pop(); public void Pop() => this.WrappedNotDisposed.Pop();
public Task<IFontHandle> WaitAsync() => public Task<IFontHandle> WaitAsync() =>
this.wrapped?.WaitAsync().ContinueWith(_ => (IFontHandle)this) ?? this.WrappedNotDisposed.WaitAsync().ContinueWith(_ => (IFontHandle)this);
throw new ObjectDisposedException(nameof(FontHandleWrapper));
public override string ToString() => $"{nameof(FontHandleWrapper)}({this.wrapped})"; public override string ToString() =>
$"{nameof(FontHandleWrapper)}({this.wrapped?.ToString() ?? "disposed"})";
private void WrappedOnImFontChanged(IFontHandle obj) => this.ImFontChanged.InvokeSafely(this); private void WrappedOnImFontChanged(IFontHandle obj) => this.ImFontChanged.InvokeSafely(this);
} }

View file

@ -1,4 +1,5 @@
using System.Diagnostics.Contracts; using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -64,8 +65,9 @@ internal interface IDalamudAssetManager
/// </summary> /// </summary>
/// <param name="asset">The texture asset.</param> /// <param name="asset">The texture asset.</param>
/// <param name="defaultWrap">The default return value, if the asset is not ready for whatever reason.</param> /// <param name="defaultWrap">The default return value, if the asset is not ready for whatever reason.</param>
/// <returns>The texture wrap.</returns> /// <returns>The texture wrap. Can be <c>null</c> only if <paramref name="defaultWrap"/> is <c>null</c>.</returns>
[Pure] [Pure]
[return: NotNullIfNotNull(nameof(defaultWrap))]
IDalamudTextureWrap? GetDalamudTextureWrap(DalamudAsset asset, IDalamudTextureWrap? defaultWrap); IDalamudTextureWrap? GetDalamudTextureWrap(DalamudAsset asset, IDalamudTextureWrap? defaultWrap);
/// <summary> /// <summary>