我有一MyComposite堂课,我想为“尺寸变化”设置动画。
为此,我正在循环更改大小。
每次打loop之后,我都会打电话给layout()。
不幸的是,Composite每次迭代后都不会重新绘制,而是直接跳到我Composite的最终大小。
如何在每次更改尺寸时强制窗口小部件重新绘制?
MyComposite和动画:
//start
new Animation().start(myComposite);
...
public MyComposite(Composite parent, int style, int bgcolor) {
super(parent, style);
this.setBackground(getDisplay().getSystemColor(bgcolor));
}
@Override
public Point computeSize(int wHint, int hHint, boolean changed) {
return super.computeSize(width, height, changed);
}
class Animation{
public void start(MyComposite composite){
for(int i=0; i<1000; i++){
composite.width++;
composite.getParent().layout(true, true);
}
}
}
MyComposite:
重绘工作如下:
所以问题是,我没有立即触发重新绘制请求。正确的动画功能如下所示:
//layout of the composite doesn't work
//composite.layout(true, true);
//layout of parent works
composite.getParent().layout(true, true);
//marks the composite's screen are as invalidates, which will force a
composite.redraw(); redraw on next paint request
//tells the application to do all outstanding paint requests immediately
composite.update();