mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
label offset is now adjusted whenever the text is updated
This commit is contained in:
parent
e43c2fbeb4
commit
4036aa5fc7
@ -1,10 +1,15 @@
|
||||
(function() {
|
||||
// constants
|
||||
var NONE = 'none',
|
||||
var ATTR_CHANGE_LIST = ['fontFamily', 'fontSize', 'fontStyle', 'padding', 'lineHeight', 'text'],
|
||||
CHANGE_KINETIC = 'Change.kinetic',
|
||||
NONE = 'none',
|
||||
UP = 'up',
|
||||
RIGHT = 'right',
|
||||
DOWN = 'down',
|
||||
LEFT = 'left';
|
||||
LEFT = 'left',
|
||||
|
||||
// cached variables
|
||||
attrChangeListLen = ATTR_CHANGE_LIST.length;
|
||||
|
||||
/**
|
||||
* Label constructor. Blobs are defined by an array of points and
|
||||
@ -32,16 +37,27 @@
|
||||
|
||||
Kinetic.Plugins.Label.prototype = {
|
||||
_initLabel: function(config) {
|
||||
var that = this,
|
||||
text = null;
|
||||
|
||||
this.innerGroup = new Kinetic.Group();
|
||||
this.createAttrs();
|
||||
Kinetic.Group.call(this, config);
|
||||
this.setText(new Kinetic.Text(config.text));
|
||||
text = new Kinetic.Text(config.text);
|
||||
this.setText(text);
|
||||
this.setRect(new Kinetic.Plugins.LabelRect(config.rect));
|
||||
this.innerGroup.add(this.getRect());
|
||||
this.innerGroup.add(this.getText());
|
||||
this.innerGroup.add(text);
|
||||
this.add(this.innerGroup);
|
||||
|
||||
this._setGroupOffset();
|
||||
this._setGroupOffset();
|
||||
|
||||
// update text data for certain attr changes
|
||||
for(var n = 0; n < attrChangeListLen; n++) {
|
||||
text.on(ATTR_CHANGE_LIST[n] + CHANGE_KINETIC, function() {
|
||||
that._setGroupOffset();
|
||||
});
|
||||
}
|
||||
},
|
||||
getWidth: function() {
|
||||
return this.getText().getWidth();
|
||||
|
@ -12,7 +12,7 @@ Test.Modules.LABEL = {
|
||||
y: 100,
|
||||
draggable: true,
|
||||
text: {
|
||||
text: 'Hello World!',
|
||||
text: '',
|
||||
fontSize: 50,
|
||||
//fontFamily: 'Calibri',
|
||||
//fontStyle: 'normal',
|
||||
@ -28,7 +28,7 @@ Test.Modules.LABEL = {
|
||||
shadowOffset: [10, 10],
|
||||
shadowOpacity: 0.2,
|
||||
lineJoin: 'round',
|
||||
//pointerDirection: 'down',
|
||||
pointerDirection: 'up',
|
||||
pointerWidth: 20,
|
||||
pointerHeight: 20,
|
||||
cornerRadius: 5
|
||||
@ -44,9 +44,11 @@ Test.Modules.LABEL = {
|
||||
|
||||
var afterTextWidth = label.getText().getWidth();
|
||||
|
||||
test(afterTextWidth > beforeTextWidth, 'label text width should have grown');
|
||||
//test(afterTextWidth > beforeTextWidth, 'label text width should have grown');
|
||||
|
||||
label.getText().setFontSize(50);
|
||||
|
||||
label.getText().setText('Hello big world');
|
||||
|
||||
layer.draw();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user