plugin system docs

custom buttons for plugins
calibration functions for Leeform
This commit is contained in:
EugeneTes
2026-03-30 16:15:47 +02:00
parent a1838cafeb
commit 4bd117af47
76 changed files with 4521 additions and 59 deletions

View File

@@ -1,8 +1,10 @@
using System.Collections.Specialized;
using MaterialSkin;
using MaterialSkin.Controls;
using VisionBuilder.UI.Common;
using VisionBuilder.UI.Common.Services;
using VisionBuilder.UI.Common.ViewModel;
using VisionBuilder.UI.Common.ViewModel.Classes;
namespace VisionBuilder.UI.Windows.Duo
{
@@ -12,10 +14,11 @@ namespace VisionBuilder.UI.Windows.Duo
private readonly IPasswordInputService _passwordInputService;
private readonly UIConfiguration _uiConfiguration;
private readonly WindowsUISettings _windowsUiSettings;
private readonly Dictionary<string, Control> _dynamicButtonControls = new();
public Form1(MainWindowVM mainWindowVm, IPasswordInputService passwordInputService, UIConfiguration uiConfiguration, WindowsUISettings windowsUiSettings)
{
_mainWindowVm = mainWindowVm;
_passwordInputService = passwordInputService;
_uiConfiguration = uiConfiguration;
@@ -30,6 +33,9 @@ namespace VisionBuilder.UI.Windows.Duo
if(!_uiConfiguration.ShowTestModeButton)
flowLayoutPanel1.Controls.Remove(btnTestMode);
_mainWindowVm.DynamicButtons.CollectionChanged += DynamicButtons_CollectionChanged;
foreach (var btn in _mainWindowVm.DynamicButtons)
AddDynamicButton(btn);
}
private void _mainWindowVm_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
@@ -105,5 +111,69 @@ namespace VisionBuilder.UI.Windows.Duo
{
return this;
}
private void DynamicButtons_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
foreach (ButtonDefinition btn in e.NewItems!)
AddDynamicButton(btn);
break;
case NotifyCollectionChangedAction.Remove:
foreach (ButtonDefinition btn in e.OldItems!)
RemoveDynamicButton(btn);
break;
case NotifyCollectionChangedAction.Reset:
foreach (var ctrl in _dynamicButtonControls.Values)
flowLayoutPanel1.Controls.Remove(ctrl);
_dynamicButtonControls.Clear();
break;
}
}
private void AddDynamicButton(ButtonDefinition buttonDef)
{
var btn = new MaterialRaisedButton
{
Text = buttonDef.Title,
Size = new Size(176, 64),
Font = new Font("Segoe UI Semibold", 12F, FontStyle.Bold),
DrawBorder = true,
Primary = buttonDef.Type == EButtonType.Toggle && buttonDef.IsToggled,
Visible = buttonDef.IsVisible
};
btn.Click += (_, _) =>
{
buttonDef.Execute();
if (buttonDef.Type == EButtonType.Toggle)
btn.Primary = buttonDef.IsToggled;
};
buttonDef.PropertyChanged += (_, args) =>
{
if (args.PropertyName == nameof(ButtonDefinition.IsVisible))
btn.Visible = buttonDef.IsVisible;
else if (args.PropertyName == nameof(ButtonDefinition.IsToggled))
btn.Primary = buttonDef.IsToggled;
};
// Insert before Minimize button
var minimizeIndex = flowLayoutPanel1.Controls.IndexOf(btnMinimize);
if (minimizeIndex >= 0)
flowLayoutPanel1.Controls.Add(btn);
flowLayoutPanel1.Controls.SetChildIndex(btn, minimizeIndex >= 0 ? minimizeIndex : flowLayoutPanel1.Controls.Count - 1);
_dynamicButtonControls[buttonDef.Key] = btn;
}
private void RemoveDynamicButton(ButtonDefinition buttonDef)
{
if (_dynamicButtonControls.TryGetValue(buttonDef.Key, out var ctrl))
{
flowLayoutPanel1.Controls.Remove(ctrl);
_dynamicButtonControls.Remove(buttonDef.Key);
}
}
}
}