mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
Add lightweight field_number
This commit is contained in:
parent
6c0bf9f966
commit
d89d8a2113
4 changed files with 58 additions and 1 deletions
53
core/field_number.js
Normal file
53
core/field_number.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2016 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Number input field
|
||||
* @author fenichel@google.com (Rachel Fenichel)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
goog.provide('Blockly.FieldNumber');
|
||||
|
||||
goog.require('Blockly.FieldTextInput');
|
||||
|
||||
/**
|
||||
* Class for an editable number field.
|
||||
* @param {string} text The initial content of the field.
|
||||
* @param {Function=} opt_validator An optional function that is called
|
||||
* to validate any constraints on what the user entered. Takes the new
|
||||
* text as an argument and returns either the accepted text, a replacement
|
||||
* text, or null to abort the change.
|
||||
* @extends {Blockly.FieldTextInput}
|
||||
* @constructor
|
||||
*/
|
||||
Blockly.FieldNumber = function(text, opt_validator) {
|
||||
Blockly.FieldNumber.superClass_.constructor.call(this, text,
|
||||
opt_validator);
|
||||
};
|
||||
goog.inherits(Blockly.FieldNumber, Blockly.FieldTextInput);
|
||||
|
||||
/**
|
||||
* Return the current value.
|
||||
* @return {number} Current value as a number
|
||||
*/
|
||||
Blockly.FieldColour.prototype.getValue = function() {
|
||||
return parseFloat(this.text_ || 0);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue