mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-13 22:49:02 -04:00
Dropdown menu categories (#647)
* add getter for category * set dropdown's data-category to parent block's category * remove unused parameter
This commit is contained in:
parent
bac07dc65a
commit
d00c2942e4
7 changed files with 33 additions and 5 deletions
|
@ -132,6 +132,12 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
|
|||
* @private
|
||||
*/
|
||||
this.outputShape_ = null;
|
||||
|
||||
/**
|
||||
* @type {?string}
|
||||
* @private
|
||||
*/
|
||||
this.category_ = null;
|
||||
|
||||
/**
|
||||
* @type {!goog.math.Coordinate}
|
||||
|
@ -1472,7 +1478,15 @@ Blockly.Block.prototype.getOutputShape = function() {
|
|||
* @param {?string} category The block's category (see constants.js).
|
||||
*/
|
||||
Blockly.Block.prototype.setCategory = function(category) {
|
||||
this.category = category;
|
||||
this.category_ = category;
|
||||
};
|
||||
|
||||
/**
|
||||
* Get this block's category (for styling purposes)
|
||||
* @return {?string} category The block's category (see constants.js).
|
||||
*/
|
||||
Blockly.Block.prototype.getCategory = function() {
|
||||
return this.category_;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -631,8 +631,8 @@ Blockly.BlockSvg.prototype.renderClassify_ = function(metrics) {
|
|||
|
||||
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
|
||||
|
||||
if (this.category) {
|
||||
this.svgGroup_.setAttribute('data-category', this.category);
|
||||
if (this.getCategory()) {
|
||||
this.svgGroup_.setAttribute('data-category', this.getCategory());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1020,8 +1020,8 @@ Blockly.BlockSvg.prototype.renderClassify_ = function() {
|
|||
|
||||
this.svgGroup_.setAttribute('data-shapes', shapes.join(' '));
|
||||
|
||||
if (this.category) {
|
||||
this.svgGroup_.setAttribute('data-category', this.category);
|
||||
if (this.getCategory()) {
|
||||
this.svgGroup_.setAttribute('data-category', this.getCategory());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -163,6 +163,14 @@ Blockly.DropDownDiv.setColour = function(backgroundColour, borderColour) {
|
|||
Blockly.DropDownDiv.DIV_.style.borderColor = borderColour;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set the category for the drop-down.
|
||||
* @param {string} category The new category for the drop-down.
|
||||
*/
|
||||
Blockly.DropDownDiv.setCategory = function(category) {
|
||||
Blockly.DropDownDiv.DIV_.setAttribute('data-category', category);
|
||||
};
|
||||
|
||||
/**
|
||||
* Shortcut to show and place the drop-down with positioning determined
|
||||
* by a particular block. The primary position will be below the block,
|
||||
|
|
|
@ -170,6 +170,7 @@ Blockly.FieldAngle.prototype.showEditor_ = function() {
|
|||
|
||||
Blockly.DropDownDiv.setColour(this.sourceBlock_.parentBlock_.getColour(),
|
||||
this.sourceBlock_.getColourTertiary());
|
||||
Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
|
||||
Blockly.DropDownDiv.showPositionedByBlock(this, this.sourceBlock_);
|
||||
|
||||
this.clickWrapper_ =
|
||||
|
|
|
@ -192,6 +192,10 @@ Blockly.FieldDropdown.prototype.showEditor_ = function() {
|
|||
this.sourceBlock_.parentBlock_.getColour() : this.sourceBlock_.getColour();
|
||||
|
||||
Blockly.DropDownDiv.setColour(primaryColour, this.sourceBlock_.getColourTertiary());
|
||||
|
||||
var category = (this.sourceBlock_.isShadow()) ?
|
||||
this.sourceBlock_.parentBlock_.getCategory() : this.sourceBlock_.getCategory();
|
||||
Blockly.DropDownDiv.setCategory(category);
|
||||
|
||||
// Calculate positioning based on the field position.
|
||||
var scale = this.sourceBlock_.workspace.scale;
|
||||
|
|
|
@ -234,6 +234,7 @@ Blockly.FieldIconMenu.prototype.showEditor_ = function() {
|
|||
contentDiv.style.width = Blockly.FieldIconMenu.DROPDOWN_WIDTH + 'px';
|
||||
|
||||
Blockly.DropDownDiv.setColour(this.sourceBlock_.getColour(), this.sourceBlock_.getColourTertiary());
|
||||
Blockly.DropDownDiv.setCategory(this.sourceBlock_.parentBlock_.getCategory());
|
||||
|
||||
// Update source block colour to look selected
|
||||
this.savedPrimary_ = this.sourceBlock_.getColour();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue