add HoneycombPanel

This commit is contained in:
NaBian committed 2019-08-10 21:24:37 +08:00
1 parent 9856ff1225
commit 9c4fb33c55
29 files changed
+327 -33

No files matched your search

@@ -396,6 +396,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\Dynamic_16x.png">
<Link>Resources\Img\LeftMainContent\Dynamic_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\PolygonHexagon_16x.png">
<Link>Resources\Img\LeftMainContent\PolygonHexagon_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\Dance.png">
<Link>Resources\Img\Dance.png</Link>
</Resource>
@@ -417,6 +417,9 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\PolygonHexagon_16x.png">
<Link>Resources\Img\LeftMainContent\PolygonHexagon_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\Dynamic_16x.png">
<Link>Resources\Img\LeftMainContent\Dynamic_16x.png</Link>
</Resource>
@@ -480,6 +480,9 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\PolygonHexagon_16x.png">
<Link>Resources\Img\LeftMainContent\PolygonHexagon_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\Dynamic_16x.png">
<Link>Resources\Img\LeftMainContent\Dynamic_16x.png</Link>
</Resource>
@@ -9,9 +9,6 @@ using HandyControlDemo.Tools;
namespace HandyControlDemo
{
/// <summary>
/// App.xaml 的交互逻辑
/// </summary>
public partial class App
{
protected override void OnStartup(StartupEventArgs e)
@@ -108,6 +108,8 @@
public static readonly string RunningBlockDemoCtl = nameof(RunningBlockDemoCtl);
public static readonly string HoneycombPanelDemoCtl = nameof(HoneycombPanelDemoCtl);
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string RepeatButtonDemoCtl = nameof(RepeatButtonDemoCtl);
@@ -56,7 +56,8 @@ var controlList = new List<string>
"CardDemoCtl",
"MagnifierDemoCtl",
"ImageBlockDemoCtl",
"RunningBlockDemoCtl"
"RunningBlockDemoCtl",
"HoneycombPanelDemoCtl"
};
var styleList = new List<string>
{
@@ -54,6 +54,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\CardDemoCtl.xaml.cs">
<DependentUpon>CardDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\HoneycombPanelDemoCtl.xaml.cs">
<DependentUpon>HoneycombPanelDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\ImageBlockDemoCtl.xaml.cs">
<DependentUpon>ImageBlockDemoCtl.xaml</DependentUpon>
</Compile>
@@ -429,6 +432,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\HoneycombPanelDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\ImageBlockDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -69,6 +69,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 添加项 的本地化字符串。
/// </summary>
public static string AddItem {
get {
return ResourceManager.GetString("AddItem", resourceCulture);
}
}
/// <summary>
/// 查找类似 动画路径 的本地化字符串。
/// </summary>
@@ -672,6 +681,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 蜂窝布局 的本地化字符串。
/// </summary>
public static string HoneycombPanel {
get {
return ResourceManager.GetString("HoneycombPanel", resourceCulture);
}
}
/// <summary>
/// 查找类似 混合布局 的本地化字符串。
/// </summary>
@@ -1185,6 +1203,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 删除项 的本地化字符串。
/// </summary>
public static string RemoveItem {
get {
return ResourceManager.GetString("RemoveItem", resourceCulture);
}
}
/// <summary>
/// 查找类似 重复按钮 的本地化字符串。
/// </summary>
@@ -636,4 +636,13 @@
<data name="RunningBlock" xml:space="preserve">
<value>RunningBlock</value>
</data>
<data name="HoneycombPanel" xml:space="preserve">
<value>HoneycombPanel</value>
</data>
<data name="AddItem" xml:space="preserve">
<value>Add an item</value>
</data>
<data name="RemoveItem" xml:space="preserve">
<value>Remove an item</value>
</data>
</root>
@@ -636,4 +636,13 @@
<data name="RunningBlock" xml:space="preserve">
<value>滚动块</value>
</data>
<data name="HoneycombPanel" xml:space="preserve">
<value>蜂窝布局</value>
</data>
<data name="AddItem" xml:space="preserve">
<value>添加项</value>
</data>
<data name="RemoveItem" xml:space="preserve">
<value>删除项</value>
</data>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

@@ -157,9 +157,9 @@ namespace HandyControlDemo.Service
};
}
internal List<CardModel> GetCardDataList()
internal ObservableCollection<CardModel> GetCardDataList()
{
return new List<CardModel>
return new ObservableCollection<CardModel>
{
new CardModel
{
@@ -224,6 +224,14 @@ namespace HandyControlDemo.Service
};
}
internal CardModel GetCardData()
{
return new CardModel
{
Content = $"/HandyControlDemo;component/Resources/Img/Album/{DateTime.Now.Second % 10 + 1}.jpg"
};
}
internal List<StepBarDemoModel> GetStepBarDemoDataList()
{
return new List<StepBarDemoModel>
@@ -1,9 +1,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// GrowlDemoGrid.xaml 的交互逻辑
/// </summary>
public partial class GrowlDemoCtl
{
public GrowlDemoCtl()
@@ -0,0 +1,34 @@
<UserControl x:Class="HandyControlDemo.UserControl.HoneycombPanelDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
DataContext="{Binding CardDemo,Source={StaticResource Locator}}"
Background="{DynamicResource RegionBrush}">
<hc:TransitioningContentControl>
<Grid Margin="32">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<hc:ButtonGroup Margin="0,0,0,16">
<Button Command="{Binding AddItemCmd}" Content="{x:Static langs:Lang.AddItem}"/>
<Button Command="{Binding RemoveItemCmd}" Content="{x:Static langs:Lang.RemoveItem}"/>
</hc:ButtonGroup>
<Border Padding="0" Grid.Row="1" Style="{StaticResource BorderRegion}">
<ListBox Background="Transparent" BorderThickness="0" Style="{StaticResource ListBoxCustom}" ItemsSource="{Binding DataList}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<hc:HoneycombPanel hc:PanelElement.FluidMoveBehavior="{StaticResource BehaviorXY200}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate DataType="data:CardModel">
<hc:Gravatar Style="{StaticResource GravatarCircle}" Margin="10" Source="{Binding Content}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Border>
</Grid>
</hc:TransitioningContentControl>
</UserControl>
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl
{
public partial class HoneycombPanelDemoCtl
{
public HoneycombPanelDemoCtl()
{
InitializeComponent();
}
}
}
@@ -1,9 +1,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ImageBrowserDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ImageBrowserDemoCtl
{
public ImageBrowserDemoCtl()
@@ -1,9 +1,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// StepBarDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class StepBarDemoCtl
{
public StepBarDemoCtl()
@@ -220,7 +220,7 @@
<Image Source="../../Resources/Img/LeftMainContent/GoToTop_16x.png"/>
</hc:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.ButtonGroupDemoCtl}" Content="{x:Static langs:Lang.ButtonGroup}">
<ListBoxItem Tag="{x:Static data:MessageToken.ButtonGroupDemoCtl}" Content="{x:Static langs:Lang.ButtonGroup}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/ButtonGroup_16x.png"/>
</hc:EdgeElement.LeftContent>
@@ -350,6 +350,11 @@
<Image Source="../../Resources/Img/LeftMainContent/Panel_16x.png"/>
</hc:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.HoneycombPanelDemoCtl}" Content="{x:Static langs:Lang.HoneycombPanel}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/PolygonHexagon_16x.png"/>
</hc:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Tag="{x:Static data:MessageToken.CoverViewDemoCtl}" Content="{x:Static langs:Lang.CoverView}">
<hc:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/DetailDataView_16x.png"/>
@@ -2,9 +2,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ExpanderDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ExpanderDemoCtl
{
public ExpanderDemoCtl()
@@ -1,9 +1,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// TextBlockDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class TextBlockDemoCtl
{
public TextBlockDemoCtl()
@@ -1,9 +1,6 @@
namespace HandyControlDemo.UserControl
{
/// <summary>
/// ToggleButtonDemoCtl.xaml 的交互逻辑
/// </summary>
public partial class ToggleButtonDemoCtl
{
public ToggleButtonDemoCtl()
@@ -1,13 +1,34 @@
using HandyControlDemo.Data;
using System;
#if netle40
using GalaSoft.MvvmLight.Command;
#else
using GalaSoft.MvvmLight.CommandWpf;
#endif
using HandyControlDemo.Data;
using HandyControlDemo.Service;
namespace HandyControlDemo.ViewModel
{
public class CardDemoViewModel : DemoViewModelBase<CardModel>
{
private readonly DataService _dataService;
public CardDemoViewModel(DataService dataService)
{
_dataService = dataService;
DataList = dataService.GetCardDataList();
}
public RelayCommand AddItemCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() => DataList.Insert(0, _dataService.GetCardData()))).Value;
public RelayCommand RemoveItemCmd => new Lazy<RelayCommand>(() =>
new RelayCommand(() =>
{
if (DataList.Count > 0)
{
DataList.RemoveAt(0);
}
})).Value;
}
}
@@ -16,7 +16,7 @@ namespace HandyControlDemo.ViewModel
{
public class MainViewModel : DemoViewModelBase<DemoDataModel>
{
#region 字段
#region 字段
/// <summary>
/// 内容标题
@@ -33,7 +33,7 @@ namespace HandyControlDemo.ViewModel
/// </summary>
private ListBoxItem _listBoxItemCurrent;
#endregion
#endregion
public MainViewModel(DataService dataService)
{
@@ -54,7 +54,7 @@ namespace HandyControlDemo.ViewModel
DataList = dataService.GetDemoDataList();
}
#region 属性
#region 属性
/// <summary>
/// 子内容
@@ -84,7 +84,7 @@ namespace HandyControlDemo.ViewModel
#endregion
#region 命令
#region 命令
/// <summary>
/// 切换例子命令
@@ -88,7 +88,7 @@ namespace HandyControlDemo.ViewModel
public NoUserViewModel NoUser => ServiceLocator.Current.GetInstance<NoUserViewModel>();
public CardDemoViewModel CardDemo => ServiceLocator.Current.GetInstance<CardDemoViewModel>();
public CardDemoViewModel CardDemo => new CardDemoViewModel(ServiceLocator.Current.GetInstance<DataService>());
#endregion
}
@@ -0,0 +1,166 @@
using System;
using System.Windows;
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class HoneycombPanel : Panel
{
private double _unitLength;
private HoneycombStuffer _stuffer;
private static int GetXCount(int count)
{
if (count == 0) return 0;
count -= 1;
var index = (int) Math.Floor(Math.Pow((12.0 * count + 25) / 36, 0.5) - 5.0 / 6);
var valeIndex = 3 * index * index + 5 * index;
var centerValue = valeIndex + 2;
return count >= centerValue
? 4 * index + 6
: count > valeIndex
? 4 * index + 4
: 4 * index + 2;
}
private static int GetYCount(int count)
{
if (count == 0) return 0;
count -= 1;
var index = (int)Math.Floor(Math.Pow(count / 3.0 + 0.25, 0.5) - 0.5);
var valeIndex = 3 * index * index + 3 * index;
return count > valeIndex
? 2 * index + 2
: 2 * index;
}
/*
* layout order
*
* ● ●
* (7) (8)
*
* ● ● ●
* (6) (1) (9)
*
* ● ● ● ...
* (5) (0) (2)
*
* ● ● ...
* (4) (3)
*
*/
protected override Size MeasureOverride(Size availableSize)
{
var maxSize = new Size();
foreach (UIElement child in InternalChildren)
{
if (child != null)
{
child.Measure(availableSize);
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width);
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height);
}
}
_unitLength = Math.Max(maxSize.Width, maxSize.Height) / 2;
var xCount = GetXCount(InternalChildren.Count);
var yCount = GetYCount(InternalChildren.Count);
var availableWidth = xCount * _unitLength;
var availableHeight = yCount * Math.Pow(3, 0.5) * _unitLength + _unitLength * 2;
return new Size(availableWidth, availableHeight);
}
protected override Size ArrangeOverride(Size finalSize)
{
var childLength = _unitLength * 2;
_stuffer = new HoneycombStuffer(new Rect(finalSize.Width / 2 - _unitLength,
finalSize.Height / 2 - _unitLength, childLength, childLength));
foreach (UIElement child in InternalChildren)
{
child.Arrange(_stuffer.Move());
}
return base.ArrangeOverride(finalSize);
}
private class HoneycombStuffer
{
private int _turns;
private int _maxIndex;
private int _currentIndex = -1;
private readonly double _offsetX;
private readonly double _offsetY;
private Rect _childBounds;
private readonly double[] _offsetXArr;
private readonly double[] _offsetYArr;
public HoneycombStuffer(Rect childBounds)
{
_childBounds = childBounds;
_offsetX = childBounds.Width / 2;
_offsetY = Math.Pow(3, 0.5) * _offsetX;
_offsetXArr = new[]
{
2 * _offsetX,
_offsetX,
-_offsetX,
-2 * _offsetX,
-_offsetX,
_offsetX
};
_offsetYArr = new[]
{
0,
_offsetY,
_offsetY,
0,
-_offsetY,
-_offsetY
};
}
public Rect Move()
{
_currentIndex++;
if (_currentIndex > _maxIndex)
{
_turns++;
_maxIndex = _turns * 6 - 1;
_currentIndex = 0;
_childBounds.Offset(_offsetX, -_offsetY);
return _childBounds;
}
if (_turns > 0)
{
var index = _currentIndex / _turns;
_childBounds.Offset(_offsetXArr[index], _offsetYArr[index]);
}
return _childBounds;
}
}
}
}
@@ -25,6 +25,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ButtonGroup.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Card.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\ToggleBlock.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Panel\HoneycombPanel.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeTrack.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\RangeThumb.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
@@ -4,10 +4,12 @@
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../Basic/Converters.xaml"/>
<ResourceDictionary Source="../Basic/Sizes.xaml"/>
</ResourceDictionary.MergedDictionaries>
<!--用于包裹一个区域-->
<Style x:Key="BorderRegion" TargetType="Border">
<Setter Property="CornerRadius" Value="{StaticResource DefaultCornerRadius}"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Background" Value="{DynamicResource RegionBrush}"/>
<Setter Property="BorderThickness" Value="1"/>