Changed: add new tiles positions

This commit is contained in:
Ray 2020-05-03 11:41:54 +01:00
parent 2c116af5aa
commit 4e322b9fe9
5 changed files with 129 additions and 75 deletions

13
MainForm.Designer.cs generated
View File

@ -35,7 +35,6 @@
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
this.button3 = new System.Windows.Forms.Button();
this.contextMenuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -90,16 +89,6 @@
this.flowLayoutPanel1.TabIndex = 27; this.flowLayoutPanel1.TabIndex = 27;
this.flowLayoutPanel1.WrapContents = false; this.flowLayoutPanel1.WrapContents = false;
// //
// button3
//
this.button3.Location = new System.Drawing.Point(722, 355);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(78, 40);
this.button3.TabIndex = 28;
this.button3.Text = "button3";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -107,7 +96,6 @@
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(83)))), ((int)(((byte)(93))))); this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(76)))), ((int)(((byte)(83)))), ((int)(((byte)(93)))));
this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
this.ClientSize = new System.Drawing.Size(1088, 440); this.ClientSize = new System.Drawing.Size(1088, 440);
this.Controls.Add(this.button3);
this.Controls.Add(this.flowLayoutPanel1); this.Controls.Add(this.flowLayoutPanel1);
this.Controls.Add(this.titlePanel1); this.Controls.Add(this.titlePanel1);
this.Name = "MainForm"; this.Name = "MainForm";
@ -122,7 +110,6 @@
private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
} }

View File

@ -42,6 +42,8 @@ namespace AppLauncher
{ {
loadSession(jsonfigFilename); loadSession(jsonfigFilename);
} }
this.Width = flowLayoutPanel1.Width + (flowLayoutPanel1.Left * 2);
} }
private async void button1_Click(object sender, EventArgs e) private async void button1_Click(object sender, EventArgs e)
@ -204,32 +206,19 @@ namespace AppLauncher
return; return;
} }
int maxWidth = 0;
flowLayoutPanel1.Controls.Clear(); flowLayoutPanel1.Controls.Clear();
foreach (TileGroupModel item in rs) foreach (TileGroupModel item in rs)
{ {
TileContainer panel = new TileContainer(item); TileContainer panel = new TileContainer(item);
flowLayoutPanel1.Controls.Add(panel); maxWidth = Math.Max(maxWidth, panel.Width);
if (item.IsExpanded) flowLayoutPanel1.Controls.Add(panel);
{
//await panel.Expand();
}
} }
flowLayoutPanel1.Width = maxWidth;
} }
private void button3_Click(object sender, EventArgs e)
{
// loadSession(Application.StartupPath.TrimEnd('\\') + "\\test1.jsonfig");
}
private void button1_Click_1(object sender, EventArgs e)
{
EditTileForm addTileForm = new EditTileForm();
addTileForm.ShowDialog();
}
} }
} }

View File

@ -358,14 +358,7 @@ namespace AppLauncher.Windows.Forms
ProcessAsAdmin = (pickerBox2.ComboBox.SelectedIndex == 1) ProcessAsAdmin = (pickerBox2.ComboBox.SelectedIndex == 1)
}; };
//parentPanel.LoadInfo(model); parentPanel.AddTile(model);
//parentPanel.Info.Title = textBox1.Text?.Trim();
//parentPanel.Info.ProcessFilename = textBox2.Text?.Trim();
//parentPanel.Info.ProcessArgument = textBox3.Text?.Trim();
//parentPanel.Info.ProcessWorkingDirectory = textBox4.Text?.Trim();
//parentPanel.Info.ProcessWindowStyle = (System.Diagnostics.ProcessWindowStyle) pickerBox1.ComboBox.SelectedIndex;
//parentPanel.Info.ProcessAsAdmin = (pickerBox2.ComboBox.SelectedIndex == 1);
this.Close(); this.Close();
} }

View File

@ -1,14 +1,9 @@
using System; using AppLauncher.Models;
using System.Collections.Generic; using System;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Data; using System.Threading;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Threading;
using AppLauncher.Models;
namespace AppLauncher.Windows.Forms namespace AppLauncher.Windows.Forms
{ {
@ -32,8 +27,10 @@ namespace AppLauncher.Windows.Forms
label1.TitleText = groupInfo.Title; label1.TitleText = groupInfo.Title;
panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height); panel1.SetGridSize(groupInfo.GridSize.Width, groupInfo.GridSize.Height);
this.Width = panel1.Width;
label1.Checked = groupInfo.IsExpanded; label1.Checked = groupInfo.IsExpanded;
panel1.LoadTiles(model.Items); panel1.LoadTiles(model.Items);
panel1.Resize += panel1_Resize;
} }
protected override async void OnLoad(EventArgs e) protected override async void OnLoad(EventArgs e)
@ -44,14 +41,20 @@ namespace AppLauncher.Windows.Forms
this.Margin = new Padding(0, 0, 0, 0); this.Margin = new Padding(0, 0, 0, 0);
this.Padding = new Padding(0, 0, 0, 20); this.Padding = new Padding(0, 0, 0, 20);
this.MaximumSize = new Size(panel1.Width, expandedHeight); //this.MaximumSize = new Size(panel1.Width, ExpandedHeight);
this.MinimumSize = new Size(panel1.Width, label1.Height); //this.MinimumSize = new Size(panel1.Width, label1.Height);
this.Size = this.MaximumSize; //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; public bool IsAnimating => isAnimating;
@ -63,7 +66,7 @@ namespace AppLauncher.Windows.Forms
isAnimating = true; isAnimating = true;
while (this.Height > collapseHeight) while (this.Height > this.CollapseHeight)
{ {
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
@ -94,12 +97,12 @@ namespace AppLauncher.Windows.Forms
if (this.InvokeRequired) if (this.InvokeRequired)
{ {
this.Invoke(new MethodInvoker(() => { this.Invoke(new MethodInvoker(() => {
this.Height = collapseHeight; this.Height = this.CollapseHeight;
})); }));
} }
else else
{ {
this.Height = collapseHeight; this.Height = this.CollapseHeight;
} }
isAnimating = false; isAnimating = false;
@ -114,7 +117,7 @@ namespace AppLauncher.Windows.Forms
isAnimating = true; isAnimating = true;
while (this.Height < expandedHeight) while (this.Height < this.ExpandedHeight)
{ {
if (this.InvokeRequired) if (this.InvokeRequired)
{ {

View File

@ -1,13 +1,8 @@
using AppLauncher.Models; using AppLauncher.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AppLauncher.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 TileSize => (tileSize + margin);
public int CollapseHeight => collapseHeight; public int CollapseHeight => collapseHeight;
@ -58,7 +71,32 @@ namespace AppLauncher.Windows.Forms
public void AddTile(TileModel tile) 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() public void Clear()
@ -66,21 +104,6 @@ namespace AppLauncher.Windows.Forms
this.Controls.Clear(); 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) public Point GetTilePosition(int posX, int posY)
{ {
int x = (int)Math.Round(decimal.Divide(posX, this.TileSize)); int x = (int)Math.Round(decimal.Divide(posX, this.TileSize));
@ -193,6 +216,65 @@ namespace AppLauncher.Windows.Forms
return new Point(x, y); 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) protected Point? resolveCoord(Point coord)
{ {
if (!isTileInBounds(coord)) if (!isTileInBounds(coord))