naps2/NAPS2.Lib/EtoForms/EtoFormBase.cs
Ben Olden-Cooligan 7ca1cf7ef5 Use a BuildLayout method pattern
This helps organize logic a bit and better handles cases where forms have parameters.
2022-12-10 11:36:54 -08:00

39 lines
1.0 KiB
C#

using Eto.Forms;
using NAPS2.EtoForms.Layout;
namespace NAPS2.EtoForms;
public abstract class EtoFormBase : Form, IFormBase
{
private IFormFactory? _formFactory;
protected EtoFormBase(Naps2Config config)
{
EtoPlatform.Current.UpdateRtl(this);
Config = config;
FormStateController = new FormStateController(this, config);
Resizable = true;
LayoutController.Bind(this);
LayoutController.Invalidated += (_, _) => FormStateController.UpdateLayoutSize(LayoutController);
}
protected abstract void BuildLayout();
protected override void OnPreLoad(EventArgs e)
{
BuildLayout();
base.OnPreLoad(e);
}
public FormStateController FormStateController { get; }
public LayoutController LayoutController { get; } = new();
public IFormFactory FormFactory
{
get => _formFactory ?? throw new InvalidOperationException();
set => _formFactory = value;
}
public Naps2Config Config { get; set; }
}