mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-30 04:13:40 +01:00
Easier SingleFontChooserDialog ctor, window pos/size/flags, and more docs (#1704)
* Make SingleFontChooserDialog ctor less confusing The current constructor expects a new fresh instance of IFontAtlas, which can be easy to miss, resulting in wasted time troubleshooting without enough clues. New constructor is added that directly takes an instance of UiBuilder, and the old constructor has been obsoleted and should be changed to private on api 10. * Add position, size, and window flags conf to SFCD * Improve documentations * Add test for PopupPosition/Size --------- Co-authored-by: goat <16760685+goaaats@users.noreply.github.com>
This commit is contained in:
parent
a26bb58fdb
commit
cf4a9e3055
6 changed files with 327 additions and 60 deletions
|
|
@ -44,6 +44,8 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
private bool useBold;
|
||||
private bool useMinimumBuild;
|
||||
|
||||
private SingleFontChooserDialog? chooserDialog;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public string[]? CommandShortcuts { get; init; }
|
||||
|
||||
|
|
@ -126,32 +128,75 @@ internal class GamePrebakedFontsTestWidget : IDataWindowWidget, IDisposable
|
|||
if (ImGui.Button("Test Lock"))
|
||||
Task.Run(this.TestLock);
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Choose Editor Font"))
|
||||
{
|
||||
var fcd = new SingleFontChooserDialog(
|
||||
Service<FontAtlasFactory>.Get().CreateFontAtlas(
|
||||
$"{nameof(GamePrebakedFontsTestWidget)}:EditorFont",
|
||||
FontAtlasAutoRebuildMode.Async));
|
||||
fcd.SelectedFont = this.fontSpec;
|
||||
fcd.IgnorePreviewGlobalScale = !this.atlasScaleMode;
|
||||
Service<InterfaceManager>.Get().Draw += fcd.Draw;
|
||||
fcd.ResultTask.ContinueWith(
|
||||
r => Service<Framework>.Get().RunOnFrameworkThread(
|
||||
() =>
|
||||
{
|
||||
Service<InterfaceManager>.Get().Draw -= fcd.Draw;
|
||||
fcd.Dispose();
|
||||
if (this.chooserDialog is null)
|
||||
{
|
||||
DoNext();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.chooserDialog.Cancel();
|
||||
this.chooserDialog.ResultTask.ContinueWith(_ => Service<Framework>.Get().RunOnFrameworkThread(DoNext));
|
||||
this.chooserDialog = null;
|
||||
}
|
||||
|
||||
_ = r.Exception;
|
||||
if (!r.IsCompletedSuccessfully)
|
||||
return;
|
||||
void DoNext()
|
||||
{
|
||||
var fcd = new SingleFontChooserDialog(
|
||||
Service<FontAtlasFactory>.Get(),
|
||||
$"{nameof(GamePrebakedFontsTestWidget)}:EditorFont");
|
||||
this.chooserDialog = fcd;
|
||||
fcd.SelectedFont = this.fontSpec;
|
||||
fcd.IgnorePreviewGlobalScale = !this.atlasScaleMode;
|
||||
fcd.IsModal = false;
|
||||
Service<InterfaceManager>.Get().Draw += fcd.Draw;
|
||||
var prevSpec = this.fontSpec;
|
||||
fcd.SelectedFontSpecChanged += spec =>
|
||||
{
|
||||
this.fontSpec = spec;
|
||||
Log.Information("Selected font: {font}", this.fontSpec);
|
||||
this.fontDialogHandle?.Dispose();
|
||||
this.fontDialogHandle = null;
|
||||
};
|
||||
fcd.ResultTask.ContinueWith(
|
||||
r => Service<Framework>.Get().RunOnFrameworkThread(
|
||||
() =>
|
||||
{
|
||||
Service<InterfaceManager>.Get().Draw -= fcd.Draw;
|
||||
fcd.Dispose();
|
||||
|
||||
this.fontSpec = r.Result;
|
||||
Log.Information("Selected font: {font}", this.fontSpec);
|
||||
this.fontDialogHandle?.Dispose();
|
||||
this.fontDialogHandle = null;
|
||||
}));
|
||||
_ = r.Exception;
|
||||
var spec = r.IsCompletedSuccessfully ? r.Result : prevSpec;
|
||||
if (this.fontSpec != spec)
|
||||
{
|
||||
this.fontSpec = spec;
|
||||
this.fontDialogHandle?.Dispose();
|
||||
this.fontDialogHandle = null;
|
||||
}
|
||||
|
||||
this.chooserDialog = null;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.chooserDialog is not null)
|
||||
{
|
||||
ImGui.SameLine();
|
||||
ImGui.TextUnformatted($"{this.chooserDialog.PopupPosition}, {this.chooserDialog.PopupSize}");
|
||||
|
||||
ImGui.SameLine();
|
||||
if (ImGui.Button("Random Location"))
|
||||
{
|
||||
var monitors = ImGui.GetPlatformIO().Monitors;
|
||||
var monitor = monitors[Random.Shared.Next() % monitors.Size];
|
||||
this.chooserDialog.PopupPosition = monitor.WorkPos + (monitor.WorkSize * new Vector2(
|
||||
Random.Shared.NextSingle(),
|
||||
Random.Shared.NextSingle()));
|
||||
this.chooserDialog.PopupSize = monitor.WorkSize * new Vector2(
|
||||
Random.Shared.NextSingle(),
|
||||
Random.Shared.NextSingle());
|
||||
}
|
||||
}
|
||||
|
||||
this.privateAtlas ??=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue