mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Color picker - Avoid overlapping colors
This commit is contained in:
1 parent
212d13c1c8
commit
3efb97eedd
4 files changed
+104
-3
No files matched your search
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Xaml.Interactivity;
|
||||
using FluentAvalonia.UI.Controls;
|
||||
|
||||
namespace Artemis.UI.Shared.Behaviors;
|
||||
|
||||
/// <summary>
|
||||
/// Represents a behavior that can be used to make a numeric up down only update it's binding on focus loss.
|
||||
/// </summary>
|
||||
public class LostFocusNumericUpDownBindingBehavior : Behavior<NumericUpDown>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the binding.
|
||||
/// </summary>
|
||||
public static readonly StyledProperty<double> ValueProperty = AvaloniaProperty.Register<LostFocusNumericUpDownBindingBehavior, double>(
|
||||
nameof(Value), defaultBindingMode: BindingMode.TwoWay);
|
||||
|
||||
static LostFocusNumericUpDownBindingBehavior()
|
||||
{
|
||||
ValueProperty.Changed.Subscribe(e => ((LostFocusNumericUpDownBindingBehavior) e.Sender).OnBindingValueChanged());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the value of the binding.
|
||||
/// </summary>
|
||||
public double Value
|
||||
{
|
||||
get => GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAttached()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.LostFocus += OnLostFocus;
|
||||
base.OnAttached();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnDetaching()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.LostFocus -= OnLostFocus;
|
||||
base.OnDetaching();
|
||||
}
|
||||
|
||||
private void OnLostFocus(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
Value = AssociatedObject.Value;
|
||||
}
|
||||
|
||||
private void OnBindingValueChanged()
|
||||
{
|
||||
if (AssociatedObject != null)
|
||||
AssociatedObject.Value = Value;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
xmlns:core="clr-namespace:Artemis.Core;assembly=Artemis.Core"
|
||||
xmlns:fluent="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters"
|
||||
xmlns:gradientPicker="clr-namespace:Artemis.UI.Shared.Controls.GradientPicker">
|
||||
xmlns:gradientPicker="clr-namespace:Artemis.UI.Shared.Controls.GradientPicker"
|
||||
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors">
|
||||
<Styles.Resources>
|
||||
<VisualBrush x:Key="LightCheckerboardBrush" TileMode="Tile" Stretch="Uniform" DestinationRect="3,0,10,10">
|
||||
<VisualBrush.Visual>
|
||||
@@ -198,7 +199,11 @@
|
||||
<Border CornerRadius="4" Margin="-2" Background="{Binding Color, Converter={StaticResource SKColorToBrushConverter}}" />
|
||||
</Border>
|
||||
<TextBox Grid.Column="1" Text="{Binding Color, Converter={StaticResource SKColorToStringConverter}}" />
|
||||
<NumericUpDown Grid.Column="2" Value="{Binding Position}" FormatString="F3" ShowButtonSpinner="False" Margin="5 0" />
|
||||
<NumericUpDown Grid.Column="2" FormatString="F3" ShowButtonSpinner="False" Margin="5 0" Minimum="0" Maximum="1" Increment="0.01">
|
||||
<Interaction.Behaviors>
|
||||
<behaviors:LostFocusNumericUpDownBindingBehavior Value="{Binding Position}"/>
|
||||
</Interaction.Behaviors>
|
||||
</NumericUpDown>
|
||||
<Button Name="DeleteButton"
|
||||
Grid.Column="3"
|
||||
Classes="icon-button"
|
||||
|
||||
Reference in new issue
Block a user