Home > OP4JS, Smart Mobile Studio, Uncategorized > RTL fixup must have for Smart Mobile Studio

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.

RequestAnimationFrame

RequestAnimationFrame

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>0)
    and (Height>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).

Advertisements
  1. abouchez
    August 23, 2014 at 6:15 pm

    We also add some issues with Resize when changing the current form, if you have several nested layouts and components in your form.
    The root cause of those issues was that the OnResize event was triggered synchronously, at form changing, whereas all layouts and nested components were not properly activated.

    We add to write such a workaround:

    procedure TMainAbstractForm.Resize;
    begin
      inherited;
      if Application.CurrentForm=self then begin
        FMainLayout.Resize(self);
        FMainTopLayout.Resize(HeaderPanel);
      end;
    end;
    

    I suppose your fix may benefit to this problem, since OnResize becomes asynchronous.

    Thanks a lot for sharing ASAP!

    • abouchez
      August 23, 2014 at 6:25 pm

      I confirm: this patch also fix our OnResize issue!
      🙂

      Note that the unit is name SmartCL.Components.pas, and to be modified directly in c:\ProgramData\Optimale Systemer AS\Smart Mobile Studio\RTL\SmartCL\

      With the current official 2.1 release, the fixed code looks like this:

      procedure TW3CustomControl.AfterUpdate;
      begin
        (* was a resize issued? *)
        if GetWasSized then
        begin
          {$IFDEF USE_NEW_RESIZE}
          if  ObjectReady
          and (Width>0)
          and (Height>0) then
          begin
            w3_RequestAnimationFrame(Procedure ()
              Begin
                Resize;
                if Assigned(FOnResize) then
                FOnResize(Self);
              end);
          end;
          {$ELSE}
          if ObjectReady then
          ReSize;
          {$ENDIF}
      
          (* 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;
      
      • Jon Lennart Aasenden
        August 24, 2014 at 5:53 pm

        Yes, i actually use an older version of SMS on my laptop, which i was using at the time. It is not a “mission critical” patch, but for those that have experienced the css display resize problem (which actually stems from a bug in webkit, not our code) this will be important.

        There is a bug in webkit for nested child DIV’s, where a value (probably margin) is somehow subtracted to the child controls. So the RTL fixes this by doing a recursive “scale” of positions/sizes. This fixup comes with a price, namely a delay in the proper resize-sequence — which the requestAnimFrame call helps to relieve.

        A more “proper” change will be in the next official update.

  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: