diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index e2c842f..762a934 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -35,7 +35,6 @@ this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); - this.button3 = new System.Windows.Forms.Button(); this.contextMenuStrip1.SuspendLayout(); this.SuspendLayout(); // @@ -90,16 +89,6 @@ this.flowLayoutPanel1.TabIndex = 27; 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 // 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.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None; this.ClientSize = new System.Drawing.Size(1088, 440); - this.Controls.Add(this.button3); this.Controls.Add(this.flowLayoutPanel1); this.Controls.Add(this.titlePanel1); this.Name = "MainForm"; @@ -122,7 +110,6 @@ private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; - private System.Windows.Forms.Button button3; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; } diff --git a/MainForm.cs b/MainForm.cs index e031341..9ab6782 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -42,6 +42,8 @@ namespace AppLauncher { loadSession(jsonfigFilename); } + + this.Width = flowLayoutPanel1.Width + (flowLayoutPanel1.Left * 2); } private async void button1_Click(object sender, EventArgs e) @@ -204,32 +206,19 @@ namespace AppLauncher return; } + int maxWidth = 0; flowLayoutPanel1.Controls.Clear(); foreach (TileGroupModel item in rs) { TileContainer panel = new TileContainer(item); - flowLayoutPanel1.Controls.Add(panel); + maxWidth = Math.Max(maxWidth, panel.Width); - if (item.IsExpanded) - { - //await panel.Expand(); - } + flowLayoutPanel1.Controls.Add(panel); } + 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(); - - } } } diff --git a/Windows/Forms/AddTileForm.cs b/Windows/Forms/AddTileForm.cs index 62c04c8..b065f18 100644 --- a/Windows/Forms/AddTileForm.cs +++ b/Windows/Forms/AddTileForm.cs @@ -358,14 +358,7 @@ namespace AppLauncher.Windows.Forms ProcessAsAdmin = (pickerBox2.ComboBox.SelectedIndex == 1) }; - //parentPanel.LoadInfo(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); + parentPanel.AddTile(model); this.Close(); } diff --git a/Windows/Forms/Tile/TileContainer.cs b/Windows/Forms/Tile/TileContainer.cs index ffaa380..c5adac6 100644 --- a/Windows/Forms/Tile/TileContainer.cs +++ b/Windows/Forms/Tile/TileContainer.cs @@ -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) { diff --git a/Windows/Forms/Tile/TileLayoutPanel.cs b/Windows/Forms/Tile/TileLayoutPanel.cs index 43b3f7b..6a405d7 100644 --- a/Windows/Forms/Tile/TileLayoutPanel.cs +++ b/Windows/Forms/Tile/TileLayoutPanel.cs @@ -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))