Skip to content

Commit cc8003d

Browse files
Now works with dynamic resizing
1 parent c5ec83a commit cc8003d

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

‎ConfigGUI/ColorPicker.cs‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ public ColorPicker( string title, char oldColorCode ) {
5757
for ( char code = 'a'; code <= 'f'; code++ )
5858
MakeButton(code);
5959
for (int i = 0; i < Color.ExtColors.Length; i++) {
60-
if (!Color.ExtColors[i].Undefined) MakeButton(Color.ExtColors[i].Code);
60+
if (!Color.ExtColors[i].Undefined) MakeButton(Color.ExtColors[i].Code);
6161
}
6262
MakeCancelButton();
6363
MakeWindow( title );
6464
ResumeLayout( false );
6565
}
6666

6767

68-
const int btnWidth = 130, btnHeight = 40;
68+
const int btnWidth = 130, btnHeight = 40, btnsPerCol = 8;
6969
int index = 0;
7070
void MakeButton( char colCode ) {
71-
int row = index / 8, col = index % 8;
71+
int row = index / btnsPerCol, col = index % btnsPerCol;
7272
index++;
7373

7474
Button btn = new Button();
@@ -91,7 +91,17 @@ void MakeCancelButton() {
9191
Button bCancel = new System.Windows.Forms.Button();
9292
bCancel.DialogResult = DialogResult.Cancel;
9393
bCancel.Font = new System.Drawing.Font( "Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0 );
94-
bCancel.Location = new System.Drawing.Point( 88, 330 );
94+
95+
int rows = 1 + (index / btnsPerCol);
96+
int x = 0;
97+
// Centre if even count, align under row if odd count
98+
if ((rows & 1) == 0) {
99+
x = (rows * btnWidth) / 2 - (100 / 2);
100+
} else {
101+
x = ((rows / 2) * btnWidth) + (btnWidth - 100) / 2;
102+
}
103+
104+
bCancel.Location = new System.Drawing.Point( 8 + x, 10 + btnHeight * btnsPerCol );
95105
bCancel.Name = "bCancel";
96106
bCancel.Size = new System.Drawing.Size( 100, 25 );
97107
bCancel.TabIndex = 260;
@@ -104,7 +114,8 @@ void MakeCancelButton() {
104114
void MakeWindow(string title) {
105115
AutoScaleDimensions = new System.Drawing.SizeF( 8F, 13F );
106116
AutoScaleMode = AutoScaleMode.Font;
107-
ClientSize = new System.Drawing.Size( 278, 367 );
117+
int rows = 1 + (index / btnsPerCol);
118+
ClientSize = new System.Drawing.Size( 18 + btnWidth * rows, 47 + btnHeight * btnsPerCol );
108119
Font = new System.Drawing.Font( "Lucida Console", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, 0 );
109120
FormBorderStyle = FormBorderStyle.FixedDialog;
110121
Margin = new Padding( 4, 3, 4, 3 );

0 commit comments

Comments
 (0)