From 40bb60164ede75246e9b1d34da2e538d8560cc63 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Wed, 17 Jul 2024 22:56:54 +0800
Subject: [PATCH] chore: add avalonia button and brush demo.
---
.../HandyControlDemo_Avalonia/App.axaml.cs | 6 +-
.../Data/DemoInfo.json | 2 +-
.../HandyControlDemo_Avalonia.csproj | 4 +
.../UserControl/Main/LeftMainContent.axaml | 93 +++--
.../UserControl/Styles/BrushDemoCtl.axaml | 117 ++++++
.../UserControl/Styles/BrushDemoCtl.axaml.cs | 9 +
.../UserControl/Styles/ButtonDemoCtl.axaml | 83 +++-
.../ViewModel/Main/MainViewModel.cs | 4 +-
.../Controls/Panel/UniformSpacingPanel.cs | 373 ++++++++++++++++++
.../Data/Enum/VisualWrapping.cs | 7 +
.../HandyControl_Avalonia/Data/PanelUvSize.cs | 69 ++++
.../HandyControl_Avalonia.csproj | 5 +-
.../Themes/Styles/Button.axaml | 177 ++++-----
.../Themes/Styles/Label.axaml | 94 +++++
.../Themes/Styles/ListBox.axaml | 2 +
.../Themes/Styles/ListBoxItem.axaml | 26 +-
.../Themes/Styles/Style.axaml | 1 +
.../Themes/Styles/TabControl.axaml | 62 +--
.../Themes/Styles/TabItem.axaml | 55 +--
.../Themes/Styles/Window.axaml | 2 +-
.../Tools/Helper/MathHelper.cs | 16 +
.../HandyControl_Net_40/Themes/Theme.xaml | 4 +-
.../Controls/Panel/UniformSpacingPanel.cs | 104 +++--
23 files changed, 1021 insertions(+), 294 deletions(-)
create mode 100644 src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml
create mode 100644 src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml.cs
create mode 100644 src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs
create mode 100644 src/Avalonia/HandyControl_Avalonia/Data/Enum/VisualWrapping.cs
create mode 100644 src/Avalonia/HandyControl_Avalonia/Data/PanelUvSize.cs
create mode 100644 src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml
create mode 100644 src/Avalonia/HandyControl_Avalonia/Tools/Helper/MathHelper.cs
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/App.axaml.cs b/src/Avalonia/HandyControlDemo_Avalonia/App.axaml.cs
index 1bb6fd369..74902c4b9 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/App.axaml.cs
+++ b/src/Avalonia/HandyControlDemo_Avalonia/App.axaml.cs
@@ -1,4 +1,5 @@
-using Avalonia;
+using System.Globalization;
+using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Data.Core.Plugins;
using Avalonia.Markup.Xaml;
@@ -6,7 +7,7 @@
namespace HandyControlDemo;
-public partial class App : Application
+public class App : Application
{
public override void Initialize()
{
@@ -15,6 +16,7 @@ public override void Initialize()
public override void OnFrameworkInitializationCompleted()
{
+ Properties.Langs.Lang.Culture = new CultureInfo("en");
BindingPlugins.DataValidators.RemoveAt(0);
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json b/src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json
index b2f688de9..75d68c351 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json
+++ b/src/Avalonia/HandyControlDemo_Avalonia/Data/DemoInfo.json
@@ -1,7 +1,7 @@
[
{
"title": "Styles",
- "selectedIndex": 0,
+ "selectedIndex": -1,
"group": false,
"demoItemList": [
[ "Brush", "BrushDemoCtl", "Brush.Brush", "", "" ],
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj b/src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj
index 53ad41f1b..eeae15a11 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj
+++ b/src/Avalonia/HandyControlDemo_Avalonia/HandyControlDemo_Avalonia.csproj
@@ -57,6 +57,10 @@
ButtonDemoCtrl.axaml
+
+ BoderDemoCtl.axaml
+ Code
+
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Main/LeftMainContent.axaml b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Main/LeftMainContent.axaml
index 67246a934..7bbdd25a4 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Main/LeftMainContent.axaml
+++ b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Main/LeftMainContent.axaml
@@ -6,46 +6,55 @@
Margin="16,16,0,16"
CornerRadius="10"
Effect="{StaticResource EffectShadow4}">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml
new file mode 100644
index 000000000..0d378e458
--- /dev/null
+++ b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml
@@ -0,0 +1,117 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml.cs b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml.cs
new file mode 100644
index 000000000..5858fe93b
--- /dev/null
+++ b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/BrushDemoCtl.axaml.cs
@@ -0,0 +1,9 @@
+namespace HandyControlDemo.UserControl;
+
+public partial class BrushDemoCtl : Avalonia.Controls.UserControl
+{
+ public BrushDemoCtl()
+ {
+ InitializeComponent();
+ }
+}
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/ButtonDemoCtl.axaml b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/ButtonDemoCtl.axaml
index fd662312f..079ac8134 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/ButtonDemoCtl.axaml
+++ b/src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/ButtonDemoCtl.axaml
@@ -1,28 +1,69 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControlDemo_Avalonia/ViewModel/Main/MainViewModel.cs b/src/Avalonia/HandyControlDemo_Avalonia/ViewModel/Main/MainViewModel.cs
index c885609b2..2f5bd4d3d 100644
--- a/src/Avalonia/HandyControlDemo_Avalonia/ViewModel/Main/MainViewModel.cs
+++ b/src/Avalonia/HandyControlDemo_Avalonia/ViewModel/Main/MainViewModel.cs
@@ -69,7 +69,7 @@ private void UpdateLeftContent()
return;
}
- ContentTitle = Lang.ResourceManager.GetString(DemoItemCurrent.Name);
+ ContentTitle = Lang.ResourceManager.GetString(DemoItemCurrent.Name, Lang.Culture);
});
//load items
@@ -91,7 +91,7 @@ private void SwitchDemo(DemoItemModel item)
}
DemoItemCurrent = item;
- ContentTitle = Lang.ResourceManager.GetString(item.Name);
+ ContentTitle = Lang.ResourceManager.GetString(item.Name, Lang.Culture);
object? demoControl = AssemblyHelper.ResolveByKey(item.TargetCtlName) ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
SubContent = demoControl;
}
diff --git a/src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs b/src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs
new file mode 100644
index 000000000..68d9a7b42
--- /dev/null
+++ b/src/Avalonia/HandyControl_Avalonia/Controls/Panel/UniformSpacingPanel.cs
@@ -0,0 +1,373 @@
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Layout;
+using HandyControl.Data;
+using HandyControl.Tools;
+
+namespace HandyControl.Controls;
+
+public class UniformSpacingPanel : Panel
+{
+ public static readonly StyledProperty OrientationProperty =
+ StackPanel.OrientationProperty.AddOwner();
+
+ public static readonly StyledProperty ChildWrappingProperty =
+ AvaloniaProperty.Register(nameof(ChildWrapping));
+
+ public static readonly StyledProperty SpacingProperty =
+ StackPanel.SpacingProperty.AddOwner(
+ new StyledPropertyMetadata(defaultValue: double.NaN, coerce: CoerceLength));
+
+ public static readonly StyledProperty HorizontalSpacingProperty =
+ AvaloniaProperty.Register(nameof(HorizontalSpacing), defaultValue: double.NaN,
+ coerce: CoerceLength);
+
+ public static readonly StyledProperty VerticalSpacingProperty =
+ AvaloniaProperty.Register(nameof(VerticalSpacing), defaultValue: double.NaN,
+ coerce: CoerceLength);
+
+ public static readonly StyledProperty ItemWidthProperty =
+ AvaloniaProperty.Register(nameof(ItemWidth), defaultValue: double.NaN,
+ coerce: CoerceLength);
+
+ public static readonly StyledProperty ItemHeightProperty =
+ AvaloniaProperty.Register(nameof(ItemHeight), defaultValue: double.NaN,
+ coerce: CoerceLength);
+
+ public static readonly StyledProperty ItemHorizontalAlignmentProperty =
+ AvaloniaProperty.Register(nameof(ItemHorizontalAlignment),
+ defaultValue: HorizontalAlignment.Stretch);
+
+ public static readonly StyledProperty ItemVerticalAlignmentProperty =
+ AvaloniaProperty.Register(nameof(ItemVerticalAlignment),
+ defaultValue: VerticalAlignment.Stretch);
+
+ private Orientation _orientation = Orientation.Horizontal;
+
+ static UniformSpacingPanel()
+ {
+ AffectsMeasure(OrientationProperty);
+ AffectsMeasure(ChildWrappingProperty);
+ AffectsMeasure(SpacingProperty);
+ AffectsMeasure(HorizontalSpacingProperty);
+ AffectsMeasure(VerticalSpacingProperty);
+ AffectsMeasure(ItemWidthProperty);
+ AffectsMeasure(ItemHeightProperty);
+ AffectsMeasure(ItemHorizontalAlignmentProperty);
+ AffectsMeasure(ItemVerticalAlignmentProperty);
+
+ OrientationProperty.Changed.AddClassHandler(OnOrientationChanged);
+ }
+
+ private static void OnOrientationChanged(UniformSpacingPanel self, AvaloniaPropertyChangedEventArgs args)
+ {
+ if (args.NewValue is Orientation orientation)
+ {
+ self._orientation = orientation;
+ }
+ }
+
+ private static double CoerceLength(AvaloniaObject _, double length) => length < 0 ? 0 : length;
+
+ public Orientation Orientation
+ {
+ get => GetValue(OrientationProperty);
+ set => SetValue(OrientationProperty, value);
+ }
+
+ public VisualWrapping ChildWrapping
+ {
+ get => GetValue(ChildWrappingProperty);
+ set => SetValue(ChildWrappingProperty, value);
+ }
+
+ public double Spacing
+ {
+ get => GetValue(SpacingProperty);
+ set => SetValue(SpacingProperty, value);
+ }
+
+ public double HorizontalSpacing
+ {
+ get => GetValue(HorizontalSpacingProperty);
+ set => SetValue(HorizontalSpacingProperty, value);
+ }
+
+ public double VerticalSpacing
+ {
+ get => GetValue(VerticalSpacingProperty);
+ set => SetValue(VerticalSpacingProperty, value);
+ }
+
+ public double ItemWidth
+ {
+ get => GetValue(ItemWidthProperty);
+ set => SetValue(ItemWidthProperty, value);
+ }
+
+ public double ItemHeight
+ {
+ get => GetValue(ItemHeightProperty);
+ set => SetValue(ItemHeightProperty, value);
+ }
+
+ public HorizontalAlignment? ItemHorizontalAlignment
+ {
+ get => GetValue(ItemHorizontalAlignmentProperty);
+ set => SetValue(ItemHorizontalAlignmentProperty, value);
+ }
+
+ public VerticalAlignment? ItemVerticalAlignment
+ {
+ get => GetValue(ItemVerticalAlignmentProperty);
+ set => SetValue(ItemVerticalAlignmentProperty, value);
+ }
+
+ protected override Size MeasureOverride(Size availableSize)
+ {
+ var curLineSize = new PanelUvSize(_orientation);
+ var panelSize = new PanelUvSize(_orientation);
+ var uvConstraint = new PanelUvSize(_orientation, availableSize);
+ double itemWidth = ItemWidth;
+ double itemHeight = ItemHeight;
+ bool itemWidthSet = !double.IsNaN(itemWidth);
+ bool itemHeightSet = !double.IsNaN(itemHeight);
+ var itemHorizontalAlignment = ItemHorizontalAlignment;
+ var itemVerticalAlignment = ItemVerticalAlignment;
+ bool itemHorizontalAlignmentSet = itemHorizontalAlignment != null;
+ bool itemVerticalAlignmentSet = itemVerticalAlignment != null;
+ var childWrapping = ChildWrapping;
+ var spacingSize = GetSpacingSize();
+
+ var childConstraint = new Size(
+ itemWidthSet ? itemWidth : availableSize.Width,
+ itemHeightSet ? itemHeight : availableSize.Height);
+
+ bool isFirst = true;
+
+ if (childWrapping == VisualWrapping.NoWrap)
+ {
+ var layoutSlotSize = new PanelUvSize(_orientation, availableSize);
+
+ if (_orientation == Orientation.Horizontal)
+ {
+ layoutSlotSize.U = double.PositiveInfinity;
+ }
+ else
+ {
+ layoutSlotSize.V = double.PositiveInfinity;
+ }
+
+ for (int i = 0, count = Children.Count; i < count; ++i)
+ {
+ var child = Children[i];
+
+ if (itemHorizontalAlignmentSet)
+ {
+ child.SetCurrentValue(HorizontalAlignmentProperty, itemHorizontalAlignment);
+ }
+
+ if (itemVerticalAlignmentSet)
+ {
+ child.SetCurrentValue(VerticalAlignmentProperty, itemVerticalAlignment);
+ }
+
+ child.Measure(new Size(layoutSlotSize.Width, layoutSlotSize.Height));
+
+ var sz = new PanelUvSize(
+ _orientation,
+ itemWidthSet ? itemWidth : child.DesiredSize.Width,
+ itemHeightSet ? itemHeight : child.DesiredSize.Height);
+
+ curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
+ curLineSize.V = Math.Max(sz.V, curLineSize.V);
+
+ isFirst = false;
+ }
+ }
+ else
+ {
+ for (int i = 0, count = Children.Count; i < count; i++)
+ {
+ var child = Children[i];
+
+ if (itemHorizontalAlignmentSet)
+ {
+ child.SetCurrentValue(HorizontalAlignmentProperty, itemHorizontalAlignment);
+ }
+
+ if (itemVerticalAlignmentSet)
+ {
+ child.SetCurrentValue(VerticalAlignmentProperty, itemVerticalAlignment);
+ }
+
+ child.Measure(childConstraint);
+
+ var sz = new PanelUvSize(
+ _orientation,
+ itemWidthSet ? itemWidth : child.DesiredSize.Width,
+ itemHeightSet ? itemHeight : child.DesiredSize.Height);
+
+ if (MathHelper.GreaterThan(curLineSize.U + sz.U + spacingSize.U, uvConstraint.U))
+ {
+ panelSize.U = Math.Max(curLineSize.U, panelSize.U);
+ panelSize.V += curLineSize.V + spacingSize.V;
+ curLineSize = sz;
+
+ if (MathHelper.GreaterThan(sz.U, uvConstraint.U))
+ {
+ panelSize.U = Math.Max(sz.U, panelSize.U);
+ panelSize.V += sz.V + spacingSize.V;
+ curLineSize = new PanelUvSize(_orientation);
+ }
+ }
+ else
+ {
+ curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
+ curLineSize.V = Math.Max(sz.V, curLineSize.V);
+
+ isFirst = false;
+ }
+ }
+ }
+
+ panelSize.U = Math.Max(curLineSize.U, panelSize.U);
+ panelSize.V += curLineSize.V;
+
+ return new Size(panelSize.Width, panelSize.Height);
+ }
+
+ protected override Size ArrangeOverride(Size finalSize)
+ {
+ int firstInLine = 0;
+ double itemWidth = ItemWidth;
+ double itemHeight = ItemHeight;
+ double accumulatedV = 0;
+ double itemU = _orientation == Orientation.Horizontal ? itemWidth : itemHeight;
+ var curLineSize = new PanelUvSize(_orientation);
+ var uvFinalSize = new PanelUvSize(_orientation, finalSize);
+ bool itemWidthSet = !double.IsNaN(itemWidth);
+ bool itemHeightSet = !double.IsNaN(itemHeight);
+ bool useItemU = _orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet;
+ var childWrapping = ChildWrapping;
+ var spacingSize = GetSpacingSize();
+
+ bool isFirst = true;
+
+ if (childWrapping == VisualWrapping.NoWrap)
+ {
+ ArrangeLine(uvFinalSize.V, useItemU, itemU, spacingSize.U);
+ }
+ else
+ {
+ for (int i = 0, count = Children.Count; i < count; i++)
+ {
+ var child = Children[i];
+
+ var sz = new PanelUvSize(
+ _orientation,
+ itemWidthSet ? itemWidth : child.DesiredSize.Width,
+ itemHeightSet ? itemHeight : child.DesiredSize.Height);
+
+ if (MathHelper.GreaterThan(curLineSize.U + (isFirst ? sz.U : sz.U + spacingSize.U), uvFinalSize.U))
+ {
+ ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU, spacingSize.U);
+
+ accumulatedV += curLineSize.V + spacingSize.V;
+ curLineSize = sz;
+
+ firstInLine = i;
+ }
+ else
+ {
+ curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
+ curLineSize.V = Math.Max(sz.V, curLineSize.V);
+ }
+
+ isFirst = false;
+ }
+
+ if (firstInLine < Children.Count)
+ {
+ ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, Children.Count, useItemU, itemU,
+ spacingSize.U);
+ }
+ }
+
+ return finalSize;
+ }
+
+ private PanelUvSize GetSpacingSize()
+ {
+ double spacing = Spacing;
+
+ if (!double.IsNaN(spacing))
+ {
+ return new PanelUvSize(_orientation, spacing, spacing);
+ }
+
+ double horizontalSpacing = HorizontalSpacing;
+ if (double.IsNaN(horizontalSpacing))
+ {
+ horizontalSpacing = 0;
+ }
+
+ double verticalSpacing = VerticalSpacing;
+ if (double.IsNaN(verticalSpacing))
+ {
+ verticalSpacing = 0;
+ }
+
+ return new PanelUvSize(_orientation, horizontalSpacing, verticalSpacing);
+ }
+
+ private void ArrangeLine(double lineV, bool useItemU, double itemU, double spacing)
+ {
+ double u = 0;
+ bool isHorizontal = _orientation == Orientation.Horizontal;
+
+ // ReSharper disable once ForCanBeConvertedToForeach
+ for (int i = 0; i < Children.Count; i++)
+ {
+ Control child = Children[i];
+ var childSize = new PanelUvSize(_orientation, child.DesiredSize);
+ double layoutSlotU = useItemU ? itemU : childSize.U;
+
+ child.Arrange(isHorizontal ? new Rect(u, 0, layoutSlotU, lineV) : new Rect(0, u, lineV, layoutSlotU));
+
+ if (layoutSlotU > 0)
+ {
+ u += layoutSlotU + spacing;
+ }
+ }
+ }
+
+ private void ArrangeWrapLine(
+ double v,
+ double lineV,
+ int start,
+ int end,
+ bool useItemU,
+ double itemU,
+ double spacing)
+ {
+ double u = 0;
+ bool isHorizontal = _orientation == Orientation.Horizontal;
+
+ for (int i = start; i < end; i++)
+ {
+ var child = Children[i];
+
+ var childSize = new PanelUvSize(_orientation, child.DesiredSize);
+ double layoutSlotU = useItemU ? itemU : childSize.U;
+
+ child.Arrange(isHorizontal ? new Rect(u, v, layoutSlotU, lineV) : new Rect(v, u, lineV, layoutSlotU));
+
+ if (layoutSlotU > 0)
+ {
+ u += layoutSlotU + spacing;
+ }
+ }
+ }
+}
diff --git a/src/Avalonia/HandyControl_Avalonia/Data/Enum/VisualWrapping.cs b/src/Avalonia/HandyControl_Avalonia/Data/Enum/VisualWrapping.cs
new file mode 100644
index 000000000..d744c97ce
--- /dev/null
+++ b/src/Avalonia/HandyControl_Avalonia/Data/Enum/VisualWrapping.cs
@@ -0,0 +1,7 @@
+namespace HandyControl.Data;
+
+public enum VisualWrapping
+{
+ NoWrap,
+ Wrap
+}
diff --git a/src/Avalonia/HandyControl_Avalonia/Data/PanelUvSize.cs b/src/Avalonia/HandyControl_Avalonia/Data/PanelUvSize.cs
new file mode 100644
index 000000000..e5219a0fc
--- /dev/null
+++ b/src/Avalonia/HandyControl_Avalonia/Data/PanelUvSize.cs
@@ -0,0 +1,69 @@
+using Avalonia;
+using Avalonia.Layout;
+
+namespace HandyControl.Data;
+
+internal struct PanelUvSize
+{
+ private readonly Orientation _orientation;
+
+ public Size ScreenSize => new(U, V);
+
+ public double U { get; set; }
+
+ public double V { get; set; }
+
+ public double Width
+ {
+ get => _orientation == Orientation.Horizontal ? U : V;
+ private set
+ {
+ if (_orientation == Orientation.Horizontal)
+ {
+ U = value;
+ }
+ else
+ {
+ V = value;
+ }
+ }
+ }
+
+ public double Height
+ {
+ get => _orientation == Orientation.Horizontal ? V : U;
+ private set
+ {
+ if (_orientation == Orientation.Horizontal)
+ {
+ V = value;
+ }
+ else
+ {
+ U = value;
+ }
+ }
+ }
+
+ public PanelUvSize(Orientation orientation, double width, double height)
+ {
+ U = V = 0d;
+ _orientation = orientation;
+ Width = width;
+ Height = height;
+ }
+
+ public PanelUvSize(Orientation orientation, Size size)
+ {
+ U = V = 0d;
+ _orientation = orientation;
+ Width = size.Width;
+ Height = size.Height;
+ }
+
+ public PanelUvSize(Orientation orientation)
+ {
+ U = V = 0d;
+ _orientation = orientation;
+ }
+}
diff --git a/src/Avalonia/HandyControl_Avalonia/HandyControl_Avalonia.csproj b/src/Avalonia/HandyControl_Avalonia/HandyControl_Avalonia.csproj
index 64d992698..5b94b2f92 100644
--- a/src/Avalonia/HandyControl_Avalonia/HandyControl_Avalonia.csproj
+++ b/src/Avalonia/HandyControl_Avalonia/HandyControl_Avalonia.csproj
@@ -8,7 +8,7 @@
-
+
@@ -26,7 +26,4 @@
-
-
-
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Button.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Button.axaml
index 59670c001..be003770f 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Button.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Button.axaml
@@ -1,19 +1,11 @@
-
-
-
-
-
-
+
+ Value="{StaticResource DefaultControlPadding}" />
+
+
+
+
+
-
+
-
-
-
+
-
-
-
+
+
-
-
+ Value="{DynamicResource SecondaryRegionBrush}" />
-
-
+ Value="{DynamicResource BorderBrush}" />
+
-
-
-
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml
new file mode 100644
index 000000000..0a8cc8328
--- /dev/null
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Label.axaml
@@ -0,0 +1,94 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ListBox.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ListBox.axaml
index b84bd017b..bce89486e 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ListBox.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/ListBox.axaml
@@ -8,6 +8,8 @@
Value="{DynamicResource BorderBrush}" />
+
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ xmlns:hc="clr-namespace:HandyControl.Controls">
+
+ Value="{DynamicResource SecondaryRegionBrush}" />
-
-
-
-
-
-
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Style.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Style.axaml
index d45e0da78..819b4aeb2 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Style.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Style.axaml
@@ -17,6 +17,7 @@
+
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabControl.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabControl.axaml
index 5ff351a6b..253bfc223 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabControl.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabControl.axaml
@@ -2,69 +2,73 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
-
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+
+
-
+
+
-
+
+
-
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabItem.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabItem.axaml
index 533f67cdc..34ac5a54b 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabItem.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/TabItem.axaml
@@ -15,31 +15,42 @@
+ Value="Center" />
+ Value="Center" />
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Window.axaml b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Window.axaml
index 6cde86101..9f288134e 100644
--- a/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Window.axaml
+++ b/src/Avalonia/HandyControl_Avalonia/Themes/Styles/Window.axaml
@@ -12,7 +12,7 @@
+ Value="12" />
diff --git a/src/Avalonia/HandyControl_Avalonia/Tools/Helper/MathHelper.cs b/src/Avalonia/HandyControl_Avalonia/Tools/Helper/MathHelper.cs
new file mode 100644
index 000000000..1a7fb297e
--- /dev/null
+++ b/src/Avalonia/HandyControl_Avalonia/Tools/Helper/MathHelper.cs
@@ -0,0 +1,16 @@
+using System;
+
+namespace HandyControl.Tools;
+
+internal static class MathHelper
+{
+ public const double Epsilon = 2.2204460492503131e-016;
+
+ public static bool AreClose(double value1, double value2) =>
+ // ReSharper disable once CompareOfFloatsByEqualityOperator
+ value1 == value2 || IsVerySmall(value1 - value2);
+
+ public static bool IsVerySmall(double value) => Math.Abs(value) < 1E-06;
+
+ public static bool GreaterThan(double value1, double value2) => value1 > value2 && !AreClose(value1, value2);
+}
diff --git a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
index 16f2e9797..6d0508f9e 100644
--- a/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
+++ b/src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
@@ -10720,8 +10720,8 @@
-
-
+
+
diff --git a/src/Shared/HandyControl_Shared/Controls/Panel/UniformSpacingPanel.cs b/src/Shared/HandyControl_Shared/Controls/Panel/UniformSpacingPanel.cs
index 11b5ff50f..2df57c6fb 100644
--- a/src/Shared/HandyControl_Shared/Controls/Panel/UniformSpacingPanel.cs
+++ b/src/Shared/HandyControl_Shared/Controls/Panel/UniformSpacingPanel.cs
@@ -9,16 +9,12 @@ namespace HandyControl.Controls;
public class UniformSpacingPanel : Panel
{
- private Orientation _orientation;
-
- public UniformSpacingPanel()
- {
- _orientation = Orientation.Horizontal;
- }
+ private Orientation _orientation = Orientation.Horizontal;
public static readonly DependencyProperty OrientationProperty =
StackPanel.OrientationProperty.AddOwner(typeof(UniformSpacingPanel),
- new FrameworkPropertyMetadata(Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsMeasure, OnOrientationChanged));
+ new FrameworkPropertyMetadata(Orientation.Horizontal, FrameworkPropertyMetadataOptions.AffectsMeasure,
+ OnOrientationChanged));
private static void OnOrientationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
@@ -132,7 +128,8 @@ private static bool IsSpacingValid(object value)
return false;
}
- private void ArrangeWrapLine(double v, double lineV, int start, int end, bool useItemU, double itemU, double spacing)
+ private void ArrangeWrapLine(double v, double lineV, int start, int end, bool useItemU, double itemU,
+ double spacing)
{
double u = 0;
var isHorizontal = _orientation == Orientation.Horizontal;
@@ -191,7 +188,7 @@ protected override Size MeasureOverride(Size constraint)
var itemHorizontalAlignment = ItemHorizontalAlignment;
var itemVerticalAlignment = ItemVerticalAlignment;
var itemHorizontalAlignmentSet = itemHorizontalAlignment != null;
- var itemVerticalAlignmentSet = ItemVerticalAlignment != null;
+ var itemVerticalAlignmentSet = itemVerticalAlignment != null;
var spacingSize = GetSpacingSize();
var childConstraint = new Size(
@@ -201,9 +198,20 @@ protected override Size MeasureOverride(Size constraint)
var children = InternalChildren;
var isFirst = true;
- if (childWrapping == VisualWrapping.Wrap)
+ if (childWrapping == VisualWrapping.NoWrap)
{
- for (int i = 0, count = children.Count; i < count; i++)
+ var layoutSlotSize = constraint;
+
+ if (_orientation == Orientation.Horizontal)
+ {
+ layoutSlotSize.Width = double.PositiveInfinity;
+ }
+ else
+ {
+ layoutSlotSize.Height = double.PositiveInfinity;
+ }
+
+ for (int i = 0, count = children.Count; i < count; ++i)
{
var child = children[i];
if (child == null) continue;
@@ -218,49 +226,22 @@ protected override Size MeasureOverride(Size constraint)
child.SetCurrentValue(VerticalAlignmentProperty, itemVerticalAlignment);
}
- child.Measure(childConstraint);
+ child.Measure(layoutSlotSize);
var sz = new PanelUvSize(
_orientation,
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
- if (MathHelper.GreaterThan(curLineSize.U + sz.U + spacingSize.U, uvConstraint.U))
- {
- panelSize.U = Math.Max(curLineSize.U, panelSize.U);
- panelSize.V += curLineSize.V + spacingSize.V;
- curLineSize = sz;
-
- if (MathHelper.GreaterThan(sz.U, uvConstraint.U))
- {
- panelSize.U = Math.Max(sz.U, panelSize.U);
- panelSize.V += sz.V + spacingSize.V;
- curLineSize = new PanelUvSize(_orientation);
- }
- }
- else
- {
- curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
- curLineSize.V = Math.Max(sz.V, curLineSize.V);
+ curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
+ curLineSize.V = Math.Max(sz.V, curLineSize.V);
- isFirst = false;
- }
+ isFirst = false;
}
}
else
{
- var layoutSlotSize = constraint;
-
- if (_orientation == Orientation.Horizontal)
- {
- layoutSlotSize.Width = double.PositiveInfinity;
- }
- else
- {
- layoutSlotSize.Height = double.PositiveInfinity;
- }
-
- for (int i = 0, count = children.Count; i < count; ++i)
+ for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
if (child == null) continue;
@@ -275,17 +256,33 @@ protected override Size MeasureOverride(Size constraint)
child.SetCurrentValue(VerticalAlignmentProperty, itemVerticalAlignment);
}
- child.Measure(layoutSlotSize);
+ child.Measure(childConstraint);
var sz = new PanelUvSize(
_orientation,
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
- curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
- curLineSize.V = Math.Max(sz.V, curLineSize.V);
+ if (MathHelper.GreaterThan(curLineSize.U + sz.U + spacingSize.U, uvConstraint.U))
+ {
+ panelSize.U = Math.Max(curLineSize.U, panelSize.U);
+ panelSize.V += curLineSize.V + spacingSize.V;
+ curLineSize = sz;
- isFirst = false;
+ if (MathHelper.GreaterThan(sz.U, uvConstraint.U))
+ {
+ panelSize.U = Math.Max(sz.U, panelSize.U);
+ panelSize.V += sz.V + spacingSize.V;
+ curLineSize = new PanelUvSize(_orientation);
+ }
+ }
+ else
+ {
+ curLineSize.U += isFirst ? sz.U : sz.U + spacingSize.U;
+ curLineSize.V = Math.Max(sz.V, curLineSize.V);
+
+ isFirst = false;
+ }
}
}
@@ -337,7 +334,11 @@ protected override Size ArrangeOverride(Size finalSize)
var children = InternalChildren;
var isFirst = true;
- if (childWrapping == VisualWrapping.Wrap)
+ if (childWrapping == VisualWrapping.NoWrap)
+ {
+ ArrangeLine(uvFinalSize.V, useItemU, itemU, spacingSize.U);
+ }
+ else
{
for (int i = 0, count = children.Count; i < count; i++)
{
@@ -369,13 +370,10 @@ protected override Size ArrangeOverride(Size finalSize)
if (firstInLine < children.Count)
{
- ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU, spacingSize.U);
+ ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU,
+ spacingSize.U);
}
}
- else
- {
- ArrangeLine(uvFinalSize.V, useItemU, itemU, spacingSize.U);
- }
return finalSize;
}