How can I change the color of each category label to same block color?

580 views
Skip to first unread message

Byeong-Kyu Ahn

unread,
Jan 5, 2019, 1:00:36 PM1/5/19
to Blockly
I want change the color of each category to same color with block color.

Is it possible?

As the result of finding code, each category label has class "blocklyTreeLabel" and id ":1.label", ":2.label:, ...

Message has been deleted

Beka Westberg

unread,
Jan 5, 2019, 3:33:26 PM1/5/19
to Blockly
Hello,

There is actually a way to do this without using css! I believe you would want to use colour references. Blockly keeps its colors inside a string table, so that they can be kept consistent more easily.

You would need to set the hue values in the msg/messages.js file

Blockly.Msg.LOGIC_HUE = '210'; // Set this to whatever hue value you want.

And then in your toolbox you can do something like:
<category name="Logic" colour="%{BKY_LOGIC_HUE}"> // This is the important part!
  <-- your blocks here --!>
</category>

You may also need to do a build step if you're running in compressed mode (if you followed the directions on the fixed size workspace page you're probably running in compressed mode). Luckily that's pretty simple!

Just navigate to blockly's root folder through the command line and then run the command:
python build.py langfiles

Hope that helps! If that wasn't what you were looking for be sure to message back!
Beka

Byeong-Kyu Ahn

unread,
Jan 5, 2019, 7:54:14 PM1/5/19
to Blockly
Well, it can change color only blocks. I want change the color of label, for example "Logic".
Thanks.

Beka Westberg

unread,
Jan 6, 2019, 10:04:36 AM1/6/19
to Blockly
Hello,

The lucky thing is that colour references can be used wherever you want. Whether you want to use it on toolbox labels, blocks, or something else, the system doesn't care :D

So in the example above the first line sets the label color, by using the colour attribute of the category.
<category name="Logic" colour="%{BKY_LOGIC_HUE}"> // This line sets the label color

 <-- your blocks here --!>
</category>

You could also set the colour attribute to a hue value and it would still work:
<category name="Logic" colour="210"> // This line sets the label color

 <-- your blocks here --!>
</category>

You can see the documentation about this here.

TL:DR I believe the colour attribute is what you're looking for, colour references would be optional :D

Hope that clarifies things! If you still don't think that's what you're looking for please message back,
Beka

Byeong-Kyu Ahn

unread,
Jan 6, 2019, 8:40:23 PM1/6/19
to Blockly

Yes, you're right. By set the colour attribute, it can change the color - blocks, color box that placed left of the label.
But, the label remained only black color.

Is there ant method to change color label?

Byeong-Kyu Ahn

unread,
Jan 6, 2019, 8:42:43 PM1/6/19
to Blockly
The image attached.
url.png
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Ümit Dönmez

unread,
Jul 23, 2021, 6:26:44 AM7/23/21
to Blockly
How can I change the field label colours?
Reply all
Reply to author
Forward
0 new messages