ukijs/rect引数の与え方
各viewの生成に使われるrect引数は、Rect.create()関数を経て、最終的にはRect()関数に渡されるようです。
Rect.create関数の使い方は、次のようになるようです。
- 引数なしの場合:nullを返します。
- 1引数の場合:
- 引数がRectなら、それを返します。
- 引数が"200 300" あるいは "0 10 200 300"形式の文字列の場合、これをrectに変換します。
- 2引数の場合:
- 2つの数値を与えれば、x = y = 0とし、引数をwidth,heightとして設定します。
- PointとSizeを与えることもできます。
- 4引数の場合
- それらをx,y,width,heightとして設定します。
/** * Creates rect from different representations * - if no params given returns null * - if uki.geometry.Rect given returns it * - if "200 300" or "0 10 200 300" string converts it to rect * - if two or four params given creates rect from them * * @memberOf uki.geometry.Rect * @name creates * @function * * @param {...string|number|uki.geometry.Rect} var_args Rect representation * * @returns {uki.geometry.Rect} created size */ Rect.create = function(a1, a2, a3, a4) { if (a1 === undefined) return null; if (a1.x !== undefined) return a1; if (/\S+\s+\S+/.test(a1 + '')) return Rect.fromString(a1, a2); if (a3 === undefined) return new Rect(a1, a2); return new Rect(a1, a2, a3, a4); };
/** * Creates Rect from "x y width height" or "width height" string * * @memberOf uki.geometry.Rect * @name fromString * @function * * @param {string} string * @returns {uki.geometry.Rect} */ Rect.fromString = function(string) { var parts = string.split(/\s+/); if (parts.length > 2) return new Rect( parts[0], parts[1], parts[2], parts[3] ); return new Rect( parts[0], parts[1] ) ; };
/** * Rectangle with x, y, width and height properties * May be used as uki.geometry.Point or uki.geometry.Size * - if 4 arguments given creates size with x,y,width,height set to the given arguments * - if 2 number arguments given creates size with x = y = 0 and width and height set * set to the given arguments * - if a Point and a Size given creates rect with point as an origin and given size * * @param {...number|uki.geometry.Point|uki.geometry.Size} var_args * @name uki.geometry.Rect * @augments uki.geometry.Size * @augments uki.geometry.Point * @constructor */ var Rect = uki.geometry.Rect = function(a1, a2, a3, a4) { if (a3 !== undefined) { this.x = a1*1.0 || 0.0; this.y = a2*1.0 || 0.0; this.width = a3*1.0 || 0.0; this.height = a4*1.0 || 0.0; } else if (a1 === undefined || a1.x === undefined) { this.x = 0; this.y = 0; this.width = a1*1.0 || 0.0; this.height = a2*1.0 || 0.0; } else { this.x = a1 ? a1.x*1.0 : 0; this.y = a1 ? a1.y*1.0 : 0; this.width = a2 ? a2.width*1.0 : 0; this.height = a2 ? a2.height*1.0 : 0; } };