WIP: collapsing tile panel + heading

This commit is contained in:
Ray committed 2020-04-05 13:36:39 +01:00
1 parent 0f916de22c
commit 06f570122c
4 files changed
+175 -131

No files matched your search

+5
View File
@@ -48,6 +48,8 @@
this.label1.Size = new System.Drawing.Size(575, 20);
this.label1.TabIndex = 8;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.label1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick);
this.label1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick);
//
// pictureBox1
//
@@ -65,6 +67,8 @@
this.pictureBox1.Size = new System.Drawing.Size(20, 20);
this.pictureBox1.TabIndex = 7;
this.pictureBox1.TabStop = false;
this.pictureBox1.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick);
this.pictureBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick);
//
// HeadingPanel
//
@@ -75,6 +79,7 @@
this.MinimumSize = new System.Drawing.Size(100, 20);
this.Name = "HeadingPanel";
this.Size = new System.Drawing.Size(600, 20);
this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HeadingPanel_MouseClick);
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
+46 -1
View File
@@ -1,4 +1,7 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher.Windows.Forms
{
@@ -11,6 +14,7 @@ namespace AppLauncher.Windows.Forms
InitializeComponent();
this.Checked = false;
}
[Category("Appearance"), Browsable(true)]
@@ -28,5 +32,46 @@ namespace AppLauncher.Windows.Forms
}
}
public TilePanelContainer TilePanelContainer { get; set; } = null;
protected async override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.TilePanelContainer != null)
{
if (this.Checked)
{
await this.TilePanelContainer.Expand(120);
}
else
{
await this.TilePanelContainer.Collapse(0);
}
}
}
private async void HeadingPanel_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
{
return;
}
this.Checked = !this.Checked;
if (this.TilePanelContainer != null)
{
if (this.Checked)
{
await this.TilePanelContainer.Expand(120);
}
else
{
await this.TilePanelContainer.Collapse(0);
}
}
}
}
}
+66 -17
View File
@@ -4,6 +4,7 @@ using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -26,27 +27,72 @@ namespace AppLauncher.Windows.Forms
OnResize(e);
}
protected override void OnResize(EventArgs e)
public Point GridSize
{
base.OnResize(e);
get
{
int w = (int)Math.Floor(decimal.Divide(this.Width, this.TileSize));
int h = (int)Math.Floor(decimal.Divide(this.Height, this.TileSize));
int tileWidth = (tileSize + margin);
int w = (int)Math.Floor(decimal.Divide(this.Width, tileWidth));
int h = (int)Math.Floor(decimal.Divide(this.Height, tileWidth));
this.GridSize = new Point(w, h);
return new Point(w, h);
}
}
public Point GridSize { get; protected set; }
public int TileSize => (tileSize + margin);
public async Task Collapse(int height, int increment = 6)
{
await Task.Run(() =>
{
while (this.Height > height)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Height -= increment;
}));
}
else
{
this.Height -= increment;
}
Thread.Sleep(10);
}
});
}
public async Task Expand(int height, int increment = 8)
{
await Task.Run(() =>
{
while (this.Height < height)
{
if (this.InvokeRequired)
{
this.Invoke(new MethodInvoker(() => {
this.Height += increment;
this.Invalidate();
}));
}
else
{
this.Height += increment;
this.Invalidate();
}
Thread.Sleep(10);
}
});
}
public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y);
public Point GetTileCoord(int posX, int posY)
{
int w = (tileSize + margin);
int x = (int)Math.Round(decimal.Divide(posX, w));
int y = (int)Math.Round(decimal.Divide(posY, w));
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
int y = (int)Math.Round(decimal.Divide(posY, this.TileSize));
if (x < 0) x = 0;
if (y < 0) y = 0;
@@ -58,15 +104,18 @@ namespace AppLauncher.Windows.Forms
public Point GetTilePosition(int posX, int posY)
{
int w = (tileSize + margin);
int x = (int)Math.Round(decimal.Divide(posX, w));
int y = (int)Math.Round(decimal.Divide(posY, w));
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
int y = (int)Math.Round(decimal.Divide(posY, this.TileSize));
if (x < 0) x = 0;
if (y < 0) y = 0;
return new Point((x * w), (y * w));
return new Point((x * this.TileSize), (y * this.TileSize));
}
public void SetGridSize(int width, int height)
{
this.Size = new Size((this.TileSize * width), (this.TileSize * height));
}
}
}
}