From 66d8ddec79b82a989d05da1bc8bd3dbf033b5235 Mon Sep 17 00:00:00 2001 From: chinboy Date: Wed, 8 Jul 2026 16:33:05 +0800 Subject: [PATCH] fix(Space): restore preset spacing in size showcase --- .../Layout/Space/Views/SpaceShowCase.axaml | 7 ++-- .../Layout/Space/Views/SpaceShowCase.axaml.cs | 36 ++++++++++++++++++- .../ShowCases/SpaceShowCaseExamples.snapshot | 2 +- .../ShowCases/SpaceShowCasePageTests.cs | 7 ++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml b/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml index 6f0af28ba..0836b4de4 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml +++ b/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml @@ -117,10 +117,11 @@ - + diff --git a/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml.cs b/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml.cs index e41b56583..b582176f4 100644 --- a/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml.cs +++ b/controlgallery/AtomUIGallery/ShowCases/Layout/Space/Views/SpaceShowCase.axaml.cs @@ -12,7 +12,7 @@ using Avalonia.LogicalTree; using Avalonia.VisualTree; using AtomUIGallery.Localization; using AtomUISlider = AtomUI.Desktop.Controls.Slider; -using ScenarioTabStripItem = AtomUI.Desktop.Controls.TabStripItem; +using Avalonia.Controls.Primitives; namespace AtomUIGallery.ShowCases.Space; @@ -69,6 +69,40 @@ public partial class SpaceShowCase : GalleryReactiveUserControl } customSizeSlider.IsVisible = sizeType == CustomizableSizeType.Custom; + if (TryFindTemplateControl(radioButton, "SizeDemoSpace", out var sizeDemoSpace)) + { + ApplySizeDemoSpacing(sizeDemoSpace, sizeType, customSizeSlider.Value); + } + } + + public void HandleCustomSpacingValueChanged(object? sender, RangeBaseValueChangedEventArgs e) + { + if (sender is not AtomUISlider slider || + DataContext is not SpaceViewModel { SizeType: CustomizableSizeType.Custom }) + { + return; + } + + if (TryFindTemplateControl(slider, "SizeDemoSpace", out var sizeDemoSpace)) + { + ApplySizeDemoSpacing(sizeDemoSpace, CustomizableSizeType.Custom, slider.Value); + } + } + + private static void ApplySizeDemoSpacing(AtomUI.Desktop.Controls.Space space, + CustomizableSizeType sizeType, + double customSpacing) + { + if (sizeType == CustomizableSizeType.Custom) + { + var spacing = Math.Max(0, customSpacing); + space.ItemSpacing = spacing; + space.LineSpacing = spacing; + return; + } + + space.ClearValue(AtomUI.Desktop.Controls.Space.ItemSpacingProperty); + space.ClearValue(AtomUI.Desktop.Controls.Space.LineSpacingProperty); } private void RefreshCurrentViewModelData() diff --git a/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCaseExamples.snapshot b/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCaseExamples.snapshot index 3b61b60cc..222277669 100644 --- a/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCaseExamples.snapshot +++ b/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCaseExamples.snapshot @@ -1,2 +1,2 @@ count: 9 -sha256: d84f37042fd53aff587c49b45dfcebbfd50b480813dc001a557d35bc54aef044 +sha256: 5ebdbdabb01cc71c23baba0b5824a62e4a3527487732f8d8140bf82d73200336 diff --git a/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCasePageTests.cs b/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCasePageTests.cs index 3c97f9f1a..0d429ec10 100644 --- a/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCasePageTests.cs +++ b/tests/AtomUIGallery.Tests/ShowCases/SpaceShowCasePageTests.cs @@ -54,7 +54,11 @@ public class SpaceShowCasePageTests source.ShouldContain("SpaceShowCaseLangResource AlignTitle"); source.ShouldContain("SpaceShowCaseLangResource CompactFormTitle"); source.ShouldContain("SpaceShowCaseLangResource CompactButtonTitle"); + source.ShouldContain("Name=\"SizeDemoSpace\""); + source.ShouldContain("ValueChanged=\"HandleCustomSpacingValueChanged\""); source.ShouldNotContain("{Binding #CustomSizeSlider.Value"); + source.ShouldNotContain("ItemSpacing=\"{Binding CustomSpacingValue, Priority=Template}\""); + source.ShouldNotContain("LineSpacing=\"{Binding CustomSpacingValue, Priority=Template}\""); source.ShouldNotContain("Gallery<"); @@ -83,6 +87,9 @@ public class SpaceShowCasePageTests codeBehindSource.ShouldNotContain("new SpaceApiDataGrid()"); codeBehindSource.ShouldNotContain("new SpaceDesignTokenDataGrid()"); codeBehindSource.ShouldContain("HandleSizeTypeChanged"); + codeBehindSource.ShouldContain("HandleCustomSpacingValueChanged"); + codeBehindSource.ShouldContain("ClearValue(AtomUI.Desktop.Controls.Space.ItemSpacingProperty)"); + codeBehindSource.ShouldContain("ClearValue(AtomUI.Desktop.Controls.Space.LineSpacingProperty)"); codeBehindSource.ShouldContain("TryFindTemplateControl(radioButton, \"CustomSizeSlider\", out var customSizeSlider)"); codeBehindSource.ShouldNotContain("FindRequired"); codeBehindSource.ShouldNotContain("new SpaceBasicShowCase()");