You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

131 lines
2.8 KiB

/**
* This file is part of the jps-like-websites lib
* URL: https://git.labos.goip.de/chris/jpc-like-websites
* @copyright by its creator Christian Martin
*/
/**
* Simple Dimensions container for the height and width in pixels.
*/
class Dimensions extends DirectionUnitDependentAttribute {
constructor(defaultValue = 0, defaultUnit = SizeUnits.PIXEL) {
super();
this._unit = defaultUnit;
this._fFirst = defaultValue;
this._fSecond = defaultValue;
}
/**
* Sets width (x) value of amount
* @param {number} amount
* @returns {Dimensions} this Dimensions Modifier
*/
width(amount) {
this._fFirst = amount;
return this;
}
/**
* Sets height (y) value of amount
* @param {number} amount
* @returns {Dimensions} this Dimensions Modifier
*/
height(amount) {
this._fSecond = amount;
return this;
}
/**
*
* @param {number} size
* @returns {Dimensions}
*/
all(size) {
return this.width(size).height(size);
}
getOrderedValues() {
return this.getOrderedValues().slice(2)
}
/**
*
* @returns {Object}
*/
toModifications() {
let w = { key: "width", value: this._fFirst + this._unit }
let h = { key: "height", value: this._fSecond + this._unit }
let is_w = this._fFirst > 0;
let is_h = this._fSecond > 0;
if (is_h && is_w) {
return [w, h]
} else if (is_w) {
return [w]
} else if (is_h) {
return [h]
} else {
return []
}
}
/**
*
* @returns {TwoDimPoint}
*/
toTwoDimPoint() {
return new TwoDimPoint(
this._fFirst,
this._fSecond
);
}
}
class DimensionsChain extends Dimensions {
_modifier;
constructor(modifier) {
super();
this._modifier = modifier;
}
/**
*
* @returns {Modifier|ChainableModifier}
*/
toModifier() {
return this._modifier
.dimensions(this);
}
/**
*
* @returns {Modifier|ChainableModifier}
*/
ensureModifier() {
return this.toModifier()
}
/**
*
* @returns {Component} the Component that was (supposed to be) modified by this obj.
*/
toComponent() {
return this._modifier
.dimensions(this)
.toComponent();
}
/**
*
* @param {Component|Array<Component>} innerComponent children of the Component under modification.
* @returns {Component}
*/
childContext(innerComponent) {
return this._modifier
.dimensions(this)
.toComponent()
.childContext(innerComponent);
}
}