This repository has been archived on 2024-08-06. You can view files and clone it, but cannot push or open issues or pull requests.
linear-app-launcher/Windows/Forms/TileContainer.cs

150 lines
4.0 KiB
C#
Raw Normal View History

using FizzyLauncher.Models;
using RyzStudio.Windows.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
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
{
protected const int DEFAULT_COLUMN = 6;
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);
}
[Browsable(false)]
public event EventHandler OnColumnSizeChanged;
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;
}
}
}
public IEnumerable<TileGroupModel> GroupModels
{
get
{
foreach (TilePanelLayout item in this.Groups)
{
yield return item.Model;
}
}
}
public int TileWidthCount { get; private set; } = DEFAULT_COLUMN;
public void Add(TilePanelLayout tilePanelLayout)
{
ThreadControl.Add(flowLayoutPanel1, tilePanelLayout);
}
public void Add()
{
ThreadControl.Add(flowLayoutPanel1, new TilePanelLayout(new TileGroupModel()
{
Title = "New Group",
IsExpanded = true,
GridSize = new Size(6, 1)
}));
this.TileWidthCount = Math.Max(this.TileWidthCount, 6);
}
public void Clear(bool addDefault = false)
{
ThreadControl.Clear(flowLayoutPanel1);
this.TileWidthCount = DEFAULT_COLUMN;
if (addDefault)
{
this.Add();
}
ColumnSizeChanged();
}
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);
}
ColumnSizeChanged();
}
protected void ColumnSizeChanged()
{
this.OnColumnSizeChanged?.Invoke(this, null);
}
}
}