2019-03-12 15:36:12 +00:00
|
|
|
/*
|
2021-06-22 16:22:38 +00:00
|
|
|
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
|
2019-03-12 15:36:12 +00: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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-06-22 19:09:42 +00:00
|
|
|
* Fires when the middle panel has been resized (throttled).
|
2019-03-12 15:36:12 +00:00
|
|
|
* @event module:utils~ResizeNotifier#"middlePanelResized"
|
|
|
|
*/
|
2020-06-22 19:09:42 +00:00
|
|
|
/**
|
|
|
|
* Fires when the middle panel has been resized by a pixel.
|
|
|
|
* @event module:utils~ResizeNotifier#"middlePanelResizedNoisy"
|
|
|
|
*/
|
2021-06-22 16:22:38 +00:00
|
|
|
|
2019-03-12 15:36:12 +00:00
|
|
|
import { EventEmitter } from "events";
|
|
|
|
import { throttle } from "lodash";
|
|
|
|
|
|
|
|
export default class ResizeNotifier extends EventEmitter {
|
2021-06-22 16:22:38 +00:00
|
|
|
private _isResizing = false;
|
|
|
|
|
|
|
|
// with default options, will call fn once at first call, and then every x ms
|
|
|
|
// if there was another call in that timespan
|
|
|
|
private throttledMiddlePanel = throttle(() => this.emit("middlePanelResized"), 200);
|
2020-09-02 11:00:35 +00:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public get isResizing(): boolean {
|
2020-09-02 11:00:35 +00:00
|
|
|
return this._isResizing;
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public startResizing(): void {
|
2020-09-02 11:00:35 +00:00
|
|
|
this._isResizing = true;
|
2020-10-19 12:08:11 +00:00
|
|
|
this.emit("isResizing", true);
|
2020-09-02 11:00:35 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public stopResizing(): void {
|
2020-09-02 11:00:35 +00:00
|
|
|
this._isResizing = false;
|
2020-10-19 12:08:11 +00:00
|
|
|
this.emit("isResizing", false);
|
2019-03-12 15:36:12 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private noisyMiddlePanel(): void {
|
2020-06-22 19:09:42 +00:00
|
|
|
this.emit("middlePanelResizedNoisy");
|
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
private updateMiddlePanel(): void {
|
2021-06-22 16:22:38 +00:00
|
|
|
this.throttledMiddlePanel();
|
|
|
|
this.noisyMiddlePanel();
|
2020-06-22 19:09:42 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 15:36:12 +00:00
|
|
|
// can be called in quick succession
|
2023-01-12 13:25:14 +00:00
|
|
|
public notifyLeftHandleResized(): void {
|
2019-03-12 17:00:05 +00:00
|
|
|
// don't emit event for own region
|
2021-06-22 16:22:38 +00:00
|
|
|
this.updateMiddlePanel();
|
2019-03-12 15:36:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// can be called in quick succession
|
2023-01-12 13:25:14 +00:00
|
|
|
public notifyRightHandleResized(): void {
|
2021-06-22 16:22:38 +00:00
|
|
|
this.updateMiddlePanel();
|
2019-03-12 15:36:12 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
public notifyTimelineHeightChanged(): void {
|
2021-06-22 16:22:38 +00:00
|
|
|
this.updateMiddlePanel();
|
2020-07-31 12:02:40 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 15:36:12 +00:00
|
|
|
// can be called in quick succession
|
2023-01-12 13:25:14 +00:00
|
|
|
public notifyWindowResized(): void {
|
2021-06-22 16:22:38 +00:00
|
|
|
this.updateMiddlePanel();
|
2019-03-12 15:36:12 +00:00
|
|
|
}
|
|
|
|
}
|