From ed7ac5e3a87f563f50c93c572fa27bec328d0c64 Mon Sep 17 00:00:00 2001 From: Iain Cooke Date: Wed, 12 Dec 2018 22:40:12 +0100 Subject: [PATCH 1/2] Fixed HorizontalLayout to adjust height of submorphs to match container if Resize Submorphs and not Resize Container set --- layout.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/layout.js b/layout.js index 41a687ee..29e5fba8 100644 --- a/layout.js +++ b/layout.js @@ -445,6 +445,8 @@ export class HorizontalLayout extends FloatLayout { // supported directions: "leftToRight", "rightToLeft", "centered" this._direction = props.direction || "leftToRight"; // top, center, bottom + this._resizeSubmorphs = typeof props.resizeSubmorphs !== "undefined" ? + props.resizeSubmorphs : false; this._align = props.align || "top"; } @@ -466,20 +468,40 @@ export class HorizontalLayout extends FloatLayout { get spacing() { return this._spacing; } set spacing(offset) { this._spacing = offset; this.apply(); } + + get resizeSubmorphs() { return this._resizeSubmorphs } + set resizeSubmorphs(bool) { this._resizeSubmorphs = bool; this.apply(); } async apply(animate = false) { if (this.active || !this.container || !this.container.submorphs.length) return; - var { direction, align, spacing, container, autoResize, layoutableSubmorphs } = this; + var { direction, align, spacing, container, autoResize, layoutableSubmorphs, padding, resizeSubmorphs } = this; if (!layoutableSubmorphs.length) return; super.apply(animate); + let + padLeft = padding ? padding.left() : 0, + padRight = padding ? padding.right() : 0, + padTop = padding ? padding.top() : 0, + padBottom = padding ? padding.bottom() : 0, + containerHeight = container.height, + submorphHeight = containerHeight - spacing*2 - padTop - padBottom; + this.active = true; this.maxHeight = 0; var minExtent = this.computeMinContainerExtent(spacing, container, layoutableSubmorphs); - if (!autoResize) minExtent = minExtent.maxPt(container.extent); + if (!autoResize) { + minExtent = minExtent.maxPt(container.extent); + if (resizeSubmorphs) { + for (let m of layoutableSubmorphs) { + if (m.height !== submorphHeight) + m.height = submorphHeight; + } + this.forceLayoutsInNextLevel(); + } + } var startX = 0, rightToLeft = false; if (direction === "rightToLeft") { From ca6f80eb4c005bffec6136561c10fd2d43c13064 Mon Sep 17 00:00:00 2001 From: Iain Cooke Date: Thu, 13 Dec 2018 07:27:37 +0100 Subject: [PATCH 2/2] Semi-fix of behaviour of HorizontalLayout when ResizeContainer true and align=RightToLeft; Submorphs now stay within container bounds, right aligned, but the container can be wider than the sum of submorphs; height fits. This is arguably the wrong way around (height should be unconstrained, width should fit). But if you want fit, use LeftToRight, and the end result is horizontal fit anyhow - and in no case is height unconstrained (cf VerticalLayout, which never constrains width) --- layout.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/layout.js b/layout.js index 29e5fba8..e88889a4 100644 --- a/layout.js +++ b/layout.js @@ -520,7 +520,9 @@ export class HorizontalLayout extends FloatLayout { if (direction === "centered") { var leftOffset = layoutableSubmorphs[0].left; w = arr.last(layoutableSubmorphs).right + leftOffset - } else { + } else if (rightToLeft) { + w = arr.first(layoutableSubmorphs).right + spacing + } else { w = arr.last(layoutableSubmorphs).right + spacing; }