
const {ccclass, property} = cc._decorator;
const LeftPadding = 50;
const RightPadding = 50;
/**
 * 刘海屏适配
 * @author 薛鸿潇
 */
@ccclass
export default class BangsFit extends cc.Component {

    onLoad() {
        this._AdaptLeftAndRight();
    }

    /*============================================================================================================*/
    /**
     */
    /*============================================================================================================*/
    _AdaptLeftAndRight() {
        let widget = this.node.getComponent(cc.Widget);
        if (!widget) return;

        let is_big = this.IsBigScreenRatio();
        if (is_big) {
            widget.top = LeftPadding;
            widget.bottom = RightPadding;
        }
    }

    /**
     * @returns 是宽屏
     */
    IsBigScreenRatio() {
        return this.GetWinHeightWidthRatio() >= 1.86;
    }

    /**
     * @returns 屏幕比率
     */
    GetWinHeightWidthRatio() {
        let ratio = cc.winSize.height >= cc.winSize.width ? (cc.winSize.height / cc.winSize.width) : (cc.winSize.width / cc.winSize.height);

        return ratio;
    }
}
