feat: new measure method.

This commit is contained in:
rabbitism
2024-01-04 23:17:34 +08:00
parent 66bc512ae2
commit 86b71a3c82
4 changed files with 90 additions and 27 deletions

View File

@@ -156,4 +156,11 @@ public class Timeline: ItemsControl
}
}
protected override Size ArrangeOverride(Size finalSize)
{
var panel = this.ItemsPanelRoot as TimelinePanel;
panel.Mode = this.Mode;
return base.ArrangeOverride(finalSize);
}
}

View File

@@ -158,13 +158,35 @@ public class TimelineItem: HeaderedContentControl
PseudoClasses.Set(PC_Last, end);
}
internal (double?, double?, double?, double?) GetWidth()
internal (double left, double mid, double right) GetWidth()
{
return (_headerPresenter?.Bounds.Width, _contentPresenter?.Bounds.Width, _iconPresenter?.Bounds.Width, _timePresenter?.Bounds.Width);
if (_headerPresenter is null) return new ValueTuple<double, double, double>(0, 0, 0);
double header = _headerPresenter?.DesiredSize.Width ?? 0;
double icon = _iconPresenter?.DesiredSize.Width ?? 0;
double content = _contentPresenter?.DesiredSize.Width ?? 0;
double time = _timePresenter?.DesiredSize.Width ?? 0;
double max = Math.Max(header, content);
if (Mode == TimelineItemDisplayMode.Left)
{
max = Math.Max(max, time);
return (max, icon, 0);
}
if (Mode == TimelineItemDisplayMode.Right)
{
max = Math.Max(max, time);
return (0, icon, max);
}
if (Mode == TimelineItemDisplayMode.Separate)
{
return (time, icon, max);
}
return new ValueTuple<double, double, double>(0, 0, 0);
}
internal void SetWidth(double? header, double? content, double? icon, double? time)
internal void SetWidth(double? left, double? mid, double? right)
{
_rootGrid.ColumnDefinitions[0].Width = new GridLength(200);
_rootGrid.ColumnDefinitions[0].Width = new GridLength(left??0);
_rootGrid.ColumnDefinitions[1].Width = new GridLength(mid??0);
_rootGrid.ColumnDefinitions[2].Width = new GridLength(right??0);
}
}

View File

@@ -25,7 +25,6 @@ public class TimelinePanel: Panel
double left = 0;
double right = 0;
double icon = 0;
double width = 0;
double height = 0;
foreach (var child in Children)
{
@@ -33,40 +32,51 @@ public class TimelinePanel: Panel
if (child is TimelineItem t)
{
var doubles = t.GetWidth();
left = Math.Max(left, doubles.left);
icon = Math.Max(icon, doubles.mid);
right = Math.Max(right, doubles.right);
}
width = Math.Max(width, child.DesiredSize.Width);
height+=child.DesiredSize.Height;
}
foreach (var child in Children)
{
if (child is TimelineItem t)
{
t.LeftWidth = left;
t.RightWidth = right;
t.IconWidth = icon;
}
}
return new Size(width, height);
return new Size(left+icon+right, height);
}
protected override Size ArrangeOverride(Size finalSize)
{
Rect rect = new Rect();
double left = 0, mid = 0, right = 0;
double height = 0;
foreach (var child in Children)
{
rect = rect.WithWidth(Math.Max(rect.Width, child.DesiredSize.Width));
rect = rect.WithHeight(rect.Height + child.DesiredSize.Height);
child.Arrange(rect);
rect = rect.WithY(rect.Y+child.DesiredSize.Height);
if (child is TimelineItem t)
{
var doubles = t.GetWidth();
t.SetWidth(0, 0, 0, 0);
left = Math.Max(left, doubles.left);
mid = Math.Max(mid, doubles.mid);
right = Math.Max(right, doubles.right);
}
}
Rect rect = new Rect(0, 0, left + mid + right, 0);
foreach (var child in Children)
{
if (child is TimelineItem t)
{
t.SetWidth(left, mid, right);
rect = rect.WithHeight(t.DesiredSize.Height);
t.InvalidateArrange();
//rect = rect.WithHeight(t.DesiredSize.Height);
child.Arrange(rect);
rect = rect.WithY(rect.Y + t.DesiredSize.Height);
height+=t.DesiredSize.Height;
}
}
//return base.ArrangeOverride(finalSize);
return rect.Size;
return new Size(left + mid + right, height);
}
public override void ApplyTemplate()
{
base.ApplyTemplate();
}
}