浏览代码

Finished size abstraction

Patrick Ryan 6 年之前
父节点
当前提交
898832249e
共有 1 个文件被更改,包括 34 次插入19 次删除
  1. 34 19
      gui/src/2D/controls/colorpicker.ts

+ 34 - 19
gui/src/2D/controls/colorpicker.ts

@@ -7,6 +7,7 @@ import { Button } from "./button";
 import { Grid } from "./grid";
 import { Grid } from "./grid";
 import { AdvancedDynamicTexture } from "../advancedDynamicTexture";
 import { AdvancedDynamicTexture } from "../advancedDynamicTexture";
 import { TextBlock } from ".";
 import { TextBlock } from ".";
+import { parse } from "url";
 
 
 /** Class used to create color pickers */
 /** Class used to create color pickers */
 export class ColorPicker extends Control {
 export class ColorPicker extends Control {
@@ -495,7 +496,7 @@ export class ColorPicker extends Control {
             var closeIconColor: Color3;
             var closeIconColor: Color3;
 
 
             // Button settings
             // Button settings
-            var buttonFontSize = 16;
+            var buttonFontSize: number;
             var butEdit: Button;
             var butEdit: Button;
             var buttonWidth: string;
             var buttonWidth: string;
             var buttonHeight: string;
             var buttonHeight: string;
@@ -725,6 +726,7 @@ export class ColorPicker extends Control {
                 }
                 }
             }
             }
 
 
+            // Mode switch to render button text and close symbols on swatch controls
             function EditSwatches(mode?: boolean) {
             function EditSwatches(mode?: boolean) {
                 if (mode !== undefined) {
                 if (mode !== undefined) {
                     editSwatchMode = mode;
                     editSwatchMode = mode;
@@ -744,7 +746,7 @@ export class ColorPicker extends Control {
                         thisButton.textBlock!.text = "";
                         thisButton.textBlock!.text = "";
                     }
                     }
                     if (butEdit !== undefined) {
                     if (butEdit !== undefined) {
-                        butEdit.textBlock!.text = "Edit Swatches";
+                        butEdit.textBlock!.text = "Edit";
                     }
                     }
                 }
                 }
             }
             }
@@ -753,7 +755,7 @@ export class ColorPicker extends Control {
              * When Save Color button is pressed this function will first create a swatch drawer if one is not already
              * When Save Color button is pressed this function will first create a swatch drawer if one is not already
              * made. Then all controls are removed from the drawer and we step through the savedColors array and
              * made. Then all controls are removed from the drawer and we step through the savedColors array and
              * creates one swatch per color. It will also set the height of the drawer control based on how many
              * creates one swatch per color. It will also set the height of the drawer control based on how many
-             * saved colors there are and how many can be stored on one row.
+             * saved colors there are and how many can be stored per row.
              */
              */
             function UpdateSwatches(color: string, button: Button) {
             function UpdateSwatches(color: string, button: Button) {
                 if (options.savedColors) {
                 if (options.savedColors) {
@@ -804,11 +806,11 @@ export class ColorPicker extends Control {
             // Shows or hides edit swatches button depending on if there are saved swatches
             // Shows or hides edit swatches button depending on if there are saved swatches
             function setEditButtonVisibility(enableButton: boolean) {
             function setEditButtonVisibility(enableButton: boolean) {
                 if (enableButton) {
                 if (enableButton) {
-                    butEdit = Button.CreateSimpleButton("butEdit", "Edit Swatches");
+                    butEdit = Button.CreateSimpleButton("butEdit", "Edit");
                     butEdit.width = buttonWidth;
                     butEdit.width = buttonWidth;
-                    butEdit.height = butOK.height;
-                    // butEdit.top = "-10px";
+                    butEdit.height = buttonHeight;
                     butEdit.left = (Math.floor(parseInt(buttonWidth) * 0.1)).toString() + "px";
                     butEdit.left = (Math.floor(parseInt(buttonWidth) * 0.1)).toString() + "px";
+                    butEdit.top = (parseFloat(butEdit.left) * -1).toString() + "px";
                     butEdit.verticalAlignment = Control.VERTICAL_ALIGNMENT_BOTTOM;
                     butEdit.verticalAlignment = Control.VERTICAL_ALIGNMENT_BOTTOM;
                     butEdit.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
                     butEdit.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
                     butEdit.thickness = 2;
                     butEdit.thickness = 2;
@@ -909,8 +911,9 @@ export class ColorPicker extends Control {
             // pickerPanel.width = pickerWidth;
             // pickerPanel.width = pickerWidth;
             pickerPanel.height = options.pickerHeight;
             pickerPanel.height = options.pickerHeight;
             var panelHead: number = parseInt(options.headerHeight) / parseInt(options.pickerHeight);
             var panelHead: number = parseInt(options.headerHeight) / parseInt(options.pickerHeight);
-            pickerPanel.addRowDefinition(panelHead, false);
-            pickerPanel.addRowDefinition(1.0, false);
+            var pickerPanelRows: number[] = [panelHead, 1.0 - panelHead]
+            pickerPanel.addRowDefinition(pickerPanelRows[0], false);
+            pickerPanel.addRowDefinition(pickerPanelRows[1], false);
             dialogContainer.addControl(pickerPanel, 0, 0);
             dialogContainer.addControl(pickerPanel, 0, 0);
 
 
             // Picker container head
             // Picker container head
@@ -995,8 +998,9 @@ export class ColorPicker extends Control {
             var pickerBodyRight: Grid = new Grid();
             var pickerBodyRight: Grid = new Grid();
             pickerBodyRight.name = "Dialogue Right Half";
             pickerBodyRight.name = "Dialogue Right Half";
             pickerBodyRight.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
             pickerBodyRight.horizontalAlignment = Control.HORIZONTAL_ALIGNMENT_LEFT;
-            pickerBodyRight.addRowDefinition(0.514, false);
-            pickerBodyRight.addRowDefinition(0.486, false);
+            var pickerBodyRightRows: number[] = [0.514, 0.486];
+            pickerBodyRight.addRowDefinition(pickerBodyRightRows[0], false);
+            pickerBodyRight.addRowDefinition(pickerBodyRightRows[1], false);
             dialogBody.addControl(pickerBodyRight, 1, 1);
             dialogBody.addControl(pickerBodyRight, 1, 1);
 
 
             // Picker container swatches and buttons
             // Picker container swatches and buttons
@@ -1072,17 +1076,28 @@ export class ColorPicker extends Control {
             var buttonGrid: Grid = new Grid();
             var buttonGrid: Grid = new Grid();
             buttonGrid.name = "Button Grid";
             buttonGrid.name = "Button Grid";
             buttonGrid.height = 0.8;
             buttonGrid.height = 0.8;
-            buttonGrid.addRowDefinition(1 / 3, false);
-            buttonGrid.addRowDefinition(1 / 3, false);
-            buttonGrid.addRowDefinition(1 / 3, false);
+            var buttonGridRows: number = 1 / 3;
+            buttonGrid.addRowDefinition(buttonGridRows, false);
+            buttonGrid.addRowDefinition(buttonGridRows, false);
+            buttonGrid.addRowDefinition(buttonGridRows, false);
             pickerSwatchesButtons.addControl(buttonGrid, 0, 1);
             pickerSwatchesButtons.addControl(buttonGrid, 0, 1);
 
 
+            // Determine pixel width and height for all buttons from overall panel dimensions
             buttonWidth = (Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[1] * 0.67)).toString() + "px";
             buttonWidth = (Math.floor(parseInt(options.pickerWidth) * dialogBodyCols[1] * pickerButtonsCol[1] * 0.67)).toString() + "px";
-                        
+            buttonHeight = (Math.floor(parseInt(options.pickerHeight) * pickerPanelRows[1] * pickerBodyRightRows[0] * (parseFloat(buttonGrid.height.toString()) / 100) * buttonGridRows * 0.7)).toString() + "px";   
+ 
+            // Determine button type size
+            if (parseFloat(buttonWidth) > parseFloat(buttonHeight)) {
+                buttonFontSize = Math.floor(parseFloat(buttonHeight) * 0.45);
+            }
+            else {
+                buttonFontSize= Math.floor(parseFloat(buttonWidth) * 0.11);
+            }
+
             // Panel Buttons
             // Panel Buttons
             var butOK: Button = Button.CreateSimpleButton("butOK", "OK");
             var butOK: Button = Button.CreateSimpleButton("butOK", "OK");
             butOK.width = buttonWidth;
             butOK.width = buttonWidth;
-            butOK.height = 0.7;
+            butOK.height = buttonHeight;
             butOK.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
             butOK.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
             butOK.thickness = 2;
             butOK.thickness = 2;
             butOK.color = buttonColor;
             butOK.color = buttonColor;
@@ -1104,7 +1119,7 @@ export class ColorPicker extends Control {
 
 
             var butCancel: Button = Button.CreateSimpleButton("butCancel", "Cancel");
             var butCancel: Button = Button.CreateSimpleButton("butCancel", "Cancel");
             butCancel.width = buttonWidth;
             butCancel.width = buttonWidth;
-            butCancel.height = 0.7;
+            butCancel.height = buttonHeight;
             butCancel.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
             butCancel.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
             butCancel.thickness = 2;
             butCancel.thickness = 2;
             butCancel.color = buttonColor;
             butCancel.color = buttonColor;
@@ -1125,9 +1140,9 @@ export class ColorPicker extends Control {
             buttonGrid.addControl(butCancel, 1, 0);
             buttonGrid.addControl(butCancel, 1, 0);
 
 
             if (options.savedColors) {
             if (options.savedColors) {
-                var butSave: Button = Button.CreateSimpleButton("butSave", "Save Swatch");
+                var butSave: Button = Button.CreateSimpleButton("butSave", "Save");
                 butSave.width = buttonWidth;
                 butSave.width = buttonWidth;
-                butSave.height = 0.7;
+                butSave.height = buttonHeight;
                 butSave.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
                 butSave.verticalAlignment = Control.VERTICAL_ALIGNMENT_CENTER;
                 butSave.thickness = 2;
                 butSave.thickness = 2;
                 butSave.fontSize = buttonFontSize;
                 butSave.fontSize = buttonFontSize;
@@ -1209,7 +1224,7 @@ export class ColorPicker extends Control {
                 var labelText: TextBlock = new TextBlock();
                 var labelText: TextBlock = new TextBlock();
                 labelText.text = inputFieldLabels[i];
                 labelText.text = inputFieldLabels[i];
                 labelText.color = buttonColor;
                 labelText.color = buttonColor;
-                labelText.fontSize = 16;
+                labelText.fontSize = buttonFontSize;
                 rgbValuesQuadrant.addControl(labelText, i, 0);
                 rgbValuesQuadrant.addControl(labelText, i, 0);
             }
             }