Files
ThreadNet-Web/src/resizer/room.js
T

128 lines
3.4 KiB
JavaScript
Raw Normal View History

2018-10-17 11:38:25 +02:00
/*
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import {Sizer} from "./sizer";
class RoomSizer extends Sizer {
setItemSize(item, size) {
2019-01-10 14:03:17 +01:00
item.style.flexBasis = `${Math.round(size)}px`;
item.classList.add("resized-sized");
}
}
2018-12-19 23:51:19 +01:00
/*
class RoomSubList extends ResizeItem {
collapsed() {
}
2019-01-09 15:53:04 +01:00
id() {
2018-12-19 23:51:19 +01:00
}
2019-01-09 15:53:04 +01:00
maxSize() {
}
minSize() {
2018-12-19 23:51:19 +01:00
}
}
*/
const MIN_SIZE = 74;
2018-12-19 23:51:19 +01:00
// would be good to have a way in here to know if the item can be resized
// - collapsed items can't be resized (.mx_RoomSubList_hidden)
// - items at MIN_SIZE can't be resized smaller
// - items at maxContentHeight can't be resized larger
// if you shrink the predecesor, and start dragging down again afterwards, which item has to grow?
/*
either items before (starting from first or last)
or
*/
2018-12-19 23:51:19 +01:00
class RoomDistributor {
constructor(item) {
this.item = item;
}
_handleSize() {
return 1;
}
_isCollapsed(item) {
return item.domNode.classList.contains("mx_RoomSubList_hidden");
}
_contentSize(item) {
const scrollItem = item.domNode.querySelector(".mx_RoomSubList_scroll");
2019-01-09 15:45:47 +01:00
const header = item.domNode.querySelector(".mx_RoomSubList_labelContainer");
const headerHeight = item.sizer.getItemSize(header);
return headerHeight + scrollItem.scrollHeight;
}
2018-12-19 23:51:19 +01:00
resize(size) {
if (size < 0) {
console.log("NEGATIVE SIZE RESIZE RESIZE RESIZE!!!", size);
}
let item = this.item;
// cache result of this loop?
2018-12-19 23:51:19 +01:00
// move to item that is at position of cursor
// this would happen if the cursor goes beyond the min-height
while (item) {
// TODO: collapsed
2019-01-08 18:17:34 +01:00
if (this._isCollapsed(item)) {
item = item.previous();
}
else if (size <= MIN_SIZE) {
item.setSize(MIN_SIZE);
const remainder = MIN_SIZE - size;
2018-12-19 23:51:19 +01:00
item = item.previous();
if (item) {
size = item.size() - remainder - this._handleSize();
}
}
else {
const contentSize = this._contentSize(item);
if (size > contentSize) {
item.setSize(contentSize);
const remainder = size - contentSize;
item = item.previous();
if (item) {
size = item.size() + remainder; // todo: handle size here?
}
}
else {
item.setSize(size);
item = null;
size = 0;
}
2018-12-19 23:51:19 +01:00
}
}
}
resizeFromContainerOffset(containerOffset) {
this.resize(containerOffset - this.item.offset());
}
}
module.exports = {
RoomSizer,
RoomDistributor,
};