Skip to content

Commit

Permalink
nikolai/Function block label readability (#3154)
Browse files Browse the repository at this point in the history
* highlight function name & wrap arguments into parenthesis

* put label name variable and field creation into else statement

* removed redundant variable, localize word "function" for label

* variable name fix

Co-authored-by: Matin shafiei <70938039+matin-binary@users.noreply.github.com>
  • Loading branch information
nikolai-deriv and matin-deriv committed May 20, 2021
1 parent 4cc0574 commit 5cebb70
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions packages/bot-skeleton/src/scratch/hooks/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ Blockly.BlockSvg.prototype.setCollapsed = function (collapsed) {
.filter(icon => !(icon instanceof Blockly.ScratchBlockComment))
.forEach(icon => icon.setVisible(false));

const text = this.toString(Blockly.COLLAPSE_CHARS);

// Ensure class persists through collapse. Falls back to first
// field that has a class. Doesn't work when multiple
// field_labels on a block have different classes. So far we
Expand All @@ -264,12 +262,25 @@ Blockly.BlockSvg.prototype.setCollapsed = function (collapsed) {
const dropdown_path =
this.workspace.options.pathToMedia +
(isDarkRgbColour(this.getColour()) ? 'dropdown-arrow.svg' : 'dropdown-arrow-dark.svg');
const field_label = new Blockly.FieldLabel(text, field_class);
const field_expand_icon = new Blockly.FieldImage(dropdown_path, 16, 16, localize('Expand'), () =>
this.setCollapsed(false)
);

this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(field_label).appendField(field_expand_icon).init();
if (this.type === 'procedures_defreturn' || this.type === 'procedures_defnoreturn') {
const function_name = this.getFieldValue('NAME');
const args = ` (${this.arguments.join(', ')})`;

this.appendDummyInput(COLLAPSED_INPUT_NAME)
.appendField(new Blockly.FieldLabel(localize('function'), field_class))
.appendField(new Blockly.FieldLabel(function_name + args, 'header__title'))
.appendField(field_expand_icon)
.init();
} else {
const text = this.toString(Blockly.COLLAPSE_CHARS);
const field_label = new Blockly.FieldLabel(text, field_class);

this.appendDummyInput(COLLAPSED_INPUT_NAME).appendField(field_label).appendField(field_expand_icon).init();
}
} else {
this.removeInput(COLLAPSED_INPUT_NAME);
this.setWarningText(null); // Clear any warnings inherited from enclosed blocks.
Expand Down

0 comments on commit 5cebb70

Please sign in to comment.