Correct way do preserve shell aspect ratio in SWT

a 夏天 提交于 2019-12-25 07:24:34

问题


I've been trying to find a way to force a shell to resize preserving a certain aspect ratio. This is the only way I've come up with:

shell.addControlListener(new ControlListener() {

    @Override
    public void controlMoved(ControlEvent e) {}

    @Override
    public void controlResized(ControlEvent e) {
        final Rectangle window = mShell.getClientArea();

        if (aspectRatio <= 1) {
            window.width = (int) (window.height * aspectRatio);
        } else {
            window.height = (int) (window.width / aspectRatio);
        }
        shell.setSize(window.width, window.height);
    }
});

The problem with this approach is that shell.setSize() also sets off a resize event (and it also screws up the title bar in OS X Lion)...

Any ideas? This problem has really been killing me for ages and I couldn't find a solution anywhere.

来源:https://stackoverflow.com/questions/15437563/correct-way-do-preserve-shell-aspect-ratio-in-swt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!