forked from ens-lg4/MenulyJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field_textbutton.js
54 lines (36 loc) · 1.88 KB
/
field_textbutton.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @fileoverview Textbutton field.
* @author Leo Gordon
*/
'use strict';
goog.provide('Blockly.FieldTextbutton');
goog.require('Blockly.Field');
Blockly.FieldTextbutton = function(buttontext, changeHandler) {
Blockly.FieldTextbutton.superClass_.constructor.call(this, '');
this.buttontext_ = buttontext;
this.changeHandler_ = changeHandler;
this.setText(buttontext);
};
goog.inherits(Blockly.FieldTextbutton, Blockly.Field);
Blockly.FieldTextbutton.prototype.clone = function() {
return new Blockly.FieldTextbutton(this.buttontext_, this.changeHandler_);
};
Blockly.FieldTextbutton.prototype.CURSOR = 'default';
Blockly.FieldTextbutton.prototype.showEditor_ = function() {
if (this.changeHandler_) {
this.changeHandler_();
}
};
/*
// An example of how to use FieldTextbutton: implementation of a simple register with limiters linked to "-" and "+" buttons
Blockly.Block.appendMinusPlusCounter = function(block, name, startValue, lowerLimit, upperLimit) {
block.appendDummyInput(name+'_input')
.appendField(name+':', name+'_label')
.appendField(String(startValue || '0'), name)
.appendField(new Blockly.FieldTextbutton('–', function() { var counter_=parseInt(this.sourceBlock_.getFieldValue(name))-1; if((lowerLimit===undefined) || counter_>=lowerLimit) { this.sourceBlock_.setFieldValue(String(counter_), name); } }), name+'_minus')
.appendField(new Blockly.FieldTextbutton('+', function() { var counter_=parseInt(this.sourceBlock_.getFieldValue(name))+1; if((upperLimit===undefined) || counter_<=upperLimit) { this.sourceBlock_.setFieldValue(String(counter_), name); } }), name+'_plus');
}
// A usage example of the above. You can add two independent MinusPlusCounters to a block by saying:
Blockly.Block.appendMinusPlusCounter(this, 'age', 0, 0 );
Blockly.Block.appendMinusPlusCounter(this, 'temperature', 37, 34, 42 );
*/