2020-04-11 17:43:20 +00:00
|
|
|
|
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;
|
2020-05-02 16:17:10 +00:00
|
|
|
|
protected bool isAnimating = false;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
public TileContainer(TileGroupModel model) : base()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
this.ContextMenuStrip = contextMenuStrip1;
|
|
|
|
|
//this.BackColor = Color.MistyRose;
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
label1.TileGroupPanel = this;
|
|
|
|
|
|
|
|
|
|
groupInfo = model;
|
|
|
|
|
|
|
|
|
|
label1.TitleText = groupInfo.Title;
|
|
|
|
|
panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
|
|
|
|
|
label1.Checked = groupInfo.IsExpanded;
|
|
|
|
|
panel1.LoadTiles(model.Items);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
protected override async void OnLoad(EventArgs e)
|
2020-04-11 17:43:20 +00:00
|
|
|
|
{
|
|
|
|
|
base.OnLoad(e);
|
|
|
|
|
|
|
|
|
|
label1.Width = panel1.Width;
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
this.Margin = new Padding(0, 0, 0, 0);
|
|
|
|
|
this.Padding = new Padding(0, 0, 0, 20);
|
|
|
|
|
this.MaximumSize = new Size(panel1.Width, expandedHeight);
|
2020-04-11 17:43:20 +00:00
|
|
|
|
this.MinimumSize = new Size(panel1.Width, label1.Height);
|
|
|
|
|
this.Size = this.MaximumSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected int collapseHeight => label1.Height + panel1.CollapseHeight;
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
protected int expandedHeight => label1.Height + panel1.ExpandedHeight + this.Padding.Top + this.Padding.Bottom;
|
|
|
|
|
|
|
|
|
|
public bool IsAnimating => isAnimating;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
|
|
|
|
|
public async Task Collapse()
|
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (isAnimating) return;
|
|
|
|
|
|
|
|
|
|
isAnimating = true;
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
while (this.Height > collapseHeight)
|
|
|
|
|
{
|
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(new MethodInvoker(() => {
|
|
|
|
|
this.Height -= collapseIncrement;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Height -= collapseIncrement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Thread.Sleep(10);
|
|
|
|
|
}
|
2020-05-02 16:17:10 +00:00
|
|
|
|
|
|
|
|
|
isAnimating = false;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task CollapseNow()
|
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (isAnimating) return;
|
|
|
|
|
|
|
|
|
|
isAnimating = true;
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
if (this.InvokeRequired)
|
|
|
|
|
{
|
|
|
|
|
this.Invoke(new MethodInvoker(() => {
|
|
|
|
|
this.Height = collapseHeight;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
this.Height = collapseHeight;
|
|
|
|
|
}
|
2020-05-02 16:17:10 +00:00
|
|
|
|
|
|
|
|
|
isAnimating = false;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task Expand()
|
|
|
|
|
{
|
|
|
|
|
await Task.Run(() =>
|
|
|
|
|
{
|
2020-05-02 16:17:10 +00:00
|
|
|
|
if (isAnimating) return;
|
|
|
|
|
|
|
|
|
|
isAnimating = true;
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
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);
|
|
|
|
|
}
|
2020-05-02 16:17:10 +00:00
|
|
|
|
|
|
|
|
|
isAnimating = false;
|
2020-04-11 17:43:20 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-02 16:17:10 +00:00
|
|
|
|
public async Task InvalidateContainer(bool animate = true)
|
|
|
|
|
{
|
|
|
|
|
if (this.IsAnimating)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (label1.Checked)
|
|
|
|
|
{
|
|
|
|
|
await this.Expand();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (animate)
|
|
|
|
|
{
|
|
|
|
|
await this.Collapse();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
await this.CollapseNow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
AddTileForm addForm = new AddTileForm(panel1);
|
|
|
|
|
addForm.ShowDialog();
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-11 17:43:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|