2018-10-17 11:38:25 +02:00
|
|
|
/*
|
2019-01-16 10:29:15 +00:00
|
|
|
Copyright 2019 New Vector Ltd
|
2018-10-17 11:38:25 +02:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-01-14 20:33:33 +01:00
|
|
|
import ResizeItem from "../item";
|
|
|
|
|
import Sizer from "../sizer";
|
2020-10-20 11:03:03 +01:00
|
|
|
import Resizer, {IConfig} from "../resizer";
|
2019-01-14 20:24:54 +01:00
|
|
|
|
2018-10-17 13:42:30 +02:00
|
|
|
/**
|
|
|
|
|
distributors translate a moving cursor into
|
|
|
|
|
CSS/DOM changes by calling the sizer
|
|
|
|
|
|
2018-11-26 16:42:58 +01:00
|
|
|
they have two methods:
|
|
|
|
|
`resize` receives then new item size
|
|
|
|
|
`resizeFromContainerOffset` receives resize handle location
|
|
|
|
|
within the container bounding box. For internal use.
|
|
|
|
|
This method usually ends up calling `resize` once the start offset is subtracted.
|
2018-10-17 13:42:30 +02:00
|
|
|
*/
|
2020-10-20 11:03:03 +01:00
|
|
|
export default class FixedDistributor<C extends IConfig, I extends ResizeItem<any> = ResizeItem<C>> {
|
|
|
|
|
static createItem(resizeHandle: HTMLDivElement, resizer: Resizer, sizer: Sizer): ResizeItem {
|
2019-01-14 20:24:54 +01:00
|
|
|
return new ResizeItem(resizeHandle, resizer, sizer);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
static createSizer(containerElement: HTMLElement, vertical: boolean, reverse: boolean): Sizer {
|
2019-01-14 20:24:54 +01:00
|
|
|
return new Sizer(containerElement, vertical, reverse);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
private readonly beforeOffset: number;
|
|
|
|
|
|
|
|
|
|
constructor(public readonly item: I) {
|
2018-12-19 23:51:19 +01:00
|
|
|
this.beforeOffset = item.offset();
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
public resize(size: number) {
|
2018-12-19 23:51:19 +01:00
|
|
|
this.item.setSize(size);
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|
|
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
public resizeFromContainerOffset(offset: number) {
|
2018-11-26 16:42:58 +01:00
|
|
|
this.resize(offset - this.beforeOffset);
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|
2019-01-11 17:17:58 +01:00
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
public start() {}
|
2019-01-11 17:17:58 +01:00
|
|
|
|
2020-10-20 11:03:03 +01:00
|
|
|
public finish() {}
|
2018-09-24 16:07:42 +01:00
|
|
|
}
|