Smart Mobile Studio
  • News
  • Forums
  • Download
  • Store
  • Showcases
    • Featured demos
    • The Smart Contest 2013, Round 1 – Graphics
  • Documentation
    • Get the book
    • System requirements
    • Prerequisites
    • Getting started
      • Introduction
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • Themes and styles
    • Project types
      • Visual project
      • Game project
      • Console project
    • Layout manager
    • Networking
      • TW3HttpRequest
      • TW3JSONP
      • Loading files
  • About

pmSmart Box Model

This article explains how Smart Mobile Studio takes care of margins, padding, borders and positions controls. Just like in the CSS Box Model, all elements can be considered as boxes. All controls can have margins, border and padding which affect how your control looks like.

The RTL has three PositionModes that decide how your control is positioned and sized:

  • pmRelative
  • pmAbsolute
  • pmSmart (default)

pmRelative and pmAbsolute positions the controls according to the CSS Box Model. In the standard CSS Box Model your controls full size depends on the padding, border and margin of the style. If you do a MyControl.SetSize(320,50), your control’s size will actually be bigger as the browser adds the padding, margin and border to the control resulting in the control “leaking out” of the desired area. So to make sure that your control occupies just the right area needs quite a lot of calculations and careful work.

Because the standard CSS Box Model is hard to work with, Smart Mobile Studio offers an innovative new PositionMode: pmSmart, which is extremely easy and powerful to use.

The leading idea behing pmSmart is that the RTL should automatically take care of positioning and sizing your controls according to the margin, padding and border sizes. So if you do MyControl.SetSize(320,50), Smart Mobile Studio makes sure that the control does not “leak out” of that area. It also automatically positions the control respecting the parent control’s margin and border.

  • Width returns the full width of your control including the margin, border and padding.
  • Height returns the full height of your control including the margin, border and padding.
  • ClientRect returns the usable client area after margin, border and padding have been excluded.
  • Top and Left is relative to the usable client area.

Guidelines:

  • Use ClientRect (or ClientWidth and ClientHeight) to know how big an area you have inside the control to work with.
  • Anything you put inside a control should be inside ClientRect to make sure that you respect the parent control’s boundaries.
  • When you put anything inside ClientRect, the RTL will make sure that it does not overlap the control’s padding. So if you do a MoveTo(0,0), the RTL will automatically put your control to the proper location at the top left corner. (The red arrow in the picture)

Below is example code that creates a Parent Panel and fills it with three child panels. Each child panel has a full size label inside it. Notice how the code does not have to do any calculations of margins, paddings and borders. All that is taken care by the Smart Mobile Studio RTL.

  var ParentPanel:=TW3Panel.Create(Self);
  ParentPanel.SetBounds(0,0,ClientWidth,100);

  //Calculate how wide the child panels can be
  var ChildPanelWidth:=ParentPanel.ClientWidth div 3;

  for var i:=0 to 2 do begin
    var ChildPanel:=TW3Panel.Create(ParentPanel);
    ChildPanel.SetBounds(i*ChildPanelWidth,0,ChildPanelWidth,ParentPanel.ClientHeight);

    //Fill the client panel with a label
    var lbl:=TW3Label.Create(ChildPanel);
    lbl.SetBounds(ChildPanel.ClientRect);
    lbl.Caption:='Panel '+IntToStr(i+1);
    //Center the label caption
    lbl.AlignText:=taCenter;
  end;

Pages

  • About
  • Feature Matrix
  • Forums
  • News
  • Release History
  • Download
  • Showcases
    • The Smart Contest 2013, Round 1 – Graphics
  • Store
  • Documentation
    • Creating your own controls
    • Debugging, exceptions and error handling
    • Differences between Delphi and Smart
    • Get the book
    • Getting started
      • Introduction
      • Local storage, session storage and global storage
      • Application architecture
      • The application object
      • Forms and navigation
      • Message dialogs
      • pmSmart Box Model
      • Themes and styles
    • Layout manager
    • Networking
      • Loading files
      • TW3HttpRequest
      • TW3JSONP
    • Prerequisites
    • Real data, talking to sqLite
    • System requirements
    • Project types
      • Visual project
      • Game project
      • Console project

Archives

  • December 2019
  • December 2018
  • November 2018
  • July 2018
  • June 2018
  • February 2018
  • September 2017
  • April 2017
  • November 2016
  • October 2016
  • September 2016
  • April 2016
  • March 2016
  • January 2016
  • October 2015
  • September 2015
  • July 2015
  • April 2015
  • January 2015
  • December 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • June 2014
  • March 2014
  • February 2014
  • January 2014
  • December 2013
  • November 2013
  • October 2013
  • August 2013
  • July 2013
  • June 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • January 2013
  • December 2012
  • November 2012
  • August 2012
  • July 2012
  • June 2012
  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • November 2011
  • October 2011
  • September 2011

Categories

  • Announcements (25)
  • Developers log (119)
  • Documentation (26)
  • News (104)
  • News and articles (16)

WordPress

  • Register
  • Log in
  • WordPress

Subscribe

  • Entries (RSS)
  • Comments (RSS)
© Optimale Systemer AS