don't over-constraint layout while resizing

adapting the approach taken in the prototype
pull/21833/head
Bruno Windels 2019-01-28 17:52:46 +01:00
parent b0bb4eb5ab
commit 88f25dec4d
1 changed files with 28 additions and 1 deletions

View File

@ -41,6 +41,14 @@ export class Layout {
this._sectionHeights = Object.assign({}, initialSizes);
// in-progress heights, while dragging. Committed on mouse-up.
this._heights = [];
// use while manually resizing to cancel
// the resize for a given mouse position
// when the previous resize made the layout
// constrained
this._clampedOffset = 0;
// used while manually resizing, to clear
// _clampedOffset when the direction of resizing changes
this._lastOffset = 0;
}
setAvailableHeight(newSize) {
@ -268,6 +276,22 @@ export class Layout {
this._sectionHeights[section.id] = this._heights[i];
});
}
_setUncommittedSectionHeight(sectionIndex, offset) {
if (Math.sign(offset) != Math.sign(this._lastOffset)) {
this._clampedOffset = undefined;
}
if (this._clampedOffset !== undefined) {
if (offset < 0 && offset < this._clampedOffset) {
return;
}
if (offset > 0 && offset > this._clampedOffset) {
return;
}
}
this._clampedOffset = this._relayout(sectionIndex, offset);
this._lastOffset = offset;
}
}
class Handle {
@ -278,7 +302,10 @@ class Handle {
}
setHeight(height) {
this._layout._relayout(this._sectionIndex, height - this._initialHeight);
this._layout._setUncommittedSectionHeight(
this._sectionIndex,
height - this._initialHeight,
);
return this;
}