Archived
Changed: add new tiles positions
This commit is contained in:
1 parent
2c116af5aa
commit
4e322b9fe9
5 files changed
+129
-75
No files matched your search
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using AppLauncher.Models;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Threading;
|
||||
using AppLauncher.Models;
|
||||
|
||||
namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
@@ -32,8 +27,10 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
label1.TitleText = groupInfo.Title;
|
||||
panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
|
||||
this.Width = panel1.Width;
|
||||
label1.Checked = groupInfo.IsExpanded;
|
||||
panel1.LoadTiles(model.Items);
|
||||
panel1.Resize += panel1_Resize;
|
||||
}
|
||||
|
||||
protected override async void OnLoad(EventArgs e)
|
||||
@@ -44,14 +41,20 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
this.Margin = new Padding(0, 0, 0, 0);
|
||||
this.Padding = new Padding(0, 0, 0, 20);
|
||||
this.MaximumSize = new Size(panel1.Width, expandedHeight);
|
||||
this.MinimumSize = new Size(panel1.Width, label1.Height);
|
||||
this.Size = this.MaximumSize;
|
||||
//this.MaximumSize = new Size(panel1.Width, ExpandedHeight);
|
||||
//this.MinimumSize = new Size(panel1.Width, label1.Height);
|
||||
//this.Size = this.MaximumSize;
|
||||
this.Size = new Size(panel1.Width, this.ExpandedHeight);
|
||||
}
|
||||
|
||||
protected int collapseHeight => label1.Height + panel1.CollapseHeight;
|
||||
private async void panel1_Resize(object sender, EventArgs e)
|
||||
{
|
||||
await this.InvalidateContainer();
|
||||
}
|
||||
|
||||
protected int expandedHeight => label1.Height + panel1.ExpandedHeight + this.Padding.Top + this.Padding.Bottom;
|
||||
public int CollapseHeight => label1.Height + panel1.CollapseHeight;
|
||||
|
||||
public int ExpandedHeight => label1.Height + panel1.ExpandedHeight + this.Padding.Top + this.Padding.Bottom;
|
||||
|
||||
public bool IsAnimating => isAnimating;
|
||||
|
||||
@@ -63,7 +66,7 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
while (this.Height > collapseHeight)
|
||||
while (this.Height > this.CollapseHeight)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
@@ -94,12 +97,12 @@ namespace AppLauncher.Windows.Forms
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
this.Invoke(new MethodInvoker(() => {
|
||||
this.Height = collapseHeight;
|
||||
this.Height = this.CollapseHeight;
|
||||
}));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.Height = collapseHeight;
|
||||
this.Height = this.CollapseHeight;
|
||||
}
|
||||
|
||||
isAnimating = false;
|
||||
@@ -114,7 +117,7 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
isAnimating = true;
|
||||
|
||||
while (this.Height < expandedHeight)
|
||||
while (this.Height < this.ExpandedHeight)
|
||||
{
|
||||
if (this.InvokeRequired)
|
||||
{
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
using AppLauncher.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AppLauncher.Windows.Forms
|
||||
{
|
||||
@@ -50,6 +45,24 @@ namespace AppLauncher.Windows.Forms
|
||||
}
|
||||
}
|
||||
|
||||
public TileContainer TileContainer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this.Parent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (this.Parent.GetType() != typeof(TileContainer))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (TileContainer)this.Parent;
|
||||
}
|
||||
}
|
||||
|
||||
public int TileSize => (tileSize + margin);
|
||||
|
||||
public int CollapseHeight => collapseHeight;
|
||||
@@ -58,7 +71,32 @@ namespace AppLauncher.Windows.Forms
|
||||
|
||||
public void AddTile(TileModel tile)
|
||||
{
|
||||
Point gridSize = this.GridSize;
|
||||
|
||||
if (items.Count >= (gridSize.X * gridSize.Y))
|
||||
{
|
||||
this.SetGridSize(gridSize.X, (gridSize.Y + 1));
|
||||
}
|
||||
|
||||
Point? newCoord = findLastFreeCoord();
|
||||
if (newCoord == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tile.Position = newCoord.Value;
|
||||
|
||||
TilePanel panel = new TilePanel();
|
||||
panel.LoadInfo(tile);
|
||||
panel.Location = convertCoordToLocation(tile.Position);
|
||||
|
||||
items.Add(new Item()
|
||||
{
|
||||
Tile = panel,
|
||||
Coord = tile.Position
|
||||
});
|
||||
|
||||
this.Controls.Add(panel);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
@@ -66,21 +104,6 @@ namespace AppLauncher.Windows.Forms
|
||||
this.Controls.Clear();
|
||||
}
|
||||
|
||||
//public Point GetTileCoord(Point location) => this.GetTileCoord(location.X, location.Y);
|
||||
|
||||
//public Point GetTileCoord(int posX, int posY)
|
||||
//{
|
||||
// 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, y);
|
||||
//}
|
||||
|
||||
//public Point GetTilePosition(Point location) => this.GetTilePosition(location.X, location.Y);
|
||||
|
||||
public Point GetTilePosition(int posX, int posY)
|
||||
{
|
||||
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
|
||||
@@ -193,6 +216,65 @@ namespace AppLauncher.Windows.Forms
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
protected Point? findLastFreeCoord()
|
||||
{
|
||||
Point gridSize = this.GridSize;
|
||||
|
||||
// none available
|
||||
if (items.Count >= (gridSize.X * gridSize.Y))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// only one available
|
||||
if (items.Count >= ((gridSize.X * gridSize.Y) - 1))
|
||||
{
|
||||
return findFirstFreeCoord();
|
||||
}
|
||||
|
||||
Point? rv = null;
|
||||
|
||||
for (int y = (gridSize.Y - 1); y >= 0; y--)
|
||||
{
|
||||
for (int x = (gridSize.X - 1); x >= 0; x--)
|
||||
{
|
||||
if (hasTile(new Point(x, y)))
|
||||
{
|
||||
if (rv.HasValue)
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = new Point(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Point? findFirstFreeCoord()
|
||||
{
|
||||
Point gridSize = this.GridSize;
|
||||
|
||||
for (int y = 0; y < gridSize.Y; y++)
|
||||
{
|
||||
for (int x = 0; x < gridSize.X; x++)
|
||||
{
|
||||
if (hasTile(new Point(x, y)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
return new Point(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected Point? resolveCoord(Point coord)
|
||||
{
|
||||
if (!isTileInBounds(coord))
|
||||
|
||||
Reference in new issue
Block a user