ScreenToGif/Controls/RadialPanel.cs
(完整代码) 2KBusing System;
using System.Windows;
using System.Windows.Controls;
namespace ScreenToGif.Controls
{
///<summary>
///A panel that organizes it's inner elements in a circular fashion.
///</summary>
public class RadialPanel : Panel
{
// Measure each children and give as much room as they want.
protected override Size MeasureOverride(Size availableSize)
{
foreach (UIElement elem in Children)
{
//Give Infinite size as the avaiable size for all the children.
elem.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
}
return base.MeasureOverride(availableSize);
}
//Arrange all children based on the geometric equations for the circle.
protected override Size ArrangeOverride(Size finalSize)
{
if (Children.Count == 0)
return finalSize;
var angle = 0d;
//Degrees converted to Radian by multiplying with PI/180
var incrementalAngularSpace = (360.0 / Children.Count) * (Math.PI / 180);
//An approximate radii based on the avialable size , obviusly a better approach is needed here.
var radiusX = finalSize.Width / 2.4;
var radiusY = finalSize.Height / 2.4;
foreach (UIElement elem in Children)
{
//Calculate the point on the circle for the element.
var childPoint = new Point(Math.Cos(angle) * radiusX, -Math.Sin(angle) * radiusY);
//Offsetting the point to the Avalable rectangular area which is FinalSize.
var actualChildPoint = new Point(finalSize.Width / 2 + childPoint.X - elem.DesiredSize.Width / 2, finalSize.Height / 2 + childPoint.Y - elem.DesiredSize.Height / 2);
//Call Arrange method on the child element by giving the calculated point as the placementPoint.
elem.Arrange(new Rect(actualChildPoint.X, actualChildPoint.Y, elem.DesiredSize.Width, elem.DesiredSize.Height));
//Calculate the new _angle for the next element.
angle += incrementalAngularSpace;
}
return finalSize;
}
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
