Improve aspect management with scale_height mode
-import {Size, Sizeable, SizeHint, BoxSizing} from "./types"
+import {Size, Sizeable, SizeHint, BoxSizing, SizingPolicy} from "./types"
import {BBox, CoordinateTransform} from "../util/bbox"
const {min, max, round} = Math
@@ -111,7 +111,13 @@ export abstract class Layoutable {
if (aspect != null) {
const {width_policy, height_policy} = this.sizing
+ const gt = (width: SizingPolicy, height: SizingPolicy) => {
+ const policies = {max: 4, fit: 3, min: 2, fixed: 1}
+ return policies[width] > policies[height]
+ }
+
if (width_policy != "fixed" && height_policy != "fixed") {
+ if (width_policy == height_policy) {
const w_width = width
const w_height = round(width / aspect)
@@ -128,12 +134,16 @@ export abstract class Layoutable {
width = h_width
height = h_height
}
+ } else if (gt(width_policy, height_policy)) {
+ height = round(width/aspect)
+ } else {
+ width = round(height*aspect)
+ }
} else if (width_policy == "fixed") {
height = round(width/aspect)
} else if (height_policy == "fixed") {
width = round(height*aspect)
- } else
- throw new Error("unrechable")
+ }
}
return {width, height}
