top left right bottom 增加负数支持
This commit is contained in:
parent
53284484f0
commit
7646ff55de
@ -116,8 +116,8 @@ export default class Painter {
|
|||||||
const lineHeight = view.css.lineHeight ? view.css.lineHeight.toPx() : view.css.fontSize.toPx();
|
const lineHeight = view.css.lineHeight ? view.css.lineHeight.toPx() : view.css.fontSize.toPx();
|
||||||
height = lineHeight * lines;
|
height = lineHeight * lines;
|
||||||
|
|
||||||
x = view.css.right ? this.style.width - view.css.right.toPx() : (view.css.left ? view.css.left.toPx() : 0);
|
x = view.css.right ? this.style.width - view.css.right.toPx(true) : (view.css.left ? view.css.left.toPx(true) : 0);
|
||||||
y = view.css.bottom ? this.style.height - height - view.css.bottom.toPx() : (view.css.top ? view.css.top.toPx() : 0);
|
y = view.css.bottom ? this.style.height - height - view.css.bottom.toPx(true) : (view.css.top ? view.css.top.toPx(true) : 0);
|
||||||
extra = { lines: lines, lineHeight: lineHeight };
|
extra = { lines: lines, lineHeight: lineHeight };
|
||||||
} else {
|
} else {
|
||||||
if (!(view.css.width && view.css.height)) {
|
if (!(view.css.width && view.css.height)) {
|
||||||
@ -126,8 +126,8 @@ export default class Painter {
|
|||||||
}
|
}
|
||||||
width = view.css.width.toPx();
|
width = view.css.width.toPx();
|
||||||
height = view.css.height.toPx();
|
height = view.css.height.toPx();
|
||||||
x = view.css.right ? this.style.width - view.css.right.toPx() : (view.css.left ? view.css.left.toPx() : 0);
|
x = view.css.right ? this.style.width - view.css.right.toPx(true) : (view.css.left ? view.css.left.toPx(true) : 0);
|
||||||
y = view.css.bottom ? this.style.height - height - view.css.bottom.toPx() : (view.css.top ? view.css.top.toPx() : 0);
|
y = view.css.bottom ? this.style.height - height - view.css.bottom.toPx(true) : (view.css.top ? view.css.top.toPx(true) : 0);
|
||||||
}
|
}
|
||||||
const angle = view.css.rotate ? this._getAngle(view.css.rotate) : 0;
|
const angle = view.css.rotate ? this._getAngle(view.css.rotate) : 0;
|
||||||
// 当设置了 right 时,默认 align 用 right,反之用 left
|
// 当设置了 right 时,默认 align 用 right,反之用 left
|
||||||
|
|||||||
13
painter.js
13
painter.js
@ -188,8 +188,17 @@ let screenK = 0.5;
|
|||||||
|
|
||||||
function setStringPrototype() {
|
function setStringPrototype() {
|
||||||
/* eslint-disable no-extend-native */
|
/* eslint-disable no-extend-native */
|
||||||
String.prototype.toPx = function toPx() {
|
/**
|
||||||
const reg = /^[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
* 是否支持负数
|
||||||
|
* @param {Boolean} minus 是否支持负数
|
||||||
|
*/
|
||||||
|
String.prototype.toPx = function toPx(minus) {
|
||||||
|
let reg;
|
||||||
|
if (minus) {
|
||||||
|
reg = /^-?[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
||||||
|
} else {
|
||||||
|
reg = /^[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
||||||
|
}
|
||||||
const results = reg.exec(this);
|
const results = reg.exec(this);
|
||||||
if (!this || !results) {
|
if (!this || !results) {
|
||||||
console.error(`The size: ${this} is illegal`);
|
console.error(`The size: ${this} is illegal`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user