# HG changeset patch # User sl # Date 1413307929 -7200 # Node ID dcd2bbb90d422422355118e0a8582d9f72aee4e2 # Parent 2add30edb508a1b9ea2ceab476b78c13bca7f553 Support row and column span. diff -r 2add30edb508 -r dcd2bbb90d42 Client/MainForm.Designer.cs --- a/Client/MainForm.Designer.cs Mon Oct 13 21:42:42 2014 +0200 +++ b/Client/MainForm.Designer.cs Tue Oct 14 19:32:09 2014 +0200 @@ -37,6 +37,7 @@ this.buttonSetTopText = new System.Windows.Forms.Button(); this.buttonLayoutUpdate = new System.Windows.Forms.Button(); this.buttonSetBitmap = new System.Windows.Forms.Button(); + this.buttonLayoutUpdatWithSpan = new System.Windows.Forms.Button(); this.SuspendLayout(); // // buttonSetText @@ -123,11 +124,22 @@ this.buttonSetBitmap.UseVisualStyleBackColor = true; this.buttonSetBitmap.Click += new System.EventHandler(this.buttonSetBitmap_Click); // + // buttonLayoutUpdatWithSpan + // + this.buttonLayoutUpdatWithSpan.Location = new System.Drawing.Point(176, 189); + this.buttonLayoutUpdatWithSpan.Name = "buttonLayoutUpdatWithSpan"; + this.buttonLayoutUpdatWithSpan.Size = new System.Drawing.Size(75, 23); + this.buttonLayoutUpdatWithSpan.TabIndex = 27; + this.buttonLayoutUpdatWithSpan.Text = "Layout span"; + this.buttonLayoutUpdatWithSpan.UseVisualStyleBackColor = true; + this.buttonLayoutUpdatWithSpan.Click += new System.EventHandler(this.buttonLayoutUpdatWithSpan_Click); + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(443, 252); + this.Controls.Add(this.buttonLayoutUpdatWithSpan); this.Controls.Add(this.buttonSetBitmap); this.Controls.Add(this.buttonLayoutUpdate); this.Controls.Add(this.buttonSetTopText); @@ -157,6 +169,7 @@ private System.Windows.Forms.Button buttonSetTopText; private System.Windows.Forms.Button buttonLayoutUpdate; private System.Windows.Forms.Button buttonSetBitmap; + private System.Windows.Forms.Button buttonLayoutUpdatWithSpan; } } diff -r 2add30edb508 -r dcd2bbb90d42 Client/MainForm.cs --- a/Client/MainForm.cs Mon Oct 13 21:42:42 2014 +0200 +++ b/Client/MainForm.cs Tue Oct 14 19:32:09 2014 +0200 @@ -177,7 +177,48 @@ graphics.DrawLine(blackPen, x1, y2, x2, y1); } - iClient.SetBitmap(new BitmapField(0, bitmap)); + BitmapField field = new BitmapField(0, bitmap); + field.ColumnSpan = 2; + iClient.SetBitmap(field); + } + + private void buttonLayoutUpdatWithSpan_Click(object sender, EventArgs e) + { + //Define a 2 by 2 layout + TableLayout layout = new TableLayout(2, 2); + //Second column only takes up 25% + layout.Columns[0].Width = 25F; + layout.Columns[1].Width = 75F; + //Send layout to server + iClient.SetLayout(layout); + + //Set a bitmap for our first field + int x1 = 0; + int y1 = 0; + int x2 = 64; + int y2 = 64; + + Bitmap bitmap = new Bitmap(x2, y2); + Pen blackPen = new Pen(Color.Black, 3); + + // Draw line to screen. + using (var graphics = Graphics.FromImage(bitmap)) + { + graphics.DrawLine(blackPen, x1, y1, x2, y2); + graphics.DrawLine(blackPen, x1, y2, x2, y1); + } + + BitmapField field = new BitmapField(0, bitmap); + field.RowSpan = 2; + iClient.SetBitmap(field); + + //Set texts + iClient.SetTexts(new TextField[] + { + new TextField(1, textBoxTop.Text, Alignment), + new TextField(2, textBoxBottom.Text, Alignment) + }); + } } } diff -r 2add30edb508 -r dcd2bbb90d42 Server/MainForm.cs --- a/Server/MainForm.cs Mon Oct 13 21:42:42 2014 +0200 +++ b/Server/MainForm.cs Tue Oct 14 19:32:09 2014 +0200 @@ -160,7 +160,7 @@ labelFontWidth.Text = "Font width: " + charWidth; } - MarqueeLabel label = null; + MarqueeLabel label = null; //Get the first label control we can find foreach (Control ctrl in tableLayoutPanel.Controls) { @@ -863,18 +863,15 @@ if (client != null) { //Populate our client with the given text fields - int j = 0; foreach (TextField textField in aTextFields) { - if (client.Fields.Count < (j + 1)) + //Make sure all our texts are in place + while (client.Fields.Count < (textField.Index + 1)) { - client.Fields.Add(textField); + //Add a text field with proper index + client.Fields.Add(new TextField(client.Fields.Count)); } - else - { - client.Fields[j] = textField; - } - j++; + client.Fields[textField.Index] = textField; } //Put each our text fields in a label control foreach (TextField field in aTextFields) @@ -1024,7 +1021,7 @@ if (aClient.Fields.Count > 0) { //Create root node for our texts - TreeNode textsRoot = new TreeNode("Text"); + TreeNode textsRoot = new TreeNode("Fields"); node.Nodes.Add(textsRoot); //For each text add a new entry foreach (DataField field in aClient.Fields) @@ -1032,16 +1029,16 @@ if (field is TextField) { TextField textField = (TextField)field; - textsRoot.Nodes.Add(new TreeNode(textField.Text)); + textsRoot.Nodes.Add(new TreeNode("[Text]" + textField.Text)); } else if (field is BitmapField) { - textsRoot.Nodes.Add(new TreeNode("[Bitmap Field]")); + textsRoot.Nodes.Add(new TreeNode("[Bitmap]")); } else { - textsRoot.Nodes.Add(new TreeNode("[Unknown Field Type]")); - } + textsRoot.Nodes.Add(new TreeNode("[Unknown]")); + } } } @@ -1096,6 +1093,7 @@ } } + /// DEPRECATED /// /// Empty and recreate our table layout with the given number of columns and rows. /// Sizes of rows and columns are uniform. @@ -1166,7 +1164,8 @@ private void UpdateTableLayoutPanel(ClientData aClient) { TableLayout layout = aClient.Layout; - + int fieldCount = 0; + tableLayoutPanel.Controls.Clear(); tableLayoutPanel.RowStyles.Clear(); tableLayoutPanel.ColumnStyles.Clear(); @@ -1196,6 +1195,17 @@ this.tableLayoutPanel.RowStyles.Add(layout.Rows[j]); } + //Check if we already have a control + Control existingControl = tableLayoutPanel.GetControlFromPosition(i,j); + if (existingControl!=null) + { + //We already have a control in that cell as a results of row/col spanning + //Move on to next cell then + continue; + } + + fieldCount++; + //Check if a client field already exists for that cell if (aClient.Fields.Count <= tableLayoutPanel.Controls.Count) { @@ -1204,17 +1214,30 @@ } //Create a control corresponding to the field specified for that cell - Control control = CreateControlForDataField(aClient.Fields[tableLayoutPanel.Controls.Count]); + DataField field = aClient.Fields[tableLayoutPanel.Controls.Count]; + Control control = CreateControlForDataField(field); + //Add newly created control to our table layout at the specified row and column tableLayoutPanel.Controls.Add(control, i, j); + //Make sure we specify row and column span for that new control + tableLayoutPanel.SetRowSpan(control,field.RowSpan); + tableLayoutPanel.SetColumnSpan(control, field.ColumnSpan); } } + // + while (aClient.Fields.Count > fieldCount) + { + //We have too much fields for this layout + //Just discard them until we get there + aClient.Fields.RemoveAt(aClient.Fields.Count-1); + } + CheckFontHeight(); } /// - /// Not used yet. + /// Check our type of data field and create corresponding control /// /// private Control CreateControlForDataField(DataField aField)