-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstretchcell_functions.js
25 lines (21 loc) · 1.03 KB
/
stretchcell_functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function StretchCell(inner, width, height) {
this.inner = inner; // each variable that is to be used at a later time in the prototype of this object has to be assigned like this in the constructor.
this.width = width;
this.height = height;
}
StretchCell.prototype.minWidth = function () { // creat the minWidth prototype method which returns the bigger value of either the cell width, or the inner cell's width
return Math.max(this.width, this.inner.minWidth());
};
StretchCell.prototype.minHeight = function () { // Prototype minHeight method. same as minWidth but for height.
return Math.max(this.height, (this.inner.minHeight()));
};
StretchCell.prototype.draw = function(width, height) { //draw the cell - take the contents of the inner cell and concatenate empty spaces as many as the cell width.
return this.inner.draw(width, height);
}
var sc = new StretchCell(new TextCell("abc"), 1, 2);
console.log(sc.minWidth());
// → 3
console.log(sc.minHeight());
// → 2
console.log(sc.draw(3, 2));
// → ["abc", " "]