RTL fixup must have for Smart Mobile Studio
If you own Smart Mobile Studio you may want to apply this fix. Please note that I have not tested this with more than 5 different apps, but it’s a very small alteration so it poses no real threat. Just revert the few lines it entails to the official release should anything negative occur.
And remember, this is not an “official site” for the product — but rather a personal, research & development blog.
Ayways – under HTML5, scaling a control causes a massive efficiency hit. The reason for this is not just that the whole DOM has to be re-calculated, but also that the internal resize function is triggered – which (depending in the complexity of your controls and code) can be processor hungry. When I write “hungry” I am talking about milliseconds — but a drop here and there is quickly a full glass.
This small patch forces the RTL to synchronize it’s resize operations using RequestAnimationFrame – which means the browser tries to collect and redraw as many updates to the screen in one go. This results in smoother display updates and in general – a more efficient UI.
Patching up w3components
Simply open up w3components.pas and locate the method TW3CustomControl.AfterUpdate(). Remark out the code there (just for safety in case you want to go back) and replace it with the following code. You should immediately notice that things become faster and more smooth:
procedure TW3CustomControl.AfterUpdate; begin (* was a resize issued? *) if GetWasSized then begin if ObjectReady and (Width&gt;0) and (Height&gt;0) then begin w3_RequestAnimationFrame(Procedure () Begin Resize; if Assigned(FOnResize) then FOnResize(Self); end); end; (* do we need a re-draw? *) if not GetWasMoved then SetWasMoved; end; (* Only issue a redraw once *) if GetWasMoved then Invalidate; (* FWasMoved := False; FWasSized := False; *) inherited; end;
Another vital tip for more speed, is to use BeginUpdate and EndUpdate whenever you alter your control size and/or content. This prevents resize to be called until all adjustments have executed (this is really an important point, so keep this in mind).