Search in sources :

Example 1 with NativeScreen

use of org.rstudio.core.client.dom.NativeScreen in project rstudio by rstudio.

the class ScreenUtils method getAdjustedWindowSize.

public static Size getAdjustedWindowSize(Size preferredSize) {
    // compute available height (trim to max)
    NativeScreen screen = NativeScreen.get();
    int height = Math.min(screen.getAvailHeight(), preferredSize.height);
    // trim height for large monitors
    if (screen.getAvailHeight() >= (preferredSize.height - 100)) {
        if (BrowseCap.isMacintosh())
            height = height - 107;
        else if (BrowseCap.isWindows())
            height = height - 89;
        else
            height = height - 80;
    } else {
        // adjust for window framing, etc.
        if (Desktop.isDesktop())
            height = height - 40;
        else
            height = height - 60;
        // extra adjustment for firefox on windows (extra chrome in url bar)
        if (BrowseCap.isWindows() && BrowseCap.isFirefox())
            height = height - 25;
    }
    // available height, excluding the menubar/taskbar)
    if (BrowseCap.isLinux() && BrowseCap.isChrome())
        height = height - 50;
    // compute width (trim to max)
    int width = Math.min(preferredSize.width, screen.getAvailWidth() - 20);
    // return size
    return new Size(width, height);
}
Also used : Size(org.rstudio.core.client.Size) NativeScreen(org.rstudio.core.client.dom.NativeScreen)

Example 2 with NativeScreen

use of org.rstudio.core.client.dom.NativeScreen in project rstudio by rstudio.

the class ZoomUtils method getZoomWindowSize.

public static Size getZoomWindowSize(Size sourceFrameSize, Size defaultSize) {
    int width, height;
    if (defaultSize != null) {
        // trim based on available screen size
        NativeScreen screen = NativeScreen.get();
        width = Math.min(screen.getAvailWidth(), defaultSize.width);
        height = Math.min(screen.getAvailHeight(), defaultSize.height);
    } else {
        final int PADDING = 20;
        // calculate ideal heigh and width. try to be as large as possible
        // within the bounds of the current client size
        Size bounds = new Size(Window.getClientWidth() - PADDING, Window.getClientHeight() - PADDING);
        float widthRatio = bounds.width / ((float) sourceFrameSize.width);
        float heightRatio = bounds.height / ((float) sourceFrameSize.height);
        float ratio = Math.min(widthRatio, heightRatio);
        // constrain initial width to between 300 and 1,200 pixels
        width = Math.max(300, (int) (ratio * sourceFrameSize.width));
        width = Math.min(1200, width);
        // constrain initial height to between 300 and 900 pixels
        height = Math.max(300, (int) (ratio * sourceFrameSize.height));
        height = Math.min(900, height);
    }
    return new Size(width, height);
}
Also used : Size(org.rstudio.core.client.Size) NativeScreen(org.rstudio.core.client.dom.NativeScreen)

Aggregations

Size (org.rstudio.core.client.Size)2 NativeScreen (org.rstudio.core.client.dom.NativeScreen)2