clean_ryujinx/src/Ryujinx/Systems/SetupWizard/SetupWizardPageBuilder.cs
GreemDev b033adbde7 Initial work on a setup wizard
Setup wizard abstraction & architecture from TKMM
2025-12-19 23:15:22 -06:00

69 lines
2 KiB
C#

using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Systems.SetupWizard;
using System.Threading.Tasks;
namespace Ryujinx.Systems.SetupWizard
{
public class SetupWizardPageBuilder(ContentPresenter presenter, bool isFirstPage = false)
{
private readonly SetupWizardPage _page = new(isFirstPage);
public SetupWizardPage Build()
{
return _page;
}
public SetupWizardPageBuilder WithTitle(LocaleKeys title) => WithTitle(LocaleManager.Instance[title]);
public SetupWizardPageBuilder WithTitle(string title)
{
_page.Title = title;
return this;
}
public SetupWizardPageBuilder WithContent(LocaleKeys content) => WithContent(LocaleManager.Instance[content]);
public SetupWizardPageBuilder WithContent(object? content)
{
if (content is StyledElement { Parent: ContentControl parent }) {
parent.Content = null;
}
_page.Content = content;
return this;
}
public SetupWizardPageBuilder WithHelpContent(LocaleKeys content) => WithHelpContent(LocaleManager.Instance[content]);
public SetupWizardPageBuilder WithHelpContent(object? content)
{
_page.HelpContent = content;
return this;
}
public SetupWizardPageBuilder WithContent<TControl>(object? context = null) where TControl : Control, new()
{
_page.Content = new TControl {
DataContext = context
};
return this;
}
public SetupWizardPageBuilder WithActionContent(LocaleKeys content) => WithActionContent(LocaleManager.Instance[content]);
public SetupWizardPageBuilder WithActionContent(object? content)
{
_page.ActionContent = content;
return this;
}
public ValueTask<bool> Show()
{
return _page.Show(presenter);
}
}
}