Plugin development QoL improvements

This commit is contained in:
Stone-Red-Code
2021-07-19 19:22:11 +02:00
parent 985a68b33e
commit 83a6339a46
56 changed files with 119 additions and 31 deletions
Binary file not shown.
Binary file not shown.
+1 -1
View File
@@ -48,7 +48,7 @@
<ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" DisplayMemberPath="Item1" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" /> <ComboBox x:Name="optionsComboBox" DockPanel.Dock="Top" Height="24" SelectedIndex="0" DisplayMemberPath="Item1" SelectionChanged="OptionsComboBox_SelectionChanged" Background="#FFECECEC" />
<ScrollViewer Background="#FFBBBBBB"> <ScrollViewer Background="#FFBBBBBB">
<Grid> <Grid>
<StackPanel x:Name="optionsPanel" Margin="3,3,3,0" Visibility="Collapsed"> <StackPanel x:Name="optionsPanel" Margin="3,3,3,0" HorizontalAlignment="Stretch" Visibility="Collapsed" >
</StackPanel> </StackPanel>
<StackPanel x:Name="musicVisualizerOptionsPanel" Margin="3,3,3,0"> <StackPanel x:Name="musicVisualizerOptionsPanel" Margin="3,3,3,0">
<Label Content="{DynamicResource color}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" /> <Label Content="{DynamicResource color}" HorizontalAlignment="Left" VerticalAlignment="Top" Padding="0,1" />
+48 -16
View File
@@ -423,9 +423,10 @@ namespace DesktopMagic
foreach (SettingElement settingElement in settingElements) foreach (SettingElement settingElement in settingElements)
{ {
StackPanel stackPanel = new() DockPanel stackPanel = new()
{ {
Orientation = Orientation.Horizontal LastChildFill = true,
HorizontalAlignment = HorizontalAlignment.Stretch
}; };
_ = optionsPanel.Children.Add(stackPanel); _ = optionsPanel.Children.Add(stackPanel);
@@ -440,30 +441,61 @@ namespace DesktopMagic
stackPanel.UpdateLayout(); stackPanel.UpdateLayout();
label.UpdateLayout(); label.UpdateLayout();
if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Heading eHeading) if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Label eLabel)
{ {
label.Text = eHeading.Value; label.Text = eLabel.Value;
label.Margin = new Thickness(0, 5, 3, 0); label.Margin = new Thickness(0, 5, 3, 0);
label.FontWeight = FontWeights.Bold; label.HorizontalAlignment = HorizontalAlignment.Stretch;
label.Width = optionsPanel.ActualWidth;
label.TextWrapping = TextWrapping.WrapWithOverflow; label.TextWrapping = TextWrapping.WrapWithOverflow;
eHeading.OnValueChanged += () =>
if (eLabel.Bold)
{
label.FontWeight = FontWeights.Bold;
}
eLabel.OnValueChanged += () =>
{ {
Dispatcher.Invoke(() => Dispatcher.Invoke(() =>
{ {
label.Text = eHeading.Value; label.Text = eLabel.Value;
Option_ValueChanged(); Option_ValueChanged();
}); });
}; };
} }
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.Button eButton)
{
Button button = new()
{
Content = eButton.Value,
FontSize = 10,
Height = 20,
Margin = new Thickness(0, 10, 0, 10),
Padding = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
};
button.Click += (_s, _e) =>
{
eButton.Click();
};
eButton.OnValueChanged += () =>
{
Dispatcher.Invoke(() =>
{
button.Content = eButton.Value;
Option_ValueChanged();
});
};
_ = stackPanel.Children.Add(button);
}
else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox) else if (settingElement.Element is DesktopMagicPluginAPI.Inputs.CheckBox eCheckBox)
{ {
CheckBox checkBox = new() CheckBox checkBox = new()
{ {
IsChecked = eCheckBox.Value, IsChecked = eCheckBox.Value,
Width = optionsPanel.ActualWidth - label.ActualWidth,
Style = (Style)FindResource("MaterialDesignDarkCheckBox"), Style = (Style)FindResource("MaterialDesignDarkCheckBox"),
VerticalAlignment = VerticalAlignment.Center VerticalAlignment = VerticalAlignment.Center,
HorizontalAlignment = HorizontalAlignment.Stretch
}; };
checkBox.Click += (_s, _e) => checkBox.Click += (_s, _e) =>
{ {
@@ -486,8 +518,8 @@ namespace DesktopMagic
{ {
Text = eTextBox.Value, Text = eTextBox.Value,
TextWrapping = TextWrapping.Wrap, TextWrapping = TextWrapping.Wrap,
Width = optionsPanel.ActualWidth - label.ActualWidth, VerticalAlignment = VerticalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center HorizontalAlignment = HorizontalAlignment.Stretch
}; };
textBox.TextChanged += (_s, _e) => textBox.TextChanged += (_s, _e) =>
{ {
@@ -510,8 +542,8 @@ namespace DesktopMagic
Value = eIntegerUpDown.Value, Value = eIntegerUpDown.Value,
Minimum = eIntegerUpDown.Minimum, Minimum = eIntegerUpDown.Minimum,
Maximum = eIntegerUpDown.Maximum, Maximum = eIntegerUpDown.Maximum,
Width = optionsPanel.ActualWidth - label.ActualWidth, VerticalAlignment = VerticalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center HorizontalAlignment = HorizontalAlignment.Stretch
}; };
integerUpDown.ValueChanged += (_s, _e) => integerUpDown.ValueChanged += (_s, _e) =>
{ {
@@ -536,8 +568,8 @@ namespace DesktopMagic
Maximum = eSlider.Maximum, Maximum = eSlider.Maximum,
TickFrequency = 1, TickFrequency = 1,
IsSnapToTickEnabled = true, IsSnapToTickEnabled = true,
Width = optionsPanel.ActualWidth - label.ActualWidth, VerticalAlignment = VerticalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center HorizontalAlignment = HorizontalAlignment.Stretch
}; };
slider.ValueChanged += (_s, _e) => slider.ValueChanged += (_s, _e) =>
{ {
@@ -16,5 +16,5 @@ C:\Users\David\Programmieren\DesktopMagic\src\DesktopMagic\App.xaml
226605658444 226605658444
CalendarWindow.xaml;CpuUsageWindow.xaml;DateWindow.xaml;InputDialog.xaml;MainWindow.xaml;MusicVisualizerWindow.xaml;Plugin\PluginWindow.xaml;Resources\StringResources.de.xaml;Resources\StringResources.en.xaml;TimeWindow.xaml; CalendarWindow.xaml;CpuUsageWindow.xaml;DateWindow.xaml;InputDialog.xaml;MainWindow.xaml;MusicVisualizerWindow.xaml;Plugin\PluginWindow.xaml;Resources\StringResources.de.xaml;Resources\StringResources.en.xaml;TimeWindow.xaml;
False True
@@ -86,7 +86,7 @@ namespace DesktopMagic {
return; return;
} }
_contentLoaded = true; _contentLoaded = true;
System.Uri resourceLocater = new System.Uri("/DesktopMagic;component/inputdialog.xaml", System.UriKind.Relative); System.Uri resourceLocater = new System.Uri("/DesktopMagic;V1.0.0.0;component/inputdialog.xaml", System.UriKind.Relative);
#line 1 "..\..\..\InputDialog.xaml" #line 1 "..\..\..\InputDialog.xaml"
System.Windows.Application.LoadComponent(this, resourceLocater); System.Windows.Application.LoadComponent(this, resourceLocater);
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E2A0CEAB1CE4E799C8F11878BEEF4140351A3388" #pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "C65BB0CCBD38447F44B1617C45B72B340536B1CC"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// Dieser Code wurde von einem Tool generiert. // Dieser Code wurde von einem Tool generiert.
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E2A0CEAB1CE4E799C8F11878BEEF4140351A3388" #pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "C65BB0CCBD38447F44B1617C45B72B340536B1CC"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// Dieser Code wurde von einem Tool generiert. // Dieser Code wurde von einem Tool generiert.
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E2A0CEAB1CE4E799C8F11878BEEF4140351A3388" #pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "C65BB0CCBD38447F44B1617C45B72B340536B1CC"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// Dieser Code wurde von einem Tool generiert. // Dieser Code wurde von einem Tool generiert.
@@ -1,4 +1,4 @@
#pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "E2A0CEAB1CE4E799C8F11878BEEF4140351A3388" #pragma checksum "..\..\..\MainWindow.xaml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "C65BB0CCBD38447F44B1617C45B72B340536B1CC"
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// <auto-generated> // <auto-generated>
// Dieser Code wurde von einem Tool generiert. // Dieser Code wurde von einem Tool generiert.
+18 -3
View File
@@ -8,8 +8,11 @@ namespace DesktopMagicPlugin.Test
{ {
public class PluginScript : Plugin public class PluginScript : Plugin
{ {
[Element("Heading")] [Element]
private Heading heading = new Heading(""); private Label heading = new Label("Heading", true);
[Element]
private Label label = new Label("");
[Element("Slider:")] [Element("Slider:")]
private Slider slider = new Slider(1, 23, 4); private Slider slider = new Slider(1, 23, 4);
@@ -17,10 +20,22 @@ namespace DesktopMagicPlugin.Test
[Element("Text:")] [Element("Text:")]
private TextBox textBox = new TextBox("abc"); private TextBox textBox = new TextBox("abc");
[Element]
private Button button = new Button("Press me!");
public override int UpdateInterval { get; set; }
public PluginScript() public PluginScript()
{ {
slider.OnValueChanged += Slider_OnValueChanged; slider.OnValueChanged += Slider_OnValueChanged;
textBox.OnValueChanged += TextBox_OnValueChanged; textBox.OnValueChanged += TextBox_OnValueChanged;
button.OnClick += Button_OnClick; ;
}
private void Button_OnClick()
{
Debug.WriteLine("Button pressed");
Application.UpdateWindow();
} }
private void TextBox_OnValueChanged() private void TextBox_OnValueChanged()
@@ -42,7 +57,7 @@ namespace DesktopMagicPlugin.Test
g.Clear(Application.Color); g.Clear(Application.Color);
g.DrawString(str, new Font("arial", 10), Brushes.Black, new PointF(0, 0)); g.DrawString(str, new Font("arial", 10), Brushes.Black, new PointF(0, 0));
heading.Value = str; label.Value = str;
slider.Value++; slider.Value++;
return bmp; return bmp;
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DesktopMagicPluginAPI.Inputs
{
public class Button : Element
{
public event Action OnClick;
private string _value;
public string Value
{
get => _value;
set
{
if (_value != value)
{
_value = value;
ValueChanged();
}
}
}
public Button(string value)
{
Value = value;
}
public void Click()
{
OnClick?.Invoke();
}
}
}
@@ -9,7 +9,7 @@ namespace DesktopMagicPluginAPI.Inputs
public string Name { get; } public string Name { get; }
public int OrderIndex { get; } public int OrderIndex { get; }
public ElementAttribute(string name, int orderIndex = 0) public ElementAttribute(string name = "", int orderIndex = 0)
{ {
Name = name; Name = name;
OrderIndex = orderIndex; OrderIndex = orderIndex;
@@ -1,6 +1,6 @@
namespace DesktopMagicPluginAPI.Inputs namespace DesktopMagicPluginAPI.Inputs
{ {
public class Heading : Element public class Label : Element
{ {
private string _value; private string _value;
@@ -17,9 +17,12 @@
} }
} }
public Heading(string value) public bool Bold { get; set; }
public Label(string value, bool bold = false)
{ {
Value = value; Value = value;
Bold = bold;
} }
} }
} }
@@ -1 +1 @@
3d351e819578d1d8c8cf3fc4ddef05ac96911424 ced4ac85c0c7d0fe87e126147d10f5c33d432ea7
@@ -1 +1 @@
78b084028688b20b372609aac30267390d5f6d25 801158c4d5ba4b4a8b0e6e57ad9e67f56077c71a