Skip to content

Commit

Permalink
return-applyColour()
Browse files Browse the repository at this point in the history
The new version of FieldColorNumber does not apply applyColour() inside the doValueUpdate_() method. Secondly, the applyColour() method was redesigned in the new version so that it no longer worked with this enum code.
  • Loading branch information
THEb0nny committed Mar 21, 2024
1 parent 0c685bc commit c63d81e
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions fieldeditors/field_color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber {
});
}

doValueUpdate_(colour: string) {
super.doValueUpdate_(colour);
this.applyColour();
}

applyColour() {
if (this.borderRect_) {
this.borderRect_.style.fill = this.value_;
} else if (this.sourceBlock_) {
(this.sourceBlock_ as any)?.pathObject?.svgPath?.setAttribute('fill', this.value_);
(this.sourceBlock_ as any)?.pathObject?.svgPath?.setAttribute('stroke', '#fff');
}
};

/**
* Return the current colour.
* @param {boolean} opt_asHex optional field if the returned value should be a hex
Expand All @@ -73,8 +87,6 @@ export class FieldColorEnum extends pxtblockly.FieldColorNumber {
const colour = this.mapColour(this.value_);
if (!opt_asHex && colour.indexOf('#') > -1) {
return `0x${colour.replace(/^#/, '')}`;
} else if (opt_asHex) {
return this.value_;
}
return colour;
}
Expand Down

0 comments on commit c63d81e

Please sign in to comment.