* UIBreadcrumb: 增加两端对齐,AlignBothEnds

This commit is contained in:
Sunny 2022-01-26 09:54:32 +08:00
parent 9989447771
commit 657313041d
2 changed files with 50 additions and 10 deletions

Binary file not shown.

View File

@ -17,6 +17,7 @@
* : 2021-04-10 * : 2021-04-10
* *
* 2021-04-10: V3.0.2 * 2021-04-10: V3.0.2
* 2022-01-26: V3.1.0 AlignBothEnds
******************************************************************************/ ******************************************************************************/
using System; using System;
@ -54,13 +55,30 @@ namespace Sunny.UI
Invalidate(); Invalidate();
} }
private bool alignBothEnds;
[DefaultValue(false)]
[Description("显示时两端对齐"), Category("SunnyUI")]
public bool AlignBothEnds
{
get => alignBothEnds;
set
{
if (alignBothEnds != value)
{
alignBothEnds = value;
Invalidate();
}
}
}
public delegate void OnValueChanged(object sender, int value); public delegate void OnValueChanged(object sender, int value);
public event OnValueChanged ItemIndexChanged; public event OnValueChanged ItemIndexChanged;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Localizable(true)] [Localizable(true)]
[Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + AssemblyRefEx.SystemDesign, typeof(UITypeEditor))]
[MergableProperty(false)] [MergableProperty(false)]
[Description("列表项"), Category("SunnyUI")] [Description("列表项"), Category("SunnyUI")]
public UIObjectCollection Items => items; public UIObjectCollection Items => items;
@ -100,7 +118,7 @@ namespace Sunny.UI
float width = 0; float width = 0;
if (Items.Count == 0) if (Items.Count == 0)
{ {
SizeF sf = g.MeasureString("Item0", Font); SizeF sf = g.MeasureString(Text, Font);
width = sf.Width + Height + 6; width = sf.Width + Height + 6;
if (itemWidth < width) itemWidth = (int)width; if (itemWidth < width) itemWidth = (int)width;
List<PointF> points = new List<PointF>(); List<PointF> points = new List<PointF>();
@ -117,7 +135,7 @@ namespace Sunny.UI
g.FillPolygon(br, points.ToArray()); g.FillPolygon(br, points.ToArray());
} }
g.DrawString("Item0", Font, ForeColor, (Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f); g.DrawString(Text, Font, ForeColor, (Width - sf.Width) / 2.0f, (Height - sf.Height) / 2.0f);
} }
else else
{ {
@ -136,13 +154,35 @@ namespace Sunny.UI
{ {
SizeF sf = g.MeasureString(item.ToString(), Font); SizeF sf = g.MeasureString(item.ToString(), Font);
List<PointF> points = new List<PointF>(); List<PointF> points = new List<PointF>();
points.Add(new PointF(begin + 3, 0));
points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, 0)); if (index == 0 && AlignBothEnds)
points.Add(new PointF(begin + itemWidth - 3, Height / 2.0f)); {
points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, Height)); points.Add(new PointF(begin + 3, 0));
points.Add(new PointF(begin + 3, Height)); points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, 0));
points.Add(new PointF(begin + 3 + Height / 2.0f, Height / 2.0f)); points.Add(new PointF(begin + itemWidth - 3, Height / 2.0f));
points.Add(new PointF(begin + 3, 0)); points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, Height));
points.Add(new PointF(begin + 3, Height));
points.Add(new PointF(begin + 3, 0));
}
else if (index == Items.Count - 1 && AlignBothEnds)
{
points.Add(new PointF(begin + 3, 0));
points.Add(new PointF(begin + itemWidth - 3, 0));
points.Add(new PointF(begin + itemWidth - 3, Height));
points.Add(new PointF(begin + 3, Height));
points.Add(new PointF(begin + 3 + Height / 2.0f, Height / 2.0f));
points.Add(new PointF(begin + 3, 0));
}
else
{
points.Add(new PointF(begin + 3, 0));
points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, 0));
points.Add(new PointF(begin + itemWidth - 3, Height / 2.0f));
points.Add(new PointF(begin + itemWidth - 3 - Height / 2.0f, Height));
points.Add(new PointF(begin + 3, Height));
points.Add(new PointF(begin + 3 + Height / 2.0f, Height / 2.0f));
points.Add(new PointF(begin + 3, 0));
}
Point[] pts = new Point[points.Count]; Point[] pts = new Point[points.Count];
for (int i = 0; i < points.Count; i++) for (int i = 0; i < points.Count; i++)