在PartView中正确调整GridLayout的大小

时间:2021-09-26 10:51:28

I have an Image in a grid that scales when the PartView is resized. If the BarsView starts smaller than 64 high (the size of the canvas), the bottom portion of the image gets cut off below the initial size. If it starts larger than what it is resized to, the minivitals does not shrink as it should. How can I the layout, when resized, to look like it does when I open the program at that size?

我在网格中有一个图像,可以在调整PartView大小时进行缩放。如果BarsView的开始小于64(画布的大小),则图像的底部会被切断到初始大小以下。如果它开始大于它调整大小的程度,那么小型实体就不会收缩。当我调整大小时,如何调整大小时的布局?

Screenshot of when the program is opened at normal size:

程序以正常大小打开时的屏幕截图:

在PartView中正确调整GridLayout的大小

Shrunk after opening at normal size (notice the concentration bar is pushed off the bottom of the screen):

以正常尺寸打开后收缩(注意浓度条被推离屏幕底部):

在PartView中正确调整GridLayout的大小

Opened at smaller size:

以较小的尺寸打开:

在PartView中正确调整GridLayout的大小

Opened at smaller size then expanded:

以较小的尺寸打开然后扩展:

在PartView中正确调整GridLayout的大小

Restarting between resizing has the desired effect, except for the needing to restart part.

除了需要重新启动部件之外,重新调整大小之间的重新启动具有所需的效果。

public class BarsView extends ViewPart {
    private PageBook book;
    public void createPartControl(Composite parent) {   
        book = new PageBook(parent, SWT.NONE);
        book.setLayout(new FillLayout());
        Composite page = new BarsPageView(book, view);
        book.showPage(page);
    }
    private class BarsPageView extends Composite {
        public BarsPageView(Composite parent, GameView view) {
        super(parent, SWT.NONE);
        this.setLayout(new GridLayout(3, false));

        // This is a wrapper around a StyledText
        entry = new StormFrontEntry(this, view);
        GridData entryData = new GridData(SWT.FILL, SWT.BEGINNING, true, false);
        entryData.heightHint = 22;
        entry.getWidget().setLayoutData(entryData); // getWidget() returns the StyledText

        // This is a Composite containing a Canvas
        status = new StormFrontStatus(this, view);
        status.setLayoutData(new GridData(SWT.CENTER, SWT.BEGINNING, false, false));

        // This is defined below                
        GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
        compassData.heightHint = 64;
        compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
        compass.setLayoutData(compassData);

        minivitals = new StormFrontDialogControl(this, SWT.NONE);
        GridData mvData = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
        minivitals.setLayoutData(mvData);
    }
}

public class WarlockCompass extends Canvas {
    public WarlockCompass (final Composite parent, int style, CompassTheme theme, GridData layoutData) {
        super(parent, style);
        addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent e) {
                drawCompass(e.gc);
            }
        });
        parent.addListener(SWT.Resize, new Listener() {
            @Override
            public void handleEvent(Event event) {
                // I cut out the calculations for this
                layoutData.heightHint = height;
                WarlockCompass.this.setSize(width, height);
            }
        });
    }
    private void drawCompass (GC gc) {
        // Cut out the calculations to scale the image to fix the canvas
        gc.drawImage(scaledImage, 0, 0);
    }
}

1 个解决方案

#1


0  

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

Should have been:

本来应该:

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

Changing that flag makes it resize properly.

更改该标志会使其正确调整大小。

#1


0  

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

Should have been:

本来应该:

    // This is defined below                
    GridData compassData = new GridData(SWT.CENTER, SWT.CENTER, false, true, 1, 2);
    compassData.heightHint = 64;
    compass = new WarlockCompass(this, SWT.NONE, theme, compassData);
    compass.setLayoutData(compassData);

Changing that flag makes it resize properly.

更改该标志会使其正确调整大小。