Changed: tile container size invalidation

This commit is contained in:
Ray 2021-07-31 21:59:35 +01:00
parent d8af3d4279
commit 9c293dd4f0
3 changed files with 95 additions and 65 deletions

View File

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text.Json; using System.Text.Json;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -39,6 +40,7 @@ namespace FizzyLauncher
{ {
InitializeComponent(); InitializeComponent();
tileContainer1.OnColumnSizeChanged += tileContainer1_OnSizeChanged;
notifyIcon1.Text = Application.ProductName; notifyIcon1.Text = Application.ProductName;
this.AutoScaleMode = AutoScaleMode.None; this.AutoScaleMode = AutoScaleMode.None;
@ -231,15 +233,6 @@ namespace FizzyLauncher
protected void newSession() protected void newSession()
{ {
tileContainer1.Clear(true); tileContainer1.Clear(true);
//flowLayoutPanel1.Controls.Clear();
//flowLayoutPanel1.Controls.Add(new TilePanelLayout(new TileGroupModel()
//{
// Title = "New Group",
// IsExpanded = true,
// GridSize = new Size(6, 1)
//}));
InvalidateWidth(6);
} }
protected async Task loadFile(string filename) protected async Task loadFile(string filename)
@ -301,23 +294,7 @@ namespace FizzyLauncher
} }
// load tiles // load tiles
int maxTileWidth = 0; tileContainer1.Load(this.CurrentSession.Groups);
tileContainer1.Clear();
if (this.CurrentSession.Groups != null)
{
foreach (TileGroupModel item in this.CurrentSession.Groups)
{
maxTileWidth = Math.Max(maxTileWidth, item.GridSize.Width);
TilePanelLayout panel = new TilePanelLayout(item);
tileContainer1.Add(panel);
}
}
// resize
InvalidateSize(maxTileWidth);
// reposition // reposition
if (!this.CurrentSession.StartPosition.IsEmpty) ThreadControl.SetLocation(this, this.CurrentSession.StartPosition); if (!this.CurrentSession.StartPosition.IsEmpty) ThreadControl.SetLocation(this, this.CurrentSession.StartPosition);
@ -327,6 +304,7 @@ namespace FizzyLauncher
ThreadControl.SetVisible(this, true); ThreadControl.SetVisible(this, true);
ThreadControl.SetChecked(enableAnimationsToolStripMenuItem, this.CurrentSession.EnableAnimation); ThreadControl.SetChecked(enableAnimationsToolStripMenuItem, this.CurrentSession.EnableAnimation);
ThreadControl.SetChecked(showBigIconsToolStripMenuItem, this.CurrentSession.EnableBigIconInFolder); ThreadControl.SetChecked(showBigIconsToolStripMenuItem, this.CurrentSession.EnableBigIconInFolder);
ThreadControl.SetClientHeight(this, this.CurrentSession.DefaultHeight);
ThreadControl.SetFocus(this); ThreadControl.SetFocus(this);
@ -364,14 +342,7 @@ namespace FizzyLauncher
this.CurrentSession.DefaultHeight = this.Height; this.CurrentSession.DefaultHeight = this.Height;
this.CurrentSession.AlwaysOnTop = this.TopMost; this.CurrentSession.AlwaysOnTop = this.TopMost;
this.CurrentSession.StartPosition = this.Location; this.CurrentSession.StartPosition = this.Location;
this.CurrentSession.Groups = tileContainer1.GroupModels?.ToList() ?? new List<TileGroupModel>();
// save
this.CurrentSession.Groups = new List<TileGroupModel>();
foreach (TilePanelLayout item in tileContainer1.Groups)
{
this.CurrentSession.Groups.Add(item.Model);
}
var options = new JsonSerializerOptions(); var options = new JsonSerializerOptions();
options.Converters.Add(new JsonPointConverter()); options.Converters.Add(new JsonPointConverter());
@ -419,28 +390,6 @@ namespace FizzyLauncher
return false; return false;
} }
protected void InvalidateSize(int columnWidth)
{
int newWidth = TilePanelLayout.CalcWidth(columnWidth);
newWidth += SystemInformation.VerticalScrollBarWidth;
newWidth += tileContainer1.CalcWidth;
newWidth += this.Padding.Horizontal;
ThreadControl.ClientSize(this, newWidth, this.CurrentSession.DefaultHeight);
}
protected void InvalidateWidth(int columnWidth)
{
int newWidth = TilePanelLayout.CalcWidth(columnWidth);
newWidth += SystemInformation.VerticalScrollBarWidth;
newWidth += tileContainer1.CalcWidth;
newWidth += this.Padding.Horizontal;
ThreadControl.SetClientWidth(this, newWidth);
}
#region main menu #region main menu
private void newToolStripMenuItem_Click(object sender, EventArgs e) private void newToolStripMenuItem_Click(object sender, EventArgs e)
@ -669,9 +618,18 @@ namespace FizzyLauncher
this.Close(); this.Close();
} }
#endregion
private void tileContainer1_OnSizeChanged(object sender, EventArgs e)
{
int newWidth = TilePanelLayout.CalcWidth(tileContainer1.TileWidthCount);
newWidth += SystemInformation.VerticalScrollBarWidth;
newWidth += tileContainer1.CalcWidth;
newWidth += this.Padding.Horizontal;
ThreadControl.SetClientWidth(this, newWidth);
}
#endregion
} }
} }

View File

@ -399,9 +399,9 @@ namespace RyzStudio.Windows.Forms
} }
} }
public static void ClientSize(Control control, int width, int height) => ClientSize(control, new Size(width, height)); public static void SetClientSize(Control control, int width, int height) => SetClientSize(control, new Size(width, height));
public static void ClientSize(Control control, Size value) public static void SetClientSize(Control control, Size value)
{ {
if (control.InvokeRequired) if (control.InvokeRequired)
{ {
@ -415,6 +415,20 @@ namespace RyzStudio.Windows.Forms
} }
} }
public static void SetClientHeight(Control control, int value)
{
if (control.InvokeRequired)
{
control.Invoke(new MethodInvoker(() => {
control.ClientSize = new Size(control.ClientSize.Width, value);
}));
}
else
{
control.ClientSize = new Size(control.ClientSize.Width, value);
}
}
public static void SetSize(Control control, int width, int height) => SetSize(control, new Size(width, height)); public static void SetSize(Control control, int width, int height) => SetSize(control, new Size(width, height));
public static void SetSize(Control control, Size value) public static void SetSize(Control control, Size value)

View File

@ -2,6 +2,7 @@
using RyzStudio.Windows.Forms; using RyzStudio.Windows.Forms;
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.Text;
@ -12,6 +13,8 @@ namespace FizzyLauncher.Windows.Forms
{ {
public class TileContainer : Panel public class TileContainer : Panel
{ {
protected const int DEFAULT_COLUMN = 6;
protected FlowLayoutPanel flowLayoutPanel1 = null; protected FlowLayoutPanel flowLayoutPanel1 = null;
@ -38,6 +41,10 @@ namespace FizzyLauncher.Windows.Forms
} }
[Browsable(false)]
public event EventHandler OnColumnSizeChanged;
public int CalcWidth public int CalcWidth
{ {
get => flowLayoutPanel1.Padding.Horizontal + flowLayoutPanel1.Margin.Horizontal + this.Left + this.Padding.Horizontal + this.Margin.Horizontal; get => flowLayoutPanel1.Padding.Horizontal + flowLayoutPanel1.Margin.Horizontal + this.Left + this.Padding.Horizontal + this.Margin.Horizontal;
@ -65,25 +72,76 @@ namespace FizzyLauncher.Windows.Forms
} }
} }
public IEnumerable<TileGroupModel> GroupModels
{
get
{
foreach (TilePanelLayout item in this.Groups)
{
yield return item.Model;
}
}
}
public int TileWidthCount { get; private set; } = DEFAULT_COLUMN;
public void Add(TilePanelLayout tilePanelLayout) public void Add(TilePanelLayout tilePanelLayout)
{ {
ThreadControl.Add(flowLayoutPanel1, tilePanelLayout); ThreadControl.Add(flowLayoutPanel1, tilePanelLayout);
} }
public void Add()
{
ThreadControl.Add(flowLayoutPanel1, new TilePanelLayout(new TileGroupModel()
{
Title = "New Group",
IsExpanded = true,
GridSize = new Size(6, 1)
}));
this.TileWidthCount = Math.Max(this.TileWidthCount, 6);
}
public void Clear(bool addDefault = false) public void Clear(bool addDefault = false)
{ {
ThreadControl.Clear(flowLayoutPanel1); ThreadControl.Clear(flowLayoutPanel1);
this.TileWidthCount = DEFAULT_COLUMN;
if (addDefault) if (addDefault)
{ {
flowLayoutPanel1.Controls.Add(new TilePanelLayout(new TileGroupModel() this.Add();
{
Title = "New Group",
IsExpanded = true,
GridSize = new Size(6, 1)
}));
} }
ColumnSizeChanged();
}
public void Load(List<TileGroupModel> groupList)
{
this.Clear();
if (groupList == null)
{
return;
}
foreach (TileGroupModel item in groupList)
{
this.TileWidthCount = Math.Max(this.TileWidthCount, item.GridSize.Width);
TilePanelLayout panel = new TilePanelLayout(item);
this.Add(panel);
}
ColumnSizeChanged();
}
protected void ColumnSizeChanged()
{
this.OnColumnSizeChanged?.Invoke(this, null);
} }