icon select

This commit is contained in:
2022-03-02 10:45:40 +08:00
parent 2179c6a981
commit aa38e186c7
24 changed files with 288 additions and 35 deletions

View File

@ -12,6 +12,8 @@ namespace Billing.UI
public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(GroupStackLayout));
public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(GroupStackLayout), propertyChanged: OnItemsSourcePropertyChanged);
public static readonly BindableProperty SpacingProperty = BindableProperty.Create(nameof(Spacing), typeof(double), typeof(GroupStackLayout), defaultValue: 4d);
public static readonly BindableProperty RowHeightProperty = BindableProperty.Create(nameof(RowHeight), typeof(double), typeof(GroupStackLayout), defaultValue: 32d);
public static readonly BindableProperty GroupHeightProperty = BindableProperty.Create(nameof(GroupHeight), typeof(double), typeof(GroupStackLayout), defaultValue: 24d);
public DataTemplate GroupHeaderTemplate
{
@ -33,6 +35,16 @@ namespace Billing.UI
get => (double)GetValue(SpacingProperty);
set => SetValue(SpacingProperty, value);
}
public double RowHeight
{
get => (double)GetValue(RowHeightProperty);
set => SetValue(RowHeightProperty, value);
}
public double GroupHeight
{
get => (double)GetValue(GroupHeightProperty);
set => SetValue(GroupHeightProperty, value);
}
private static void OnItemsSourcePropertyChanged(BindableObject obj, object old, object @new)
{
@ -40,14 +52,14 @@ namespace Billing.UI
stack.lastWidth = -1;
if (@new == null)
{
stack.cachedLayout.Clear();
//stack.cachedLayout.Clear();
stack.Children.Clear();
stack.InvalidateLayout();
}
else if (@new is IList list)
{
stack.freezed = true;
stack.cachedLayout.Clear();
//stack.cachedLayout.Clear();
stack.Children.Clear();
var groupTemplate = stack.GroupHeaderTemplate;
var itemTemplate = stack.ItemTemplate;
@ -91,7 +103,7 @@ namespace Billing.UI
}
}
private readonly Dictionary<View, Rectangle> cachedLayout = new();
//private readonly Dictionary<View, Rectangle> cachedLayout = new();
private bool freezed;
private double lastWidth = -1;
@ -114,27 +126,40 @@ namespace Billing.UI
return;
}
var spacing = Spacing;
var lastHeight = 0.0;
var lastHeight = 0d;
var rowHeight = RowHeight;
var groupHeight = GroupHeight;
foreach (var item in Children)
{
var measured = item.Measure(width, height, MeasureFlags.IncludeMargins);
var rect = new Rectangle(
0, lastHeight, width,
measured.Request.Height);
if (cachedLayout.TryGetValue(item, out var v))
//var measured = item.Measure(width, height, MeasureFlags.IncludeMargins);
//var rect = new Rectangle(
// 0, lastHeight, width,
// measured.Request.Height);
//if (cachedLayout.TryGetValue(item, out var v))
//{
// if (v != rect)
// {
// cachedLayout[item] = rect;
// item.Layout(rect);
// }
//}
//else
//{
// cachedLayout.Add(item, rect);
// item.Layout(rect);
//}
double itemHeight;
if (item.BindingContext is IList)
{
if (v != rect)
{
cachedLayout[item] = rect;
item.Layout(rect);
}
itemHeight = groupHeight;
}
else
{
cachedLayout.Add(item, rect);
item.Layout(rect);
itemHeight = rowHeight;
}
lastHeight += rect.Height + spacing;
var rect = new Rectangle(0, lastHeight, width, itemHeight);
item.Layout(rect);
lastHeight += itemHeight + spacing;
}
}
@ -146,11 +171,21 @@ namespace Billing.UI
}
lastWidth = widthConstraint;
var spacing = Spacing;
var lastHeight = 0.0;
var lastHeight = 0d;
var rowHeight = RowHeight;
var groupHeight = GroupHeight;
foreach (var item in Children)
{
var measured = item.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins);
lastHeight += measured.Request.Height + spacing;
//var measured = item.Measure(widthConstraint, heightConstraint, MeasureFlags.IncludeMargins);
//lastHeight += measured.Request.Height + spacing;
if (item.BindingContext is IList)
{
lastHeight += groupHeight + spacing;
}
else
{
lastHeight = rowHeight + spacing;
}
}
lastSizeRequest = new SizeRequest(new Size(widthConstraint, lastHeight));
return lastSizeRequest;