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/Tile/TileContainer.cs
2020-04-12 01:12:21 +01:00

127 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using AppLauncher.Models;
namespace AppLauncher.Windows.Forms
{
public partial class TileContainer : AUserControl
{
protected int collapseIncrement = 6;
protected int expandIncrement = 8;
protected TileGroupModel groupInfo = null;
public TileContainer(TileGroupModel model) : base()
{
InitializeComponent();
label1.TileGroupPanel = this;
groupInfo = model;
label1.TitleText = groupInfo.Title;
panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
label1.Checked = groupInfo.IsExpanded;
//label1.Width = panel1.Width;
//label1.PanelHeight = panel1.Height;
//this.Margin = new Padding(0);
//this.Size = new Size(panel1.Width, (label1.Height + panel1.Height));
//this.MaximumSize = this.Size;
//this.MinimumSize = this.Size;
//this.BackColor = Color.MistyRose;
panel1.LoadTiles(model.Items);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
label1.Width = panel1.Width;
this.Margin = new Padding(0);
this.MaximumSize = new Size(panel1.Width, (label1.Height + panel1.ExpandedHeight));
this.MinimumSize = new Size(panel1.Width, label1.Height);
this.Size = this.MaximumSize;
}
protected int collapseHeight => label1.Height + panel1.CollapseHeight;
protected int expandedHeight => label1.Height + panel1.ExpandedHeight;
public async Task Collapse()
{
await Task.Run(() =>
{
while (this.Height > collapseHeight)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Height -= collapseIncrement;
}));
}
else
{
this.Height -= collapseIncrement;
}
Thread.Sleep(10);
}
});
}
public async Task CollapseNow()
{
await Task.Run(() =>
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Height = collapseHeight;
}));
}
else
{
this.Height = collapseHeight;
}
});
}
public async Task Expand()
{
await Task.Run(() =>
{
while (this.Height < expandedHeight)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Height += expandIncrement;
this.Invalidate();
}));
}
else
{
this.Height += expandIncrement;
this.Invalidate();
}
Thread.Sleep(10);
}
});
}
}
}