Mr-Jpelaez / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

ability to specify a color palette for color picker #149

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
hi, the default colors of the color picker aren't of my taste so I wanted to 
change them, I made a quick change to allow me achieve this but maybe you have 
a better solution.

what I do is the following:

Index: core/field_colour.js
===================================================================
--- core/field_colour.js        (revision 1066)
+++ core/field_colour.js        (working copy)
@@ -28,7 +28,6 @@
 goog.require('Blockly.Field');
 goog.require('goog.ui.ColorPicker');

-
 /**
  * Class for a colour input field.
  * @param {string} colour The initial colour in '#rrggbb' format.
@@ -88,6 +87,11 @@
   goog.dom.removeChildren(Blockly.widgetDiv);
   Blockly.widgetDiv.style.display = 'block';
   var picker = goog.ui.ColorPicker.createSimpleColorGrid();
+
+  if (Blockly.FieldColour.colors) {
+      picker.setColors(Blockly.FieldColour.colors);
+  }
+
   picker.render(Blockly.widgetDiv);
   picker.setSelectedColor(this.getValue());

that is, if there's a field called Blockly.FieldColour.colors then use it to 
set the color picker colors.

it looks kind of a hack because I don't know a better place to set that that a 
FieldColour instance would have access to.

after that on the init function you set it to an array of colors and they are 
used in the color picker.

what do you think? do you know a better place to optionally specify a color 
palette? maybe make blockly have a custom color palette by default instead of 
the closure one?

btw, if you want to test, this is the color palette I'm using:

--- apps/code/code.js   (revision 1066)
+++ apps/code/code.js   (working copy)
@@ -107,6 +107,19 @@
   // Add to reserved word list: Local variables in execution evironment (runJS)
   // and the infinite loop detection function.
   Blockly.JavaScript.addReservedWords('code,timeouts,checkTimeout');
+  Blockly.FieldColour.colors = [
+      "#000000", "#3B3131", "#463E3F", "#504A4B", "#5C5858", "#666362",
+      "#726E6D", "#837E7C", "#B6B6B4", "#BCC6CC", "#000080", "#15317E",
+      "#0000A0", "#0041C2", "#1569C7", "#1F45FC", "#1589FF", "#82CAFF",
+      "#78C7C7", "#6CC417", "#52D017", "#54C571", "#85BB65", "#B2C248",
+      "#CCFB5D", "#BCE954", "#EDE275", "#FFFF00", "#FFEBCD", "#ECE5B6",
+      "#FFDB58", "#FDD017", "#F2BB66", "#FBB117", "#E9AB17", "#DEB887",
+      "#C9BE62", "#EE9A4D", "#D4A017", "#F87431", "#FF8040", "#FF7F50",
+      "#F9966B", "#E18B6B", "#F75D59", "#E55B3C", "#F70D1A", "#E42217",
+      "#DC381F", "#C34A2C", "#C24641", "#7F4E52", "#C5908E", "#EDC9AF",
+      "#E38AAE", "#F6358A", "#F535AA", "#CA226B", "#C12283", "#4B0082",
+      "#6A287E", "#6C2DC7", "#7F38EC", "#A23BEC", "#9E7BFF", "#C8A2C8",
+      "#F9B7FF", "#E3E4FA", "#FFFFFF"];

   // Make the 'Blocks' tab line up with the toolbox.
   if (Blockly.Toolbox) {

Original issue reported on code.google.com by luismarianoguerra@gmail.com on 13 Jun 2013 at 4:32

GoogleCodeExporter commented 8 years ago
Looks good to me.  I've rearranged things a bit (mixing English and American 
spellings in "FieldColour.colors" is sub-optimal) and it will land in r1096 
(within a few minutes).

Original comment by neil.fra...@gmail.com on 16 Jul 2013 at 8:35