Commit f4456b7c authored by rockyl's avatar rockyl

修复

parent b804b07c
......@@ -738,10 +738,14 @@ export default class Container extends DisplayObject {
// this.scale.x = 1;
// }
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
//子类有用,有_width,才需设置scaleX
this._width = value;
this._localBoundsSelf.width = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......@@ -762,10 +766,14 @@ export default class Container extends DisplayObject {
// } else {
// this.scale.y = 1;
// }
if (!value && value != 0) {
this._height = undefined;
} else {
if (this._height !== value) {
this._height = value;
this._localBoundsSelf.height = value;
//if (this.stage) this.stage.layoutInvalid = true;
}
this.dispatchEvent(Event.RESIZE);
}
}
......
......@@ -94,9 +94,9 @@ export default class Sprite extends Container {
this._texture = null;
this._width = 0;
//this._width = 0;
this._height = 0;
//this._height = 0;
this._tint = null;
this._tintRGB = null;
......@@ -391,14 +391,21 @@ export default class Sprite extends Container {
* @member {number}
*/
get width() {
return Math.abs(this.scale.x) * this._texture.orig.width;
return this._width || Math.abs(this.scale.x) * this._texture.orig.width;
}
set width(value) {
if (this._width !== value) {
if (!value && value != 0) {
this.scale.x = 1
} else {
const s = sign(this.scale.x) || 1;
this.scale.x = s * value / this._texture.orig.width;
}
this._width = value;
this.dispatchEvent(Event.RESIZE);
}
}
/**
......@@ -406,13 +413,22 @@ export default class Sprite extends Container {
* @member {number}
*/
get height() {
return Math.abs(this.scale.y) * this._texture.orig.height;
return this._height || Math.abs(this.scale.y) * this._texture.orig.height;
}
set height(value) {
if (!value && value != 0) {
this._height = undefined;
} else {
if (!value && value != 0) {
this.scale.y = 1
} else {
const s = sign(this.scale.y) || 1;
this.scale.y = s * value / this._texture.orig.height;
}
this._height = value;
this.dispatchEvent(Event.RESIZE);
}
}
/**
......
......@@ -169,28 +169,42 @@ export class TextField extends Sprite {
// private _textHeight: number = 0;
get width(): number {
if (this._width) return this._width;
if (!this._width && this._width != 0) {
this.updateText();
return this.scale.x * this.getLocalBounds().width;
} else {
return this._width;
}
}
set width(value: number) {
if (this._width !== value) {
if (!value && value != 0) {
this._width = undefined;
} else {
this._width = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
}
get height(): number {
if (this._height) return this._height;
if (!this._height && this._height != 0) {
this.updateText();
return this.scale.y * this.getLocalBounds().height;
} else {
return this._height;
}
}
set height(value: number) {
if (this._height !== value) {
if (!value && value != 0) {
this._height = undefined;
} else {
this._height = value;
}
this.dirty = true;
this.dispatchEvent(Event.RESIZE);
}
......@@ -588,7 +602,7 @@ export class TextField extends Sprite {
if (!text) {
s.canvas.width = 0;
s.canvas.height = 0;
if(!this._width && !this._height){
if (!this._width && !this._height) {
s._localBoundsSelf.clear();
}
this.anchorTexture = {x: 0, y: 0};
......@@ -611,7 +625,7 @@ export class TextField extends Sprite {
s.realLines = realLines;
s._prepContext(ctx);
let textWidth = s._width;
let textWidth = !s._width && s._width != 0 ? 0 : s._width;
// let lineH = s._lineSpacing + s.size;
//单行文本时
if (isPureText && text.indexOf("\n") < 0 && s.lineType == TEXT_lINETYPE.SINGLE) {
......@@ -639,7 +653,7 @@ export class TextField extends Sprite {
}
} else {
//textWidth取每行最大值,如果没设置过textWidth
const shouldMeasureTextWidth = !textWidth;
const shouldMeasureTextWidth = !s._width && s._width != 0 ? true : false;
let index = 0;
for (let i = 0, l = hardLines.length; i < l; i++) {
let str = hardLines[i];
......
......@@ -10,8 +10,9 @@ import {devicePixelRatio} from "../../2d/const";
import {Point} from "../../2d/math/Point";
const propPrefixFilter = ['_', '__', '$'];
const includeProps = ['_width', '_height'];
const propTypeFilter = ['function'];
const includeProps = ['_width', '_height', 'worldMatrix'];
const excludeProps = ['eventTypes', 'eventTypes1', 'tempDisplayObjectParent', 'renderable', 'destroyed', 'children', 'start', 'pluginName', 'isUI', 'crossOrigin'];
const propTypeFilter = ['function', 'object'];
const offsetPrefix = 'offset_';
const absValueMapping = {
x: 'a',
......@@ -63,27 +64,39 @@ export class EditorStage extends Node {
let node2 = {};
for (let key in node) {
let pass = false;
if(excludeProps.indexOf(key) >= 0){
pass = true;
}
if(!pass){
for (let prefix of propPrefixFilter) {
if (key.indexOf(prefix) >= 0) {
pass = true;
break;
}
}
if (pass && includeProps.indexOf(key) > 0) {
}
if(key === 'width'){
//debugger
}
let v = node[key];
if (propTypeFilter.indexOf(typeof v) >= 0) {
pass = true;
}
if (includeProps.indexOf(key) >= 0) {
pass = false;
}
if (pass) {
continue;
}
let v = node[key];
if (propTypeFilter.indexOf(typeof v) < 0) {
if (typeof v === 'object') {
v = objClone(v);
}
node2[key] = v;
}
}
return node2;
}
}
......@@ -100,9 +113,9 @@ export class EditorStage extends Node {
for (let key in props) {
let v = props[key];
if (key.indexOf(offsetPrefix) < 0) {
if (emptyProps.indexOf(key) >= 0) {
/*if(!v && v != 0 && emptyProps.indexOf(key) >= 0) {
key = '_' + key;
}
}*/
node[key] = v;
} else {
key = key.replace(offsetPrefix, '');
......
......@@ -32,9 +32,11 @@ class ShapeBase extends Graphics implements IUIComponent {
private onResize(e) {
this.__fieldDirty = true;
//this.onEnterFrame();
}
private onEnterFrame(e) {
private onEnterFrame(e = null) {
if (this.__fieldDirty) {
this.__fieldDirty = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment