Created
February 18, 2016 13:47
-
-
Save axelchalon/bf534b2c92c4b709c50e to your computer and use it in GitHub Desktop.
Spacer – Grid helper to get cell coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Spacer = function() { | |
this.width = null; | |
this.height = null; | |
this.columns = 0; | |
this.rows = 0; | |
this.xSpacing = 0; | |
this.ySpacing = 0; | |
this.xMargin = 0; | |
this.yMargin = 0; | |
}; | |
Spacer.prototype.setWidth = function(arg) { this.width = arg; } | |
Spacer.prototype.setHeight = function(arg) { this.height = arg; } | |
Spacer.prototype.setColumns = function(arg) { this.columns = arg; } | |
Spacer.prototype.setRows = function(arg) { this.rows = arg; } | |
Spacer.prototype.setXSpacing = function(arg) { this.xSpacing = arg; } | |
Spacer.prototype.setYSpacing = function(arg) { this.ySpacing = arg; } | |
Spacer.prototype.setXMargin = function(arg) { this.xMargin = arg; } | |
Spacer.prototype.setYMargin = function(arg) { this.yMargin = arg; } | |
Spacer.prototype.getColumnWidth = function(column) { return (this.width - this.xMargin*2 - (this.columns-1)*this.xSpacing) / this.columns; } | |
Spacer.prototype.getRowHeight = function(row) { return (this.height - this.yMargin*2 - (this.rows-1)*this.ySpacing) / this.rows; } | |
Spacer.prototype.getColumnX = function(column) { return this.xMargin + column*(this.getColumnWidth()+this.xSpacing); } | |
Spacer.prototype.getRowY = function(row) { return this.yMargin + row*(this.getRowHeight()+this.ySpacing); } | |
Spacer.prototype.getReverseRowY = function(row) { var row = this.rows-row; return this.yMargin + row*(this.getRowHeight()+this.ySpacing); } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment