// COPYRIGHT (C) Tom. ALL RIGHTS RESERVED.
// THE AntdUI PROJECT IS AN WINFORM LIBRARY LICENSED UNDER THE Apache-2.0 License.
// LICENSED UNDER THE Apache License, VERSION 2.0 (THE "License")
// YOU MAY NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE License.
// YOU MAY OBTAIN A COPY OF THE LICENSE AT
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE
// DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
// SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING PERMISSIONS AND
// LIMITATIONS UNDER THE License.
// GITEE: https://gitee.com/antdui/AntdUI
// GITHUB: https://github.com/AntdUI/AntdUI
// CSDN: https://blog.csdn.net/v_132
// QQ: 17379620
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
namespace AntdUI
{
///
/// GridPanel 格栅布局
///
[Description("GridPanel 格栅布局")]
[ToolboxItem(true)]
[DefaultProperty("Span")]
[Designer(typeof(IControlDesigner))]
public class GridPanel : IControl
{
public override Rectangle DisplayRectangle
{
get => ClientRectangle.DeflateRect(Padding);
}
///
/// 跨度
///
[Description("跨度"), Category("外观"), DefaultValue("50% 50%;50% 50%")]
[Editor(typeof(System.ComponentModel.Design.MultilineStringEditor), typeof(UITypeEditor))]
public string Span
{
get => layoutengine.Span;
set
{
if (layoutengine.Span == value) return;
layoutengine.Span = value;
OSizeChanged();
}
}
///
/// 间距
///
[Description("间距"), Category("外观"), DefaultValue(0)]
public int Gap
{
get => layoutengine.Gap;
set
{
if (layoutengine.Gap == value) return;
layoutengine.Gap = value;
OSizeChanged();
}
}
#region 布局
internal void OSizeChanged()
{
OnSizeChanged(EventArgs.Empty);
}
GridLayout layoutengine = new GridLayout();
public override LayoutEngine LayoutEngine => layoutengine;
internal class GridLayout : LayoutEngine
{
///
/// 内容大小
///
public string Span { get; set; } = "50% 50%;50% 50%";
///
/// 间距
///
public int Gap { get; set; }
public override bool Layout(object container, LayoutEventArgs layoutEventArgs)
{
if (container is GridPanel parent)
{
var rect = parent.DisplayRectangle;
if (!string.IsNullOrEmpty(Span) && parent.Controls.Count > 0)
{
var controls = new List(parent.Controls.Count);
foreach (Control it in parent.Controls)
{
if (it.Visible) controls.Insert(0, it);
}
if (controls.Count > 0)
{
int data_count = 0;
var rows = Span.Split(';', '\n');
var data = new List(rows.Length);
foreach (var row in rows)
{
if (!string.IsNullOrEmpty(row))
{
var cels = row.Split(' ', ',');
var cels_tmp = new List