Implement FontChooserDialog (#1637)

* Implement FontChooserDialog

* Minor fixes

* Fixes 2

* Add Reset default font button

* Add failsafe

* reduce uninteresting exception message

* Add remarks to use AttachExtraGlyphsForDalamudLanguage

* Support advanced font configuration options

* fixes

* Shift ui elements

* more fixes

* Add To(Localized)String for IFontSpec

* Untie GlobalFontScale from default font size

* Layout fixes

* Make UiBuilder.DefaultFontSize point to user configured value

* Update example for NewDelegateFontHandle

* Font interfaces: write notes on not intended for plugins to implement

* Update default gamma to 1.7 to match closer to prev behavior (1.4**2)

* Fix console window layout
This commit is contained in:
srkizer 2024-02-14 05:09:46 +09:00 committed by GitHub
parent 3b3823d4e6
commit 34daa73612
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 2478 additions and 81 deletions

View file

@ -97,4 +97,76 @@ internal static class ArrayExtensions
/// <returns><paramref name="array"/> casted as a <see cref="IReadOnlyCollection{T}"/> if it is one; otherwise the result of <see cref="Enumerable.ToArray{TSource}"/>.</returns>
public static IReadOnlyCollection<T> AsReadOnlyCollection<T>(this IEnumerable<T> array) =>
array as IReadOnlyCollection<T> ?? array.ToArray();
/// <inheritdoc cref="List{T}.FindIndex(System.Predicate{T})"/>
public static int FindIndex<T>(this IReadOnlyList<T> list, Predicate<T> match)
=> list.FindIndex(0, list.Count, match);
/// <inheritdoc cref="List{T}.FindIndex(int,System.Predicate{T})"/>
public static int FindIndex<T>(this IReadOnlyList<T> list, int startIndex, Predicate<T> match)
=> list.FindIndex(startIndex, list.Count - startIndex, match);
/// <inheritdoc cref="List{T}.FindIndex(int,int,System.Predicate{T})"/>
public static int FindIndex<T>(this IReadOnlyList<T> list, int startIndex, int count, Predicate<T> match)
{
if ((uint)startIndex > (uint)list.Count)
throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, null);
if (count < 0 || startIndex > list.Count - count)
throw new ArgumentOutOfRangeException(nameof(count), count, null);
if (match == null)
throw new ArgumentNullException(nameof(match));
var endIndex = startIndex + count;
for (var i = startIndex; i < endIndex; i++)
{
if (match(list[i])) return i;
}
return -1;
}
/// <inheritdoc cref="List{T}.FindLastIndex(System.Predicate{T})"/>
public static int FindLastIndex<T>(this IReadOnlyList<T> list, Predicate<T> match)
=> list.FindLastIndex(list.Count - 1, list.Count, match);
/// <inheritdoc cref="List{T}.FindLastIndex(int,System.Predicate{T})"/>
public static int FindLastIndex<T>(this IReadOnlyList<T> list, int startIndex, Predicate<T> match)
=> list.FindLastIndex(startIndex, startIndex + 1, match);
/// <inheritdoc cref="List{T}.FindLastIndex(int,int,System.Predicate{T})"/>
public static int FindLastIndex<T>(this IReadOnlyList<T> list, int startIndex, int count, Predicate<T> match)
{
if (match == null)
throw new ArgumentNullException(nameof(match));
if (list.Count == 0)
{
// Special case for 0 length List
if (startIndex != -1)
throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, null);
}
else
{
// Make sure we're not out of range
if ((uint)startIndex >= (uint)list.Count)
throw new ArgumentOutOfRangeException(nameof(startIndex), startIndex, null);
}
// 2nd have of this also catches when startIndex == MAXINT, so MAXINT - 0 + 1 == -1, which is < 0.
if (count < 0 || startIndex - count + 1 < 0)
throw new ArgumentOutOfRangeException(nameof(count), count, null);
var endIndex = startIndex - count;
for (var i = startIndex; i > endIndex; i--)
{
if (match(list[i]))
{
return i;
}
}
return -1;
}
}

View file

@ -22,6 +22,9 @@ using Dalamud.Logging.Internal;
using ImGuiNET;
using Lumina.Excel.GeneratedSheets;
using Serilog;
using TerraFX.Interop.Windows;
using Windows.Win32.Storage.FileSystem;
namespace Dalamud.Utility;
@ -684,6 +687,16 @@ public static class Util
return names.ElementAt(rng.Next(0, names.Count() - 1)).Singular.RawString;
}
/// <summary>
/// Throws a corresponding exception if <see cref="HRESULT.FAILED"/> is true.
/// </summary>
/// <param name="hr">The result value.</param>
internal static void ThrowOnError(this HRESULT hr)
{
if (hr.FAILED)
Marshal.ThrowExceptionForHR(hr.Value);
}
/// <summary>
/// Print formatted GameObject Information to ImGui.
/// </summary>