better naming for anchor
This commit is contained in:
parent
dab1f30ab4
commit
6e55ebdab7
1 changed files with 20 additions and 20 deletions
|
@ -183,10 +183,10 @@ export class Layout {
|
||||||
return overflow;
|
return overflow;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rebalanceAbove(anchor, overflowAbove) {
|
_rebalanceAbove(sectionIndex, overflowAbove) {
|
||||||
if (Math.abs(overflowAbove) > 1.0) {
|
if (Math.abs(overflowAbove) > 1.0) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
for (let i = anchor - 1; i >= 0; i--) {
|
for (let i = sectionIndex - 1; i >= 0; i--) {
|
||||||
sections.push(i);
|
sections.push(i);
|
||||||
}
|
}
|
||||||
overflowAbove = this._applyOverflow(overflowAbove, sections);
|
overflowAbove = this._applyOverflow(overflowAbove, sections);
|
||||||
|
@ -194,10 +194,10 @@ export class Layout {
|
||||||
return overflowAbove;
|
return overflowAbove;
|
||||||
}
|
}
|
||||||
|
|
||||||
_rebalanceBelow(anchor, overflowBelow) {
|
_rebalanceBelow(sectionIndex, overflowBelow) {
|
||||||
if (Math.abs(overflowBelow) > 1.0) {
|
if (Math.abs(overflowBelow) > 1.0) {
|
||||||
const sections = [];
|
const sections = [];
|
||||||
for (let i = anchor + 1; i < this._sections.length; i++) {
|
for (let i = sectionIndex + 1; i < this._sections.length; i++) {
|
||||||
sections.push(i);
|
sections.push(i);
|
||||||
}
|
}
|
||||||
overflowBelow = this._applyOverflow(overflowBelow, sections);
|
overflowBelow = this._applyOverflow(overflowBelow, sections);
|
||||||
|
@ -205,47 +205,47 @@ export class Layout {
|
||||||
return overflowBelow;
|
return overflowBelow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @param offset the amount the anchor is moved from what is stored in _sectionHeights, positive if downwards
|
// @param offset the amount the sectionIndex is moved from what is stored in _sectionHeights, positive if downwards
|
||||||
// if we're clamped, return the offset we should be clamped at.
|
// if we're clamped, return the offset we should be clamped at.
|
||||||
_relayout(anchor = 0, offset = 0, clamped = false) {
|
_relayout(sectionIndex = 0, offset = 0, clamped = false) {
|
||||||
this._heights = this._sections.map((section) => this._sectionHeights[section.id]);
|
this._heights = this._sections.map((section) => this._sectionHeights[section.id]);
|
||||||
// are these the amounts the items above/below shrank/grew and need to be relayouted?
|
// are these the amounts the items above/below shrank/grew and need to be relayouted?
|
||||||
let overflowAbove;
|
let overflowAbove;
|
||||||
let overflowBelow;
|
let overflowBelow;
|
||||||
const maxHeight = this._getMaxHeight(anchor);
|
const maxHeight = this._getMaxHeight(sectionIndex);
|
||||||
const minHeight = this._getMinHeight(anchor);
|
const minHeight = this._getMinHeight(sectionIndex);
|
||||||
// new height > max ?
|
// new height > max ?
|
||||||
if (this._heights[anchor] + offset > maxHeight) {
|
if (this._heights[sectionIndex] + offset > maxHeight) {
|
||||||
// we're pulling downwards and clamped
|
// we're pulling downwards and clamped
|
||||||
// overflowAbove = minus how much are we above max height
|
// overflowAbove = minus how much are we above max height
|
||||||
overflowAbove = (maxHeight - this._heights[anchor]) - offset;
|
overflowAbove = (maxHeight - this._heights[sectionIndex]) - offset;
|
||||||
overflowBelow = offset;
|
overflowBelow = offset;
|
||||||
} else if (this._heights[anchor] + offset < minHeight) { // new height < min?
|
} else if (this._heights[sectionIndex] + offset < minHeight) { // new height < min?
|
||||||
// we're pulling upwards and clamped
|
// we're pulling upwards and clamped
|
||||||
overflowAbove = (minHeight - this._heights[anchor]) - offset;
|
overflowAbove = (minHeight - this._heights[sectionIndex]) - offset;
|
||||||
overflowBelow = offset;
|
overflowBelow = offset;
|
||||||
} else {
|
} else {
|
||||||
overflowAbove = 0;
|
overflowAbove = 0;
|
||||||
overflowBelow = offset;
|
overflowBelow = offset;
|
||||||
}
|
}
|
||||||
this._heights[anchor] = clamp(this._heights[anchor] + offset, minHeight, maxHeight);
|
this._heights[sectionIndex] = clamp(this._heights[sectionIndex] + offset, minHeight, maxHeight);
|
||||||
|
|
||||||
// these are reassigned the amount of overflow that could not be rebalanced
|
// these are reassigned the amount of overflow that could not be rebalanced
|
||||||
// meaning we dragged the handle too far and it can't follow the cursor anymore
|
// meaning we dragged the handle too far and it can't follow the cursor anymore
|
||||||
overflowAbove = this._rebalanceAbove(anchor, overflowAbove);
|
overflowAbove = this._rebalanceAbove(sectionIndex, overflowAbove);
|
||||||
overflowBelow = this._rebalanceBelow(anchor, overflowBelow);
|
overflowBelow = this._rebalanceBelow(sectionIndex, overflowBelow);
|
||||||
|
|
||||||
if (!clamped) { // to avoid risk of infinite recursion
|
if (!clamped) { // to avoid risk of infinite recursion
|
||||||
// clamp to avoid overflowing or underflowing the page
|
// clamp to avoid overflowing or underflowing the page
|
||||||
if (Math.abs(overflowAbove) > 1.0) {
|
if (Math.abs(overflowAbove) > 1.0) {
|
||||||
// here we do the layout again with offset - the amount of space we took too much
|
// here we do the layout again with offset - the amount of space we took too much
|
||||||
this._relayout(anchor, offset + overflowAbove, true);
|
this._relayout(sectionIndex, offset + overflowAbove, true);
|
||||||
return offset + overflowAbove;
|
return offset + overflowAbove;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Math.abs(overflowBelow) > 1.0) {
|
if (Math.abs(overflowBelow) > 1.0) {
|
||||||
// here we do the layout again with offset - the amount of space we took too much
|
// here we do the layout again with offset - the amount of space we took too much
|
||||||
this._relayout(anchor, offset - overflowBelow, true);
|
this._relayout(sectionIndex, offset - overflowBelow, true);
|
||||||
return offset - overflowBelow;
|
return offset - overflowBelow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -270,14 +270,14 @@ export class Layout {
|
||||||
}
|
}
|
||||||
|
|
||||||
class Handle {
|
class Handle {
|
||||||
constructor(layout, anchor, height) {
|
constructor(layout, sectionIndex, height) {
|
||||||
this._layout = layout;
|
this._layout = layout;
|
||||||
this._anchor = anchor;
|
this._sectionIndex = sectionIndex;
|
||||||
this._initialHeight = height;
|
this._initialHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
setHeight(height) {
|
setHeight(height) {
|
||||||
this._layout._relayout(this._anchor, height - this._initialHeight);
|
this._layout._relayout(this._sectionIndex, height - this._initialHeight);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue