fix(Space): restore preset spacing in size showcase

This commit is contained in:
chinboy
2026-07-08 16:33:05 +08:00
parent f6c276d29e
commit 66d8ddec79
4 changed files with 47 additions and 5 deletions
@@ -117,10 +117,11 @@
<atom:Slider Name="CustomSizeSlider"
Minimum="0" Maximum="100"
Value="{Binding CustomSpacingValue, Mode=TwoWay}"
ValueChanged="HandleCustomSpacingValueChanged"
IsVisible="False"/>
<atom:Space Orientation="Horizontal" SizeType="{Binding SizeType}"
LineSpacing="{Binding CustomSpacingValue, Priority=Template}"
ItemSpacing="{Binding CustomSpacingValue, Priority=Template}">
<atom:Space Name="SizeDemoSpace"
Orientation="Horizontal"
SizeType="{Binding SizeType}">
<atom:Button ButtonType="Primary" Content="{gallery:SpaceShowCaseLangResource P2ContentPrimary}" />
<atom:Button Content="{gallery:SpaceShowCaseLangResource P2ContentDefault}" />
<atom:Button ButtonType="Dashed" Content="{gallery:SpaceShowCaseLangResource P2ContentDashed}" />
@@ -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<SpaceViewModel>
}
customSizeSlider.IsVisible = sizeType == CustomizableSizeType.Custom;
if (TryFindTemplateControl<AtomUI.Desktop.Controls.Space>(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<AtomUI.Desktop.Controls.Space>(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()
@@ -1,2 +1,2 @@
count: 9
sha256: d84f37042fd53aff587c49b45dfcebbfd50b480813dc001a557d35bc54aef044
sha256: 5ebdbdabb01cc71c23baba0b5824a62e4a3527487732f8d8140bf82d73200336
@@ -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("<atom:TabControl");
source.ShouldNotContain("<atom:TabItem");
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<AtomUISlider>(radioButton, \"CustomSizeSlider\", out var customSizeSlider)");
codeBehindSource.ShouldNotContain("FindRequired<AtomUISlider>");
codeBehindSource.ShouldNotContain("new SpaceBasicShowCase()");