@@ -4,6 +4,50 @@ import { booleanConverter } from '@nativescript/core/ui/core/view-base';
44import { Canvas , CanvasView , Cap , Join , Paint , Style } from '../canvas' ;
55import { parseCap , parseDashEffect , parseJoin , parseShadow , parseType } from '../utils' ;
66
7+ function parseThickness ( value : string ) {
8+ if ( typeof value === 'string' ) {
9+ const arr = value . split ( / [ , ] + / ) ;
10+
11+ let top : string ;
12+ let right : string ;
13+ let bottom : string ;
14+ let left : string ;
15+
16+ if ( arr . length === 1 ) {
17+ top = arr [ 0 ] ;
18+ right = arr [ 0 ] ;
19+ bottom = arr [ 0 ] ;
20+ left = arr [ 0 ] ;
21+ } else if ( arr . length === 2 ) {
22+ top = arr [ 0 ] ;
23+ bottom = arr [ 0 ] ;
24+ right = arr [ 1 ] ;
25+ left = arr [ 1 ] ;
26+ } else if ( arr . length === 3 ) {
27+ top = arr [ 0 ] ;
28+ right = arr [ 1 ] ;
29+ left = arr [ 1 ] ;
30+ bottom = arr [ 2 ] ;
31+ } else if ( arr . length === 4 ) {
32+ top = arr [ 0 ] ;
33+ right = arr [ 1 ] ;
34+ bottom = arr [ 2 ] ;
35+ left = arr [ 3 ] ;
36+ } else {
37+ throw new Error ( 'Expected 1, 2, 3 or 4 parameters. Actual: ' + value ) ;
38+ }
39+
40+ return {
41+ top,
42+ right,
43+ bottom,
44+ left,
45+ } ;
46+ } else {
47+ return value ;
48+ }
49+ }
50+
751function createGetter ( key , options : ShapePropertyOptions ) {
852 const realKey = '_' + key . toString ( ) ;
953 return function ( ) {
@@ -177,11 +221,18 @@ export default abstract class Shape extends Observable {
177221
178222 @percentLengthProperty ( { nonPaintProp : true } ) width : PercentLength ;
179223 @percentLengthProperty ( { nonPaintProp : true } ) height : PercentLength ;
224+
225+
180226 @percentLengthProperty ( { nonPaintProp : true } ) paddingLeft : PercentLength ;
181227 @percentLengthProperty ( { nonPaintProp : true } ) paddingRight : PercentLength ;
182228 @percentLengthProperty ( { nonPaintProp : true } ) paddingBottom : PercentLength ;
183229 @percentLengthProperty ( { nonPaintProp : true } ) paddingTop : PercentLength ;
184230
231+ @percentLengthProperty ( { nonPaintProp : true } ) marginLeft : PercentLength ;
232+ @percentLengthProperty ( { nonPaintProp : true } ) marginRight : PercentLength ;
233+ @percentLengthProperty ( { nonPaintProp : true } ) marginTop : PercentLength ;
234+ @percentLengthProperty ( { nonPaintProp : true } ) marginBottom : PercentLength ;
235+
185236 protected handleAlignment = false ;
186237
187238 abstract drawOnCanvas ( canvas : Canvas , parent : CanvasView ) : void ;
@@ -201,10 +252,10 @@ export default abstract class Shape extends Observable {
201252 if ( ! this . handleAlignment ) {
202253 const availableWidth = Utils . layout . toDevicePixels ( canvas . getWidth ( ) ) ;
203254 const availableHeight = Utils . layout . toDevicePixels ( canvas . getHeight ( ) ) ;
204- const paddingLeft = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingLeft ) + Utils . layout . toDeviceIndependentPixels ( PercentLength . toDevicePixels ( this . paddingLeft , 0 , availableWidth ) ) + Utils . layout . toDeviceIndependentPixels ( parent . effectiveBorderLeftWidth ) ;
205- const paddingRight = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingRight ) + Utils . layout . toDeviceIndependentPixels ( PercentLength . toDevicePixels ( this . paddingRight , 0 , availableWidth ) ) + Utils . layout . toDeviceIndependentPixels ( parent . effectiveBorderRightWidth ) ;
206- const paddingTop = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingTop ) + Utils . layout . toDeviceIndependentPixels ( PercentLength . toDevicePixels ( this . paddingTop , 0 , availableHeight ) ) + Utils . layout . toDeviceIndependentPixels ( parent . effectiveBorderTopWidth ) ;
207- const paddingBottom = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingBottom ) + Utils . layout . toDeviceIndependentPixels ( PercentLength . toDevicePixels ( this . paddingBottom , 0 , availableHeight ) ) + Utils . layout . toDeviceIndependentPixels ( parent . effectiveBorderBottomWidth ) ;
255+ const paddingLeft = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingLeft + PercentLength . toDevicePixels ( this . paddingLeft , 0 , availableWidth ) + parent . effectiveBorderLeftWidth ) ;
256+ const paddingRight = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingRight + PercentLength . toDevicePixels ( this . paddingRight , 0 , availableWidth ) + parent . effectiveBorderRightWidth ) ;
257+ const paddingTop = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingTop + PercentLength . toDevicePixels ( this . paddingTop , 0 , availableHeight ) + parent . effectiveBorderTopWidth ) ;
258+ const paddingBottom = Utils . layout . toDeviceIndependentPixels ( parent . effectivePaddingBottom + PercentLength . toDevicePixels ( this . paddingBottom , 0 , availableHeight ) + parent . effectiveBorderBottomWidth ) ;
208259 canvas . save ( ) ;
209260 if ( paddingLeft > 0 ) {
210261 canvas . translate ( paddingLeft , 0 ) ;
0 commit comments