You can put a button or label anywhere you can put a block in the toolbox.
JSON
{
"kind": "flyoutToolbox",
"contents": [
{
"kind": "block",
"type":"logic_operation"
},
{
"kind": "label",
"text": "A label",
"web-class": "myLabelStyle"
},
{
"kind": "label",
"text": "Another label"
},
{
"kind": "block",
"type": "logic_negate"
},
{
"kind": "button",
"text": "A button",
"callbackKey": "myFirstButtonPressed"
},
{
"kind": "block",
"type": "logic_boolean"
}
]
}
XML
<xml id="toolbox" style="display: none">
<block type="logic_operation"></block>
<label text="A label" web-class="myLabelStyle"></label>
<label text="Another label"></label>
<block type="logic_negate"></block>
<button text="A button" callbackKey="myFirstButtonPressed"></button>
<block type="logic_boolean"></block>
</xml>
<style>
.myLabelStyle>.blocklyFlyoutLabelText {
font-style: italic;
fill: green;
}
</style>
You may specify a CSS class name to apply to your button or label. In the above example, the first label uses a custom style, while the second label uses the default style.
Buttons should have callback functions; labels should not. To set the callback for a given button click, use
yourWorkspace.registerButtonCallback(yourCallbackKey, yourFunction).
Your function should accept as an argument the button that was clicked. The "Create variable..." button in the variable category is a good example of a button with a callback.