From 29aa977774fe615f11b4110846f12682d2bf43b6 Mon Sep 17 00:00:00 2001 From: Dailer Date: Sun, 6 Mar 2022 13:49:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A0JIRA=20absolute=E6=94=AF=E6=8C=81inset?= =?UTF-8?q?=20shorthand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/wrapper/layout/layout.absolute.js | 46 ++++++++++++++++------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/core/wrapper/layout/layout.absolute.js b/src/core/wrapper/layout/layout.absolute.js index fa61028c1..face5ff63 100644 --- a/src/core/wrapper/layout/layout.absolute.js +++ b/src/core/wrapper/layout/layout.absolute.js @@ -24,21 +24,43 @@ BI.AbsoluteLayout = BI.inherit(BI.Layout, { var o = this.options; var w = BI.AbsoluteLayout.superclass._addElement.apply(this, arguments); var left = 0, right = 0, top = 0, bottom = 0; - if (BI.isNotNull(item.left)) { - w.element.css({left: BI.isNumber(item.left) ? this._optimiseGap(item.left) : item.left}); - left += item.left; + var offsets = BI.pick(item, ["top", "right", "bottom", "left"]); + + if (BI.isKey(item.inset)) { + var insets = BI.map((item.inset + "").split(" "), function (i, str) { + return BI.parseFloat(str); + }); + switch (insets.length) { + case 1: + offsets = {top: insets[0], bottom: insets[0], left: insets[0], right: insets[0]} + break; + case 2: + offsets = {top: insets[0], bottom: insets[0], left: insets[1], right: insets[1]} + break; + case 3: + offsets = {top: insets[0], left: insets[1], right: insets[1], bottom: insets[2]} + break + case 4: + default: + offsets = {top: insets[0], right: insets[0], bottom: insets[0], left: insets[0]} + break; + } + } + if (BI.isNotNull(offsets.left)) { + w.element.css({left: BI.isNumber(offsets.left) ? this._optimiseGap(offsets.left) : offsets.left}); + left += offsets.left; } - if (BI.isNotNull(item.right)) { - w.element.css({right: BI.isNumber(item.right) ? this._optimiseGap(item.right) : item.right}); - right += item.right; + if (BI.isNotNull(offsets.right)) { + w.element.css({right: BI.isNumber(offsets.right) ? this._optimiseGap(offsets.right) : offsets.right}); + right += offsets.right; } - if (BI.isNotNull(item.top)) { - w.element.css({top: BI.isNumber(item.top) ? this._optimiseGap(item.top) : item.top}); - top += item.top; + if (BI.isNotNull(offsets.top)) { + w.element.css({top: BI.isNumber(offsets.top) ? this._optimiseGap(offsets.top) : offsets.top}); + top += offsets.top; } - if (BI.isNotNull(item.bottom)) { - w.element.css({bottom: BI.isNumber(item.bottom) ? this._optimiseGap(item.bottom) : item.bottom}); - bottom += item.bottom; + if (BI.isNotNull(offsets.bottom)) { + w.element.css({bottom: BI.isNumber(offsets.bottom) ? this._optimiseGap(offsets.bottom) : offsets.bottom}); + bottom += offsets.bottom; } if (BI.isNotNull(o.hgap)) {