mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 02:03:47 +08:00
after a bit more thought, I've decided to change the maxWidth property to width, to make it even more similar to CSS sizing rules. If you set the width of the text box to a certain value, and the text string width is longer than that width, the text will be clipped
This commit is contained in:
parent
05df078295
commit
92919058b2
21
dist/kinetic-core.js
vendored
21
dist/kinetic-core.js
vendored
@ -3381,14 +3381,11 @@ Kinetic.Text = function(config) {
|
||||
fontFamily: 'Calibri',
|
||||
text: '',
|
||||
fontSize: 12,
|
||||
fill: undefined,
|
||||
textStroke: undefined,
|
||||
textStrokeWidth: undefined,
|
||||
align: 'left',
|
||||
verticalAlign: 'top',
|
||||
padding: 0,
|
||||
fontStyle: 'normal',
|
||||
maxWidth: undefined
|
||||
width: 'auto'
|
||||
});
|
||||
|
||||
this.shapeType = "Text";
|
||||
@ -3398,7 +3395,7 @@ Kinetic.Text = function(config) {
|
||||
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
|
||||
context.textBaseline = 'middle';
|
||||
var textHeight = this.getTextHeight();
|
||||
var textWidth = this.getMaxWidth() === undefined ? this.getTextWidth() : this.getMaxWidth();
|
||||
var textWidth = this.attrs.width === 'auto' ? this.getTextWidth() : this.attrs.width;
|
||||
var p = this.attrs.padding;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
@ -3434,7 +3431,7 @@ Kinetic.Text = function(config) {
|
||||
|
||||
// clipping region for max width
|
||||
context.save();
|
||||
if(this.attrs.maxWidth !== undefined) {
|
||||
if(this.attrs.width !== 'auto') {
|
||||
context.beginPath();
|
||||
context.rect(x, y, textWidth + p, textHeight + p * 2);
|
||||
context.closePath();
|
||||
@ -3635,17 +3632,17 @@ Kinetic.Text.prototype = {
|
||||
};
|
||||
},
|
||||
/**
|
||||
* get max width in pixels
|
||||
* get width in pixels
|
||||
*/
|
||||
getMaxWidth: function() {
|
||||
return this.attrs.maxWidth;
|
||||
getWidth: function() {
|
||||
return this.attrs.width;
|
||||
},
|
||||
/**
|
||||
* set width
|
||||
* @param {Number} max width
|
||||
* @param {Number} width
|
||||
*/
|
||||
setMaxWidth: function(maxWidth) {
|
||||
this.attrs.maxWidth = maxWidth;
|
||||
setWidth: function(width) {
|
||||
this.attrs.width = width;
|
||||
}
|
||||
};
|
||||
// extend Shape
|
||||
|
2
dist/kinetic-core.min.js
vendored
2
dist/kinetic-core.min.js
vendored
File diff suppressed because one or more lines are too long
@ -12,14 +12,11 @@ Kinetic.Text = function(config) {
|
||||
fontFamily: 'Calibri',
|
||||
text: '',
|
||||
fontSize: 12,
|
||||
fill: undefined,
|
||||
textStroke: undefined,
|
||||
textStrokeWidth: undefined,
|
||||
align: 'left',
|
||||
verticalAlign: 'top',
|
||||
padding: 0,
|
||||
fontStyle: 'normal',
|
||||
maxWidth: undefined
|
||||
width: 'auto'
|
||||
});
|
||||
|
||||
this.shapeType = "Text";
|
||||
@ -29,7 +26,7 @@ Kinetic.Text = function(config) {
|
||||
context.font = this.attrs.fontStyle + ' ' + this.attrs.fontSize + 'pt ' + this.attrs.fontFamily;
|
||||
context.textBaseline = 'middle';
|
||||
var textHeight = this.getTextHeight();
|
||||
var textWidth = this.getMaxWidth() === undefined ? this.getTextWidth() : this.getMaxWidth();
|
||||
var textWidth = this.attrs.width === 'auto' ? this.getTextWidth() : this.attrs.width;
|
||||
var p = this.attrs.padding;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
@ -65,7 +62,7 @@ Kinetic.Text = function(config) {
|
||||
|
||||
// clipping region for max width
|
||||
context.save();
|
||||
if(this.attrs.maxWidth !== undefined) {
|
||||
if(this.attrs.width !== 'auto') {
|
||||
context.beginPath();
|
||||
context.rect(x, y, textWidth + p, textHeight + p * 2);
|
||||
context.closePath();
|
||||
@ -266,17 +263,17 @@ Kinetic.Text.prototype = {
|
||||
};
|
||||
},
|
||||
/**
|
||||
* get max width in pixels
|
||||
* get width in pixels
|
||||
*/
|
||||
getMaxWidth: function() {
|
||||
return this.attrs.maxWidth;
|
||||
getWidth: function() {
|
||||
return this.attrs.width;
|
||||
},
|
||||
/**
|
||||
* set width
|
||||
* @param {Number} max width
|
||||
* @param {Number} width
|
||||
*/
|
||||
setMaxWidth: function(maxWidth) {
|
||||
this.attrs.maxWidth = maxWidth;
|
||||
setWidth: function(width) {
|
||||
this.attrs.width = width;
|
||||
}
|
||||
};
|
||||
// extend Shape
|
||||
|
@ -1889,7 +1889,7 @@ Test.prototype.tests = {
|
||||
//draggable: true,
|
||||
align: 'center',
|
||||
verticalAlign: 'middle',
|
||||
maxWidth: 200
|
||||
width: 200
|
||||
});
|
||||
|
||||
layer.add(text);
|
||||
@ -1903,7 +1903,7 @@ Test.prototype.tests = {
|
||||
test(text.getFontStyle() == 'normal', 'font style should be normal');
|
||||
text.setPadding(20);
|
||||
test(text.getPadding() === 20, 'padding should be 20');
|
||||
test(text.getMaxWidth() === 200, 'max width should be 200');
|
||||
test(text.getWidth() === 200, 'width should be 200');
|
||||
|
||||
stage.add(layer);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user