some improvements

This commit is contained in:
2024-06-10 13:04:53 +02:00
parent 3cd0f8dce8
commit df8266fc40
18 changed files with 565 additions and 92 deletions

View File

@@ -0,0 +1,56 @@
using System.Reflection.Metadata;
namespace Pilz.Plugins.Advanced.UI;
public abstract class PluginModule<TPluginModuleUI> : PluginModuleBase where TPluginModuleUI : Control
{
public delegate void PluginModuleUIEventHandler(PluginModuleBase module, TPluginModuleUI ui);
/// <summary>
/// Fires when a <see cref="PluginModuleUI"/> instance has been created.
/// </summary>
public static event PluginModuleUIEventHandler? OnUICreated;
public bool Visible { get; set; } = true;
public bool AllowEmbedding { get; set; } = true;
/// <summary>
/// Wrapper for the <see cref="PluginFeature.Icon"/> property to directly use it as <see cref="System.Drawing.Image"/>.
/// </summary>
public Image? Image
{
get => base.Icon as Image;
set => base.Icon = value;
}
protected PluginModule(string moduleType, string moduleIdentifier) : base(moduleType, moduleIdentifier)
{
}
protected PluginModule(string moduleType, string moduleIdentifier, string moduleName) : base(moduleType, moduleIdentifier, moduleName)
{
}
public virtual void ShowUI()
{
ShowUI(null);
}
public virtual void ShowUI(PluginFunctionParameter? @params)
{
}
public virtual TPluginModuleUI CreateUI()
{
return CreateUI(null);
}
public virtual TPluginModuleUI CreateUI(PluginFunctionParameter? @params)
{
var ui = CreateNewUI(@params);
OnUICreated?.Invoke(this, ui);
return ui;
}
protected abstract TPluginModuleUI CreateNewUI(PluginFunctionParameter? @params);
}