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

92 lines
2.7 KiB
C#

using FizzyLauncher.Models;
using RyzStudio.Windows.Forms;
using System;
using System.Collections.Generic;
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 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);
}
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 void Add(TilePanelLayout tilePanelLayout)
{
ThreadControl.Add(flowLayoutPanel1, tilePanelLayout);
}
public void Clear(bool addDefault = false)
{
ThreadControl.Clear(flowLayoutPanel1);
if (addDefault)
{
flowLayoutPanel1.Controls.Add(new TilePanelLayout(new TileGroupModel()
{
Title = "New Group",
IsExpanded = true,
GridSize = new Size(6, 1)
}));
}
}
}
}