Apply most of Api10ToDo (#1782)

This commit is contained in:
srkizer 2024-04-21 15:25:33 +09:00 committed by GitHub
parent 8ff4662f1f
commit bd2c9b2258
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 115 additions and 561 deletions

View file

@ -132,14 +132,6 @@ internal sealed class DelegateFontHandle : FontHandle
/// <inheritdoc/>
public IFontHandleManager Manager { get; }
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public IFontAtlasBuildToolkitPreBuild? PreBuildToolkitForApi9Compat { get; set; }
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public bool CreateFontOnAccess { get; set; }
/// <inheritdoc/>
public void Dispose()
{

View file

@ -33,7 +33,7 @@ internal sealed partial class FontAtlasFactory
/// Implementations for <see cref="IFontAtlasBuildToolkitPreBuild"/> and
/// <see cref="IFontAtlasBuildToolkitPostBuild"/>.
/// </summary>
private class BuildToolkit : IFontAtlasBuildToolkit.IApi9Compat, IFontAtlasBuildToolkitPreBuild, IFontAtlasBuildToolkitPostBuild, IDisposable
private class BuildToolkit : IFontAtlasBuildToolkitPreBuild, IFontAtlasBuildToolkitPostBuild, IDisposable
{
private static readonly ushort FontAwesomeIconMin =
(ushort)Enum.GetValues<FontAwesomeIcon>().Where(x => x > 0).Min();
@ -111,34 +111,6 @@ internal sealed partial class FontAtlasFactory
/// <inheritdoc/>
public void DisposeWithAtlas(Action action) => this.data.Garbage.Add(action);
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public void FromUiBuilderObsoleteEventHandlers(Action action)
{
var previousSubstances = new IFontHandleSubstance[this.data.Substances.Count];
for (var i = 0; i < previousSubstances.Length; i++)
{
previousSubstances[i] = this.data.Substances[i].Manager.Substance;
this.data.Substances[i].Manager.Substance = this.data.Substances[i];
this.data.Substances[i].CreateFontOnAccess = true;
this.data.Substances[i].PreBuildToolkitForApi9Compat = this;
}
try
{
action();
}
finally
{
for (var i = 0; i < previousSubstances.Length; i++)
{
this.data.Substances[i].Manager.Substance = previousSubstances[i];
this.data.Substances[i].CreateFontOnAccess = false;
this.data.Substances[i].PreBuildToolkitForApi9Compat = null;
}
}
}
/// <inheritdoc/>
public ImFontPtr GetFont(IFontHandle fontHandle)
{

View file

@ -435,7 +435,7 @@ internal sealed partial class FontAtlasFactory
if (IsBuildInProgressForTask.Value)
{
throw new InvalidOperationException(
$"{nameof(this.NewGameFontHandle)} may not be called during {nameof(this.BuildStepChange)}, the callback of {nameof(this.NewDelegateFontHandle)}, {nameof(UiBuilder.BuildFonts)} or {nameof(UiBuilder.AfterBuildFonts)}.");
$"{nameof(this.NewGameFontHandle)} may not be called during {nameof(this.BuildStepChange)} or the callback of {nameof(this.NewDelegateFontHandle)}.");
}
return this.gameFontHandleManager.NewFontHandle(style);
@ -447,7 +447,7 @@ internal sealed partial class FontAtlasFactory
if (IsBuildInProgressForTask.Value)
{
throw new InvalidOperationException(
$"{nameof(this.NewDelegateFontHandle)} may not be called during {nameof(this.BuildStepChange)} or the callback of {nameof(this.NewDelegateFontHandle)}, {nameof(UiBuilder.BuildFonts)} or {nameof(UiBuilder.AfterBuildFonts)}.");
$"{nameof(this.NewDelegateFontHandle)} may not be called during {nameof(this.BuildStepChange)} or the callback of {nameof(this.NewDelegateFontHandle)}.");
}
return this.delegateFontHandleManager.NewFontHandle(buildStepDelegate);

View file

@ -231,14 +231,6 @@ internal class GamePrebakedFontHandle : FontHandle
/// <inheritdoc/>
public IFontHandleManager Manager => this.handleManager;
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public IFontAtlasBuildToolkitPreBuild? PreBuildToolkitForApi9Compat { get; set; }
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public bool CreateFontOnAccess { get; set; }
/// <inheritdoc/>
public void Dispose()
{
@ -295,27 +287,11 @@ internal class GamePrebakedFontHandle : FontHandle
}
}
// Use this on API 10.
// /// <inheritdoc/>
// public ImFontPtr GetFontPtr(IFontHandle handle) =>
// handle is GamePrebakedFontHandle ggfh
// ? this.fonts.GetValueOrDefault(ggfh.FontStyle)?.FullRangeFont ?? default
// : default;
/// <inheritdoc/>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
public ImFontPtr GetFontPtr(IFontHandle handle)
{
if (handle is not GamePrebakedFontHandle ggfh)
return default;
if (this.fonts.GetValueOrDefault(ggfh.FontStyle)?.FullRangeFont is { } font)
return font;
if (!this.CreateFontOnAccess)
return default;
if (this.PreBuildToolkitForApi9Compat is not { } tk)
return default;
return this.GetOrCreateFont(ggfh.FontStyle, tk);
}
public ImFontPtr GetFontPtr(IFontHandle handle) =>
handle is GamePrebakedFontHandle ggfh
? this.fonts.GetValueOrDefault(ggfh.FontStyle)?.FullRangeFont ?? default
: default;
/// <inheritdoc/>
public Exception? GetBuildException(IFontHandle handle) =>

View file

@ -21,19 +21,6 @@ internal interface IFontHandleSubstance : IDisposable
/// </summary>
IFontHandleManager Manager { get; }
/// <summary>
/// Gets or sets the relevant <see cref="IFontAtlasBuildToolkitPreBuild"/> for this.
/// </summary>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
IFontAtlasBuildToolkitPreBuild? PreBuildToolkitForApi9Compat { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to create a new instance of <see cref="ImGuiNET.ImFontPtr"/> on first
/// access, for compatibility with API 9.
/// </summary>
[Api10ToDo(Api10ToDoAttribute.DeleteCompatBehavior)]
bool CreateFontOnAccess { get; set; }
/// <summary>
/// Gets the relevant handles.
/// </summary>