2021-07-31 19:27:29 +00:00
|
|
|
|
using FizzyLauncher.Models;
|
|
|
|
|
using RyzStudio.Windows.Forms;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-07-31 20:59:35 +00:00
|
|
|
|
using System.ComponentModel;
|
2021-07-31 19:27:29 +00:00
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace FizzyLauncher.Windows.Forms
|
|
|
|
|
{
|
|
|
|
|
public class TileContainer : Panel
|
|
|
|
|
{
|
2021-07-31 20:59:35 +00:00
|
|
|
|
protected const int DEFAULT_COLUMN = 6;
|
|
|
|
|
|
2021-07-31 19:27:29 +00:00
|
|
|
|
protected FlowLayoutPanel flowLayoutPanel1 = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public TileContainer()
|
|
|
|
|
{
|
|
|
|
|
flowLayoutPanel1 = new FlowLayoutPanel();
|
|
|
|
|
flowLayoutPanel1.AutoSize = true;
|
|
|
|
|
flowLayoutPanel1.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
|
|
|
|
flowLayoutPanel1.BackColor = Color.Transparent;
|
|
|
|
|
flowLayoutPanel1.FlowDirection = FlowDirection.TopDown;
|
|
|
|
|
flowLayoutPanel1.Location = new Point(10, 10);
|
|
|
|
|
flowLayoutPanel1.Margin = new Padding(0);
|
|
|
|
|
flowLayoutPanel1.Padding = new Padding(0, 0, 0, 20);
|
|
|
|
|
flowLayoutPanel1.Size = new Size(0, 20);
|
|
|
|
|
flowLayoutPanel1.WrapContents = false;
|
|
|
|
|
|
|
|
|
|
this.AutoScroll = true;
|
|
|
|
|
this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
|
|
|
|
this.BackColor = System.Drawing.Color.Transparent;
|
|
|
|
|
this.Margin = new Padding(0);
|
|
|
|
|
this.Name = "tileContainer1";
|
|
|
|
|
this.Padding = new Padding(10, 10, 10, 20);
|
|
|
|
|
this.Controls.Add(flowLayoutPanel1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-31 20:59:35 +00:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public event EventHandler OnColumnSizeChanged;
|
|
|
|
|
|
|
|
|
|
|
2021-07-31 19:27:29 +00:00
|
|
|
|
public int CalcWidth
|
|
|
|
|
{
|
|
|
|
|
get => flowLayoutPanel1.Padding.Horizontal + flowLayoutPanel1.Margin.Horizontal + this.Left + this.Padding.Horizontal + this.Margin.Horizontal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int GroupCount
|
|
|
|
|
{
|
|
|
|
|
get => flowLayoutPanel1.Controls.Count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<TilePanelLayout> Groups
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (flowLayoutPanel1.Controls[i].GetType() != typeof(TilePanelLayout))
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TilePanelLayout container = flowLayoutPanel1.Controls[i] as TilePanelLayout;
|
|
|
|
|
yield return container;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-31 20:59:35 +00:00
|
|
|
|
public IEnumerable<TileGroupModel> GroupModels
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
foreach (TilePanelLayout item in this.Groups)
|
|
|
|
|
{
|
|
|
|
|
yield return item.Model;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int TileWidthCount { get; private set; } = DEFAULT_COLUMN;
|
|
|
|
|
|
2021-07-31 19:27:29 +00:00
|
|
|
|
|
2021-07-31 20:59:35 +00:00
|
|
|
|
public void Add()
|
|
|
|
|
{
|
2021-08-01 14:25:33 +00:00
|
|
|
|
this.Add(new TilePanelLayout(new TileGroupModel()
|
2021-07-31 20:59:35 +00:00
|
|
|
|
{
|
|
|
|
|
Title = "New Group",
|
|
|
|
|
IsExpanded = true,
|
2021-08-01 14:25:33 +00:00
|
|
|
|
GridSize = new Size(this.TileWidthCount, 1)
|
2021-07-31 20:59:35 +00:00
|
|
|
|
}));
|
2021-08-01 14:25:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(TilePanelLayout tilePanelLayout)
|
|
|
|
|
{
|
|
|
|
|
ThreadControl.Add(flowLayoutPanel1, tilePanelLayout);
|
|
|
|
|
|
|
|
|
|
this.InvalidateColumnSize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Add(int columnCount)
|
|
|
|
|
{
|
|
|
|
|
this.TileWidthCount = ((columnCount <= 0) ? DEFAULT_COLUMN : columnCount);
|
2021-07-31 20:59:35 +00:00
|
|
|
|
|
2021-08-01 14:25:33 +00:00
|
|
|
|
this.Add();
|
2021-07-31 20:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-01 14:25:33 +00:00
|
|
|
|
public void Clear()
|
2021-07-31 19:27:29 +00:00
|
|
|
|
{
|
|
|
|
|
ThreadControl.Clear(flowLayoutPanel1);
|
|
|
|
|
|
2021-07-31 20:59:35 +00:00
|
|
|
|
this.TileWidthCount = DEFAULT_COLUMN;
|
|
|
|
|
|
2021-08-01 14:25:33 +00:00
|
|
|
|
InvalidateColumnSize();
|
|
|
|
|
}
|
2021-07-31 20:59:35 +00:00
|
|
|
|
|
2021-08-01 14:25:33 +00:00
|
|
|
|
public void InvalidateColumnSize()
|
|
|
|
|
{
|
|
|
|
|
this.OnColumnSizeChanged?.Invoke(this, null);
|
2021-07-31 20:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Load(List<TileGroupModel> groupList)
|
|
|
|
|
{
|
|
|
|
|
this.Clear();
|
|
|
|
|
|
|
|
|
|
if (groupList == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (TileGroupModel item in groupList)
|
|
|
|
|
{
|
|
|
|
|
this.TileWidthCount = Math.Max(this.TileWidthCount, item.GridSize.Width);
|
|
|
|
|
|
|
|
|
|
TilePanelLayout panel = new TilePanelLayout(item);
|
|
|
|
|
|
|
|
|
|
this.Add(panel);
|
2021-07-31 19:27:29 +00:00
|
|
|
|
}
|
2021-07-31 20:59:35 +00:00
|
|
|
|
|
2021-08-01 14:25:33 +00:00
|
|
|
|
InvalidateColumnSize();
|
2021-07-31 20:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-07-31 19:27:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|