From 50043f4b6c81f2e3438087de5ff9d01c15ad3a15 Mon Sep 17 00:00:00 2001 From: Kythyria Tieran Date: Mon, 28 Aug 2023 15:43:02 +0100 Subject: [PATCH] Set a minimum size on the main form --- PD2ModelParser/UI/Form1.Designer.cs | 7 +- PD2ModelParser/UI/ImportPanel.Designer.cs | 2 + PD2ModelParser/UI/ImportPanel.cs | 118 +++++++++++++--------- 3 files changed, 76 insertions(+), 51 deletions(-) diff --git a/PD2ModelParser/UI/Form1.Designer.cs b/PD2ModelParser/UI/Form1.Designer.cs index 529d1c4..fbd7ff9 100644 --- a/PD2ModelParser/UI/Form1.Designer.cs +++ b/PD2ModelParser/UI/Form1.Designer.cs @@ -58,7 +58,7 @@ private void InitializeComponent() // this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.label3.AutoSize = true; - this.label3.Location = new System.Drawing.Point(458, 344); + this.label3.Location = new System.Drawing.Point(458, 366); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(222, 13); this.label3.TabIndex = 6; @@ -133,14 +133,15 @@ private void InitializeComponent() this.mainTabs.Location = new System.Drawing.Point(12, 12); this.mainTabs.Name = "mainTabs"; this.mainTabs.SelectedIndex = 0; - this.mainTabs.Size = new System.Drawing.Size(672, 329); + this.mainTabs.Size = new System.Drawing.Size(672, 351); this.mainTabs.TabIndex = 14; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(696, 366); + this.ClientSize = new System.Drawing.Size(696, 388); + this.MinimumSize = this.SizeFromClientSize(this.ClientSize); this.Controls.Add(this.mainTabs); this.Controls.Add(this.label3); this.Name = "Form1"; diff --git a/PD2ModelParser/UI/ImportPanel.Designer.cs b/PD2ModelParser/UI/ImportPanel.Designer.cs index b1f29c0..a73b0fa 100644 --- a/PD2ModelParser/UI/ImportPanel.Designer.cs +++ b/PD2ModelParser/UI/ImportPanel.Designer.cs @@ -177,6 +177,7 @@ private void InitializeComponent() { labelRootPointHint.Size = new System.Drawing.Size(261, 15); labelRootPointHint.TabIndex = 13; labelRootPointHint.Text = "(which bone new objects should be attached to)"; + labelRootPointHint.AutoEllipsis = true; // // scriptFile // @@ -287,6 +288,7 @@ private void InitializeComponent() { // AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly; Controls.Add(importTransformsBox); Controls.Add(lblScript); Controls.Add(scriptFile); diff --git a/PD2ModelParser/UI/ImportPanel.cs b/PD2ModelParser/UI/ImportPanel.cs index 7b1a833..6316838 100644 --- a/PD2ModelParser/UI/ImportPanel.cs +++ b/PD2ModelParser/UI/ImportPanel.cs @@ -13,68 +13,90 @@ public partial class ImportPanel : UserControl { class ImportPanelLayoutEngine : LayoutEngine { + struct TableRow { + public Label label; + public Control field; + public int labelWidth; + public int minFieldWidth; + public int height; + + public TableRow(Label label, Control field) { + this.label = label; + this.field = field; + + var labelSize = label?.GetPreferredSize(new Size(1,1)) ?? new Size(0,0); + var fieldSize = this.field.GetPreferredSize(new Size(1,1)); + + this.height = Math.Max(labelSize.Height + (label?.Margin.Vertical ?? 0), fieldSize.Height + this.field.Margin.Vertical); + this.minFieldWidth = fieldSize.Width; + this.labelWidth = labelSize.Width + (label?.Margin.Horizontal ?? 0); + } + } + Label[] labels; + Control[] fields; + TableRow[] rows; + + int maxLabelWidth; + int minFieldWidth; public ImportPanelLayoutEngine(ImportPanel panel) { } + private void InitialAnalysis(ImportPanel panel) + { + if(this.rows != null) { return; } + + this.rows = new TableRow[] { + new TableRow(panel.labelSelBaseModel, panel.baseModelFileBrowser), + new TableRow(null, panel.createNewModel), + new TableRow(panel.lblScript, panel.scriptFile), + new TableRow(panel.labelObj, panel.objectFile), + new TableRow(panel.labelPatternUV, panel.patternUVFile), + new TableRow(panel.labelAnimations, panel.animationFiles), + new TableRow(null, panel.createNewObjectsBox), + new TableRow(null, panel.importTransformsBox), + new TableRow(panel.labelRootPoint, panel.rootPoints), + new TableRow(null, panel.labelRootPointHint), + new TableRow(panel.labelSaveTo, panel.outputBox) + }; + + this.maxLabelWidth = this.rows.Select(i => i.labelWidth).Max(); + + var currY = 0; + for (var i = 0; i < rows.Length; i++) + { + var label = rows[i].label; + var labelSize = label?.GetPreferredSize(new Size(1,1)) ?? new Size(0,0); + var rowHeight = this.rows[i].height; + if (label != null) + { + var labelOffsY = (rowHeight - labelSize.Height) / 2; + label.SetBounds(this.maxLabelWidth - (labelSize.Width + label.Margin.Right), currY + labelOffsY, labelSize.Width, labelSize.Height); + } + currY += rowHeight; + } + } + public override bool Layout(object container, LayoutEventArgs layoutEventArgs) { //return base.Layout(container, layoutEventArgs); - var panel = (ImportPanel)container; //Console.WriteLine("Layout"); - this.labels = new Label[] { - panel.labelSelBaseModel, - null, - panel.lblScript, - panel.labelObj, - panel.labelPatternUV, - panel.labelAnimations, - null, - null, - panel.labelRootPoint, - null, - panel.labelSaveTo - }; + var panel = (ImportPanel)container; - var fields = new Control[] - { - panel.baseModelFileBrowser, - panel.createNewModel, - panel.scriptFile, - panel.objectFile, - panel.patternUVFile, - panel.animationFiles, - panel.createNewObjectsBox, - panel.importTransformsBox, - panel.rootPoints, - panel.labelRootPointHint, - panel.outputBox - }; + this.InitialAnalysis(panel); - var maxLabelWidth = this.labels - .Where(i => i != null) - .Select(i => i.PreferredSize.Width + i.Margin.Horizontal ).Max(); var currY = 0; - - for (var i = 0; i < fields.Length; i++) + for (var i = 0; i < rows.Length; i++) { - var label = labels[i]; - var labelSize = label?.GetPreferredSize(new Size(1,1)) ?? new Size(0,0); - var field = fields[i]; + var field = rows[i].field; var fieldSize = field.GetPreferredSize(new Size(1,1)); - var rowHeight = Math.Max(labelSize.Height + (label?.Margin.Vertical ?? 0), fieldSize.Height + field.Margin.Vertical); - - if (label != null) - { - var labelOffsY = (rowHeight - labelSize.Height) / 2; - label.SetBounds(maxLabelWidth - (labelSize.Width + label.Margin.Right), currY + labelOffsY, labelSize.Width, labelSize.Height); - } + var rowHeight = this.rows[i].height; var fieldX = maxLabelWidth + field.Margin.Left; var fieldOffsY = currY + (rowHeight - fieldSize.Height) / 2; @@ -85,7 +107,7 @@ public override bool Layout(object container, LayoutEventArgs layoutEventArgs) var buttonSize = panel.convert.GetPreferredSize(new Size(1, 1)); panel.convert.SetBounds(panel.convert.Margin.Left, currY + panel.convert.Margin.Top, panel.Width - panel.convert.Margin.Horizontal, buttonSize.Height); - currY += panel.convert.Bounds.Bottom + panel.convert.Margin.Bottom; + currY = panel.convert.Bounds.Bottom + panel.convert.Margin.Bottom; //Console.WriteLine("End Layout"); @@ -94,10 +116,10 @@ public override bool Layout(object container, LayoutEventArgs layoutEventArgs) return true; } - public Size GetMinimumSize() - { - throw new NotImplementedException(); - } + //public Size GetMinimumSize() + //{ + // panel + //} } private List root_point_items = new List();