plugin system docs
custom buttons for plugins calibration functions for Leeform
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace VisionBuilder.UI.Common.ViewModel.Classes;
|
||||
|
||||
public enum EButtonType
|
||||
{
|
||||
Click,
|
||||
Toggle
|
||||
}
|
||||
|
||||
public partial class ButtonDefinition : ObservableObject
|
||||
{
|
||||
public string Key { get; }
|
||||
public string Title { get; }
|
||||
public EButtonType Type { get; }
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isVisible = true;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isToggled;
|
||||
|
||||
private readonly Action? _clickCallback;
|
||||
private readonly Action<bool>? _toggleCallback;
|
||||
|
||||
public ButtonDefinition(string key, string title, Action clickCallback)
|
||||
{
|
||||
Key = key;
|
||||
Title = title;
|
||||
Type = EButtonType.Click;
|
||||
_clickCallback = clickCallback;
|
||||
}
|
||||
|
||||
public ButtonDefinition(string key, string title, Action<bool> toggleCallback, bool initialState = false)
|
||||
{
|
||||
Key = key;
|
||||
Title = title;
|
||||
Type = EButtonType.Toggle;
|
||||
_toggleCallback = toggleCallback;
|
||||
_isToggled = initialState;
|
||||
}
|
||||
|
||||
public void Execute()
|
||||
{
|
||||
if (Type == EButtonType.Click)
|
||||
{
|
||||
_clickCallback?.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
IsToggled = !IsToggled;
|
||||
_toggleCallback?.Invoke(IsToggled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using VisionBuilder.UI.Common.Commands;
|
||||
using VisionBuilder.UI.Common.Commands.Interfaces;
|
||||
using VisionBuilder.UI.Common.ViewModel.Classes;
|
||||
using VisionBuilder.UI.Common.ViewModel.Interfaces.UI;
|
||||
|
||||
namespace VisionBuilder.UI.Common.ViewModel;
|
||||
@@ -25,6 +26,27 @@ public partial class MainWindowVM:ObservableObject
|
||||
public ObservableCollection<SingleCameraVM> SingleCameraVms { get; set; } =
|
||||
new ObservableCollection<SingleCameraVM>();
|
||||
|
||||
public ObservableCollection<ButtonDefinition> DynamicButtons { get; } = new();
|
||||
|
||||
public void AddButton(ButtonDefinition button)
|
||||
{
|
||||
DynamicButtons.Add(button);
|
||||
}
|
||||
|
||||
public void SetButtonVisibility(string key, bool isVisible)
|
||||
{
|
||||
var button = DynamicButtons.FirstOrDefault(b => b.Key == key);
|
||||
if (button != null)
|
||||
button.IsVisible = isVisible;
|
||||
}
|
||||
|
||||
public void RemoveButton(string key)
|
||||
{
|
||||
var button = DynamicButtons.FirstOrDefault(b => b.Key == key);
|
||||
if (button != null)
|
||||
DynamicButtons.Remove(button);
|
||||
}
|
||||
|
||||
|
||||
[RelayCommand]
|
||||
public async Task Settings()
|
||||
|
||||
@@ -24,6 +24,27 @@ namespace VisionBuilder.UI.Common
|
||||
public StatisticsVM StatisticsVm { get; private set; }
|
||||
public PreviewVM PreviewVm { get; private set; }
|
||||
|
||||
public ObservableCollection<ButtonDefinition> DynamicButtons { get; } = new();
|
||||
|
||||
public void AddButton(ButtonDefinition button)
|
||||
{
|
||||
DynamicButtons.Add(button);
|
||||
}
|
||||
|
||||
public void SetButtonVisibility(string key, bool isVisible)
|
||||
{
|
||||
var button = DynamicButtons.FirstOrDefault(b => b.Key == key);
|
||||
if (button != null)
|
||||
button.IsVisible = isVisible;
|
||||
}
|
||||
|
||||
public void RemoveButton(string key)
|
||||
{
|
||||
var button = DynamicButtons.FirstOrDefault(b => b.Key == key);
|
||||
if (button != null)
|
||||
DynamicButtons.Remove(button);
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private string _currentRecipeName = "Select recipe";
|
||||
|
||||
@@ -147,8 +168,6 @@ namespace VisionBuilder.UI.Common
|
||||
public async Task Start()
|
||||
{
|
||||
|
||||
|
||||
|
||||
IsRunning = true;
|
||||
await Task.Run(() => { _recognitionControl.Start(); });
|
||||
_handlingEnabled = true;
|
||||
|
||||
Reference in New Issue
Block a user