2019-03-12 18:36:12 +03:00
|
|
|
/*
|
|
|
|
Copyright 2019 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2020-06-22 22:09:42 +03:00
|
|
|
* Fires when the middle panel has been resized (throttled).
|
2019-03-12 18:36:12 +03:00
|
|
|
* @event module:utils~ResizeNotifier#"middlePanelResized"
|
|
|
|
*/
|
2020-06-22 22:09:42 +03:00
|
|
|
/**
|
|
|
|
* Fires when the middle panel has been resized by a pixel.
|
|
|
|
* @event module:utils~ResizeNotifier#"middlePanelResizedNoisy"
|
|
|
|
*/
|
2019-03-12 18:36:12 +03:00
|
|
|
import { EventEmitter } from "events";
|
|
|
|
import { throttle } from "lodash";
|
|
|
|
|
|
|
|
export default class ResizeNotifier extends EventEmitter {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
// with default options, will call fn once at first call, and then every x ms
|
|
|
|
// if there was another call in that timespan
|
|
|
|
this._throttledMiddlePanel = throttle(() => this.emit("middlePanelResized"), 200);
|
2020-09-02 14:00:35 +03:00
|
|
|
this._isResizing = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get isResizing() {
|
|
|
|
return this._isResizing;
|
|
|
|
}
|
|
|
|
|
|
|
|
startResizing() {
|
|
|
|
this._isResizing = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
stopResizing() {
|
|
|
|
this._isResizing = false;
|
2019-03-12 18:36:12 +03:00
|
|
|
}
|
|
|
|
|
2020-06-22 22:09:42 +03:00
|
|
|
_noisyMiddlePanel() {
|
|
|
|
this.emit("middlePanelResizedNoisy");
|
|
|
|
}
|
|
|
|
|
|
|
|
_updateMiddlePanel() {
|
|
|
|
this._throttledMiddlePanel();
|
|
|
|
this._noisyMiddlePanel();
|
|
|
|
}
|
|
|
|
|
2019-03-12 18:36:12 +03:00
|
|
|
// can be called in quick succession
|
|
|
|
notifyLeftHandleResized() {
|
2019-03-12 20:00:05 +03:00
|
|
|
// don't emit event for own region
|
2020-06-22 22:09:42 +03:00
|
|
|
this._updateMiddlePanel();
|
2019-03-12 18:36:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// can be called in quick succession
|
|
|
|
notifyRightHandleResized() {
|
2020-06-22 22:09:42 +03:00
|
|
|
this._updateMiddlePanel();
|
2019-03-12 18:36:12 +03:00
|
|
|
}
|
|
|
|
|
2020-07-31 15:02:40 +03:00
|
|
|
notifyTimelineHeightChanged() {
|
|
|
|
this._updateMiddlePanel();
|
|
|
|
}
|
|
|
|
|
2019-03-12 18:36:12 +03:00
|
|
|
// can be called in quick succession
|
|
|
|
notifyWindowResized() {
|
2019-03-12 20:00:05 +03:00
|
|
|
// no need to throttle this one,
|
|
|
|
// also it could make scrollbars appear for
|
|
|
|
// a split second when the room list manual layout is now
|
|
|
|
// taller than the available space
|
|
|
|
this.emit("leftPanelResized");
|
|
|
|
|
2020-06-22 22:09:42 +03:00
|
|
|
this._updateMiddlePanel();
|
2019-03-12 18:36:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|