mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Fixed custom controls not responding to changes, fixed title bar interaciton
This commit is contained in:
1 parent
02e85af4af
commit
82b41425aa
20 files changed
+141
-120
No files matched your search
@@ -28,6 +28,7 @@ public partial class ArtemisIcon : UserControl
|
||||
InitializeComponent();
|
||||
DetachedFromLogicalTree += OnDetachedFromLogicalTree;
|
||||
LayoutUpdated += OnLayoutUpdated;
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -86,6 +87,12 @@ public partial class ArtemisIcon : UserControl
|
||||
contentControl.Height = Bounds.Height;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == IconProperty || e.Property == FillProperty)
|
||||
Update();
|
||||
}
|
||||
|
||||
private void OnDetachedFromLogicalTree(object? sender, LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
@@ -109,11 +116,7 @@ public partial class ArtemisIcon : UserControl
|
||||
public object? Icon
|
||||
{
|
||||
get => GetValue(IconProperty);
|
||||
set
|
||||
{
|
||||
SetValue(IconProperty, value);
|
||||
Update();
|
||||
}
|
||||
set => SetValue(IconProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -129,11 +132,7 @@ public partial class ArtemisIcon : UserControl
|
||||
public bool Fill
|
||||
{
|
||||
get => GetValue(FillProperty);
|
||||
set
|
||||
{
|
||||
SetValue(FillProperty, value);
|
||||
Update();
|
||||
}
|
||||
set => SetValue(FillProperty, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -38,12 +38,14 @@ public class DeviceVisualizer : Control
|
||||
_deviceVisualizerLeds = new List<DeviceVisualizerLed>();
|
||||
|
||||
PointerReleased += OnPointerReleased;
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Render(DrawingContext drawingContext)
|
||||
{
|
||||
if (Device == null)
|
||||
if (Device == null || _deviceBounds.Width == 0 || _deviceBounds.Height == 0)
|
||||
return;
|
||||
|
||||
// Determine the scale required to fit the desired size of the control
|
||||
@@ -54,11 +56,11 @@ public class DeviceVisualizer : Control
|
||||
{
|
||||
// Scale the visualization in the desired bounding box
|
||||
if (Bounds.Width > 0 && Bounds.Height > 0)
|
||||
boundsPush = drawingContext.PushPreTransform(Matrix.CreateScale(scale, scale));
|
||||
boundsPush = drawingContext.PushTransform(Matrix.CreateScale(scale, scale));
|
||||
|
||||
// Apply device rotation
|
||||
using DrawingContext.PushedState translationPush = drawingContext.PushPreTransform(Matrix.CreateTranslation(0 - _deviceBounds.Left, 0 - _deviceBounds.Top));
|
||||
using DrawingContext.PushedState rotationPush = drawingContext.PushPreTransform(Matrix.CreateRotation(Matrix.ToRadians(Device.Rotation)));
|
||||
using DrawingContext.PushedState translationPush = drawingContext.PushTransform(Matrix.CreateTranslation(0 - _deviceBounds.Left, 0 - _deviceBounds.Top));
|
||||
using DrawingContext.PushedState rotationPush = drawingContext.PushTransform(Matrix.CreateRotation(Matrix.ToRadians(Device.Rotation)));
|
||||
|
||||
// Render device and LED images
|
||||
if (_deviceImage != null)
|
||||
@@ -75,7 +77,7 @@ public class DeviceVisualizer : Control
|
||||
lock (_deviceVisualizerLeds)
|
||||
{
|
||||
// Apply device scale
|
||||
using DrawingContext.PushedState scalePush = drawingContext.PushPreTransform(Matrix.CreateScale(Device.Scale, Device.Scale));
|
||||
using DrawingContext.PushedState scalePush = drawingContext.PushTransform(Matrix.CreateScale(Device.Scale, Device.Scale));
|
||||
foreach (DeviceVisualizerLed deviceVisualizerLed in _deviceVisualizerLeds)
|
||||
deviceVisualizerLed.RenderGeometry(drawingContext, false);
|
||||
}
|
||||
@@ -152,6 +154,12 @@ public class DeviceVisualizer : Control
|
||||
OnClicked(e);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == DeviceProperty)
|
||||
SetupForDevice();
|
||||
}
|
||||
|
||||
private void DevicePropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
Dispatcher.UIThread.Post(SetupForDevice, DispatcherPriority.Background);
|
||||
@@ -169,18 +177,14 @@ public class DeviceVisualizer : Control
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<ArtemisDevice?> DeviceProperty =
|
||||
AvaloniaProperty.Register<DeviceVisualizer, ArtemisDevice?>(nameof(Device));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="ArtemisDevice" /> to display
|
||||
/// </summary>
|
||||
public ArtemisDevice? Device
|
||||
{
|
||||
get => GetValue(DeviceProperty);
|
||||
set
|
||||
{
|
||||
SetValue(DeviceProperty, value);
|
||||
SetupForDevice();
|
||||
}
|
||||
set => SetValue(DeviceProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</UserControl.Styles>
|
||||
|
||||
<Panel>
|
||||
<controls:NumberBox Name="NumberBox"
|
||||
<controls:NumberBox Name="InnerNumberBox"
|
||||
AcceptsExpression="True"
|
||||
LargeChange="{Binding $parent[sharedControls:DraggableNumberBox].LargeChange}"
|
||||
SmallChange="{Binding $parent[sharedControls:DraggableNumberBox].SmallChange}"
|
||||
|
||||
@@ -68,12 +68,13 @@ public partial class DraggableNumberBox : UserControl
|
||||
public DraggableNumberBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
NumberBox.Value = Value;
|
||||
InnerNumberBox.Value = Value;
|
||||
|
||||
PointerPressed += OnPointerPressed;
|
||||
PointerMoved += OnPointerMoved;
|
||||
PointerReleased += OnPointerReleased;
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
|
||||
AddHandler(KeyUpEvent, HandleKeyUp, RoutingStrategies.Direct | RoutingStrategies.Tunnel | RoutingStrategies.Bubble, true);
|
||||
}
|
||||
|
||||
@@ -83,11 +84,7 @@ public partial class DraggableNumberBox : UserControl
|
||||
public double Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set
|
||||
{
|
||||
SetValue(ValueProperty, value);
|
||||
SetNumberBoxValue(value);
|
||||
}
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,11 +162,11 @@ public partial class DraggableNumberBox : UserControl
|
||||
|
||||
private void SetNumberBoxValue(double value)
|
||||
{
|
||||
if (!(Math.Abs(NumberBox.Value - Value) > 0.00001))
|
||||
if (!(Math.Abs(InnerNumberBox.Value - Value) > 0.00001))
|
||||
return;
|
||||
|
||||
_updating = true;
|
||||
NumberBox.Value = Value;
|
||||
InnerNumberBox.Value = Value;
|
||||
_updating = false;
|
||||
}
|
||||
|
||||
@@ -182,7 +179,7 @@ public partial class DraggableNumberBox : UserControl
|
||||
private void OnPointerPressed(object? sender, PointerPressedEventArgs e)
|
||||
{
|
||||
PointerPoint point = e.GetCurrentPoint(this);
|
||||
_inputTextBox = NumberBox.FindDescendantOfType<TextBox>();
|
||||
_inputTextBox = InnerNumberBox.FindDescendantOfType<TextBox>();
|
||||
_moved = false;
|
||||
_startX = point.Position.X;
|
||||
_lastX = point.Position.X;
|
||||
@@ -246,6 +243,12 @@ public partial class DraggableNumberBox : UserControl
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == ValueProperty)
|
||||
SetNumberBoxValue(Value);
|
||||
}
|
||||
|
||||
private void NumberBox_OnValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args)
|
||||
{
|
||||
@@ -254,17 +257,17 @@ public partial class DraggableNumberBox : UserControl
|
||||
|
||||
if (args.NewValue < Minimum)
|
||||
{
|
||||
NumberBox.Value = Minimum;
|
||||
InnerNumberBox.Value = Minimum;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args.NewValue > Maximum)
|
||||
{
|
||||
NumberBox.Value = Maximum;
|
||||
InnerNumberBox.Value = Maximum;
|
||||
return;
|
||||
}
|
||||
|
||||
if (Math.Abs(Value - NumberBox.Value) > 0.00001)
|
||||
Value = NumberBox.Value;
|
||||
if (Math.Abs(Value - InnerNumberBox.Value) > 0.00001)
|
||||
Value = InnerNumberBox.Value;
|
||||
}
|
||||
}
|
||||
@@ -30,21 +30,26 @@ public partial class EnumComboBox : UserControl
|
||||
/// </summary>
|
||||
public EnumComboBox()
|
||||
{
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == ValueProperty)
|
||||
{
|
||||
UpdateValues();
|
||||
UpdateSelection();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the currently selected value
|
||||
/// </summary>
|
||||
public object? Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set
|
||||
{
|
||||
SetValue(ValueProperty, value);
|
||||
UpdateValues();
|
||||
UpdateSelection();
|
||||
}
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
private void OnSelectionChanged(object? sender, SelectionChangedEventArgs e)
|
||||
|
||||
@@ -94,6 +94,8 @@ public class GradientPicker : TemplatedControl
|
||||
|
||||
SelectedColorStop = EditingColorGradient.ElementAtOrDefault(index);
|
||||
});
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -102,11 +104,7 @@ public class GradientPicker : TemplatedControl
|
||||
public ColorGradient ColorGradient
|
||||
{
|
||||
get => GetValue(ColorGradientProperty);
|
||||
set
|
||||
{
|
||||
SetValue(ColorGradientProperty, value);
|
||||
ApplyToField();
|
||||
}
|
||||
set => SetValue(ColorGradientProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -342,4 +340,10 @@ public class GradientPicker : TemplatedControl
|
||||
EditingColorGradient.Randomize(6);
|
||||
SelectedColorStop = EditingColorGradient.First();
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == ColorGradientProperty)
|
||||
ApplyToField();
|
||||
}
|
||||
}
|
||||
@@ -47,17 +47,19 @@ public class GradientPickerButton : TemplatedControl
|
||||
private Button? _button;
|
||||
private ColorGradient? _lastColorGradient;
|
||||
|
||||
/// <inheritdoc />
|
||||
public GradientPickerButton()
|
||||
{
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the color gradient.
|
||||
/// </summary>
|
||||
public ColorGradient? ColorGradient
|
||||
{
|
||||
get => GetValue(ColorGradientProperty);
|
||||
set
|
||||
{
|
||||
SetValue(ColorGradientProperty, value);
|
||||
Subscribe();
|
||||
}
|
||||
set => SetValue(ColorGradientProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -175,6 +177,12 @@ public class GradientPickerButton : TemplatedControl
|
||||
LinearGradientBrush.GradientStops = collection;
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == ColorGradientProperty)
|
||||
Subscribe();
|
||||
}
|
||||
|
||||
#region Overrides of Visual
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@@ -19,21 +19,24 @@ namespace Artemis.UI.Shared;
|
||||
/// </summary>
|
||||
public partial class HotkeyBox : UserControl
|
||||
{
|
||||
private readonly TextBox _displayTextBox;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="HotkeyBox" /> class
|
||||
/// </summary>
|
||||
public HotkeyBox()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_displayTextBox = this.Find<TextBox>("DisplayTextBox");
|
||||
_displayTextBox.KeyDown += DisplayTextBoxOnKeyDown;
|
||||
_displayTextBox.KeyUp += DisplayTextBoxOnKeyUp;
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
DisplayTextBox.KeyDown += DisplayTextBoxOnKeyDown;
|
||||
DisplayTextBox.KeyUp += DisplayTextBoxOnKeyUp;
|
||||
UpdateDisplayTextBox();
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == HotkeyProperty)
|
||||
UpdateDisplayTextBox();
|
||||
}
|
||||
|
||||
private void DisplayTextBoxOnKeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.Key >= Key.LeftShift && e.Key <= Key.RightAlt)
|
||||
@@ -44,7 +47,7 @@ public partial class HotkeyBox : UserControl
|
||||
Hotkey.Modifiers = (KeyboardModifierKey?) e.KeyModifiers;
|
||||
UpdateDisplayTextBox();
|
||||
HotkeyChanged?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
|
||||
e.Handled = true;
|
||||
}
|
||||
|
||||
@@ -64,8 +67,8 @@ public partial class HotkeyBox : UserControl
|
||||
if (Hotkey?.Key != null)
|
||||
display = string.IsNullOrEmpty(display) ? Hotkey.Key.ToString() : $"{display}+{Hotkey.Key}";
|
||||
|
||||
_displayTextBox.Text = display;
|
||||
_displayTextBox.CaretIndex = _displayTextBox.Text?.Length ?? 0;
|
||||
DisplayTextBox.Text = display;
|
||||
DisplayTextBox.CaretIndex = DisplayTextBox.Text?.Length ?? 0;
|
||||
}
|
||||
|
||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
||||
@@ -101,11 +104,7 @@ public partial class HotkeyBox : UserControl
|
||||
public Hotkey? Hotkey
|
||||
{
|
||||
get => GetValue(HotkeyProperty);
|
||||
set
|
||||
{
|
||||
SetValue(HotkeyProperty, value);
|
||||
UpdateDisplayTextBox();
|
||||
}
|
||||
set => SetValue(HotkeyProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -69,6 +69,14 @@ public class SelectionRectangle : Control
|
||||
{
|
||||
AffectsRender<TextBlock>(BackgroundProperty, BorderBrushProperty, BorderThicknessProperty);
|
||||
IsHitTestVisible = false;
|
||||
|
||||
PropertyChanged += OnPropertyChanged;
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(object? sender, AvaloniaPropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.Property == InputElementProperty)
|
||||
SubscribeToInputElement();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -113,11 +121,7 @@ public class SelectionRectangle : Control
|
||||
public InputElement? InputElement
|
||||
{
|
||||
get => GetValue(InputElementProperty);
|
||||
set
|
||||
{
|
||||
SetValue(InputElementProperty, value);
|
||||
SubscribeToInputElement();
|
||||
}
|
||||
set => SetValue(InputElementProperty, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -27,14 +27,7 @@
|
||||
<Setter Property="CornerRadius" Value="8 0 0 0" />
|
||||
<Setter Property="ClipToBounds" Value="True" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="Border#TitleBar">
|
||||
<Setter Property="Height" Value="40"></Setter>
|
||||
</Style>
|
||||
<Style Selector="Window:windows Border#TitleBar">
|
||||
<Setter Property="Margin" Value="0 0 138 0"></Setter>
|
||||
</Style>
|
||||
|
||||
|
||||
<Style Selector="Border.card">
|
||||
<Setter Property="Padding" Value="16" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
|
||||
|
||||
Reference in new issue
Block a user