diff --git a/ColorSelector/ColorSelector.cs b/ColorSelector/ColorSelector.cs
index 018b814..d49a2b9 100644
--- a/ColorSelector/ColorSelector.cs
+++ b/ColorSelector/ColorSelector.cs
@@ -333,12 +333,12 @@ public ColorSelector()
private void CustomColorsLimitDecrement(object? obj)
{
- CustomColorsLimit = Math.Clamp(CustomColorsLimit - 1, 1, CustomColorsLimit_MAX);
+ CustomColorsLimit = Math.Clamp(CustomColorsLimit - 1, 1, (CustomColorsLimited) ? CustomColorsLimit_MAX : CustomColorsLimit_SAFETY_MAX);
}
private void CustomColorsLimitIncrement(object? obj)
{
- CustomColorsLimit = Math.Clamp(CustomColorsLimit + 1, 1, CustomColorsLimit_MAX);
+ CustomColorsLimit = Math.Clamp(CustomColorsLimit + 1, 1, (CustomColorsLimited) ? CustomColorsLimit_MAX : CustomColorsLimit_SAFETY_MAX);
}
private void ColorColumnsDecrement(object? obj)
@@ -485,10 +485,11 @@ public override void OnApplyTemplate()
public const double DisplayScale_MIN = .5;
public const double DisplayScale_MAX = 2.0;
- public const int CustomColorsLimit_DEFAULT = 10;
+ public const int CustomColorsLimit_DEFAULT = 20;
public const int CustomColorsLimit_MAX = 1000;
+ public const int CustomColorsLimit_SAFETY_MAX = 16383; // Memory/performance safety hard-limit
- public const int ColorColumns_DEFAULT = 5;
+ public const int ColorColumns_DEFAULT = 10;
public const int ColorColumns_MAX = 100;
public void ToggleMenu(object? obj)
@@ -516,6 +517,37 @@ private void DeleteCustomColors(object? obj)
CustomColors.Clear();
}
+ ///
+ /// Returns the int.CompareTo() result for checking the count of a collection of colors.
+ /// If CustomColorsLimited is set to true, CustomColorsLimit is the comparison value;
+ /// Else, CustomColorsLimit_SAFETY_MAX is the comparison value.
+ ///
+ ///
+ private int CustomColorsLimitReached(IEnumerable? colorCollection = null)
+ {
+ var colleciton = (colorCollection == null) ? CustomColors : colorCollection;
+ if (CustomColorsLimited)
+ return colleciton.Count().CompareTo(CustomColorsLimit);
+ else
+ return colleciton.Count().CompareTo(CustomColorsLimit_SAFETY_MAX);
+ }
+
+ private int CustomColorsLimitReached()
+ {
+ if (CustomColorsLimited)
+ return CustomColors.Count.CompareTo(CustomColorsLimit);
+ else
+ return CustomColors.Count.CompareTo(CustomColorsLimit_SAFETY_MAX);
+ }
+
+ private int GetCustomColorsLimit()
+ {
+ if (CustomColorsLimited)
+ return CustomColorsLimit;
+ else
+ return CustomColorsLimit_SAFETY_MAX;
+ }
+
///
/// Saves custom colors up to a certain limit; once limit is reached,
/// colors are replaced in FILO (First In, Last Out) order;
@@ -523,7 +555,7 @@ private void DeleteCustomColors(object? obj)
///
private void SaveCustomColor(object? obj)
{
- if (CustomColorsLimited && CustomColors.Count >= CustomColorsLimit)
+ if (CustomColorsLimitReached() >= 0)
CustomColors.RemoveAt(CustomColors.Count - 1);
CustomColors.Insert(0, GetColorFromRawColor());
@@ -2334,10 +2366,14 @@ private void ImportFromFile(ImportType importType, string filePath = "")
switch (importType)
{
case ImportType.CustomColors:
- CustomColors = new ObservableCollection(collection);
+ CustomColors.Clear();
+ for (int i = 0; i < collection.Count() && i < GetCustomColorsLimit(); ++i)
+ CustomColors.Add(collection.ElementAt(i));
break;
case ImportType.PresetColors:
- PresetColors = new ObservableCollection(collection);
+ PresetColors.Clear();
+ for (int i = 0; i < collection.Count() && i < CustomColorsLimit_SAFETY_MAX; ++i)
+ PresetColors.Add(collection.ElementAt(i));
break;
default:
break;
@@ -5817,10 +5853,13 @@ private static void CustomColorsLimitedChanged(DependencyObject d, DependencyPro
private static void UpdateCustomColors(ColorSelector selector)
{
- selector.CustomColorsLimitReadout = (selector.CustomColorsLimited) ? selector.CustomColorsLimit.ToString() : "Unlimited";
- if (selector.CustomColorsLimited && selector.CustomColors.Count >= selector.CustomColorsLimit)
+ selector.CustomColorsLimitReadout = (selector.CustomColorsLimited) ? selector.CustomColorsLimit.ToString() : "Unlimited*";
+ if (selector.CustomColorsLimitReached() >= 1)
{
- selector.CustomColors = new(selector.CustomColors.Take(selector.CustomColorsLimit));
+ var items = new List(selector.CustomColors.Take(selector.CustomColorsLimit));
+ selector.CustomColors.Clear();
+ foreach (var item in items)
+ selector.CustomColors.Add(item);
}
}
diff --git a/ColorSelector/Themes/Generic.xaml b/ColorSelector/Themes/Generic.xaml
index 73f74d6..76e4bbc 100644
--- a/ColorSelector/Themes/Generic.xaml
+++ b/ColorSelector/Themes/Generic.xaml
@@ -83,8 +83,8 @@
PresentationOptions:Freeze="True"
TileMode="FlipX"
AlignmentX="Center"
- ViewportUnits="RelativeToBoundingBox"
- Viewport="0,0,.15,.15">
+ ViewportUnits="Absolute"
+ Viewport="0,0,10,10">
@@ -93,7 +93,7 @@
-
@@ -104,7 +104,7 @@
-
@@ -1469,7 +1469,7 @@
+ Value="{x:Null}" />
-
+
@@ -2164,13 +2164,12 @@
-
+
+ ItemsPanel="{StaticResource ColorListItemPanelTemplate}">
+
+
+
+
+
+
+
+
+
+
@@ -2620,10 +2649,11 @@
IsTabStop="True"
Height="32"
Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:ColorSelector}}, Path=CustomColorsVisible, Mode=OneWay, Converter={StaticResource b2v}}">
-
+
-
+
-
+ ItemsPanel="{StaticResource ColorListItemPanelTemplate}">
+
+
+
+
+
+
+
+
+
+
@@ -3059,13 +3121,13 @@
-
+
-
-
@@ -3106,7 +3168,18 @@
-
+
+
+
+
+
@@ -3126,9 +3199,11 @@