| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| |
| |
| |
|
|
| 'use strict';
|
|
|
| goog.provide('Blockly.FieldButton');
|
|
|
| goog.require('Blockly.Field');
|
|
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.FieldButton = function(state, opt_validator) {
|
| Blockly.FieldButton.superClass_.constructor.call(this, '', opt_validator);
|
| this.text_ = state.image_url ? '' : state.label;
|
| this.opcode_ = state.opcode;
|
| this.color_ = state.color || {};
|
| this.updateTextNode_()
|
| this.addArgType('button');
|
| };
|
| goog.inherits(Blockly.FieldButton, Blockly.Field);
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| Blockly.FieldButton.fromJson = function(options) {
|
| return new Blockly.FieldButton(options);
|
| };
|
|
|
| |
| |
|
|
| Blockly.FieldButton.prototype.CURSOR = 'pointer';
|
|
|
| |
| |
|
|
| Blockly.FieldButton.prototype.init = function() {
|
| if (this.fieldGroup_) {
|
|
|
| return;
|
| }
|
| Blockly.FieldButton.superClass_.init.call(this);
|
|
|
| this.box_ = Blockly.utils.createSvgElement('rect',
|
| {
|
| 'x': 0,
|
| 'y': 0,
|
| 'rx': 4,
|
| 'ry': 4,
|
| 'width': this.size_.width,
|
| 'height': this.size_.height,
|
| 'fill': this.color_.primary || this.sourceBlock_.getColour(),
|
| 'stroke': this.color_.tertiary || this.sourceBlock_.getColourTertiary(),
|
| 'cursor': this.CURSOR
|
| }
|
| );
|
| this.textElement_.remove();
|
| this.textElement_ = Blockly.utils.createSvgElement('text',
|
| {
|
| 'class': 'blocklyText',
|
| 'y': this.size_.height / 2 + Blockly.BlockSvg.FIELD_TOP_PADDING,
|
| 'text-anchor': 'middle',
|
| 'dominant-baseline': 'middle',
|
| 'dy': goog.userAgent.EDGE_OR_IE ? Blockly.Field.IE_TEXT_OFFSET : '0',
|
| 'fill': this.color_.text || "#fff",
|
| }, null);
|
| this.fieldGroup_.append(this.textElement_)
|
| this.fieldGroup_.insertBefore(this.box_, this.textElement_);
|
| };
|
|
|
| |
| |
| |
|
|
| Blockly.FieldButton.prototype.getValue = function() {
|
| return '';
|
| };
|
| |
| |
| |
|
|
| Blockly.FieldButton.prototype.showEditor_ = function() {
|
| this.sourceBlock_.onFieldButtonClicked_(this.opcode_);
|
| };
|
|
|
| Blockly.Field.register('field_button', Blockly.FieldButton); |