This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Doric/doric-js/lib/src/util/layoutconfig.js

105 lines
2.3 KiB
JavaScript
Raw Normal View History

2020-01-03 14:44:51 +08:00
export var LayoutSpec;
(function (LayoutSpec) {
/**
* Depends on what's been set on width or height.
*/
LayoutSpec[LayoutSpec["JUST"] = 0] = "JUST";
/**
* Depends on it's content.
*/
LayoutSpec[LayoutSpec["FIT"] = 1] = "FIT";
/**
* Extend as much as parent let it take.
*/
LayoutSpec[LayoutSpec["MOST"] = 2] = "MOST";
})(LayoutSpec || (LayoutSpec = {}));
export class LayoutConfigImpl {
fit() {
this.widthSpec = LayoutSpec.FIT;
this.heightSpec = LayoutSpec.FIT;
return this;
}
2021-05-14 19:32:19 +08:00
fitWidth() {
this.widthSpec = LayoutSpec.FIT;
return this;
}
fitHeight() {
this.heightSpec = LayoutSpec.FIT;
return this;
}
2020-01-03 14:44:51 +08:00
most() {
this.widthSpec = LayoutSpec.MOST;
this.heightSpec = LayoutSpec.MOST;
return this;
}
2021-05-14 19:32:19 +08:00
mostWidth() {
this.widthSpec = LayoutSpec.MOST;
return this;
}
mostHeight() {
2021-06-22 10:52:09 +08:00
this.heightSpec = LayoutSpec.MOST;
2021-05-14 19:32:19 +08:00
return this;
}
2020-01-03 14:44:51 +08:00
just() {
this.widthSpec = LayoutSpec.JUST;
this.heightSpec = LayoutSpec.JUST;
return this;
}
2021-05-14 19:32:19 +08:00
justWidth() {
this.widthSpec = LayoutSpec.JUST;
return this;
}
justHeight() {
this.heightSpec = LayoutSpec.JUST;
return this;
}
2020-01-03 14:44:51 +08:00
configWidth(w) {
this.widthSpec = w;
return this;
}
configHeight(h) {
this.heightSpec = h;
return this;
}
configMargin(m) {
this.margin = m;
return this;
}
configAlignment(a) {
this.alignment = a;
return this;
}
configWeight(w) {
this.weight = w;
return this;
}
configMaxWidth(v) {
this.maxWidth = v;
return this;
}
configMaxHeight(v) {
this.maxHeight = v;
return this;
}
configMinWidth(v) {
this.minWidth = v;
return this;
}
configMinHeight(v) {
this.minHeight = v;
return this;
}
2020-01-03 14:44:51 +08:00
toModel() {
return {
widthSpec: this.widthSpec,
heightSpec: this.heightSpec,
margin: this.margin,
alignment: this.alignment ? this.alignment.toModel() : undefined,
weight: this.weight,
};
}
}
export function layoutConfig() {
return new LayoutConfigImpl;
}