Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nikolai/Function block label readability #3154

Merged
Merged
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