Using FireMonkey Layouts

FireMonkey has many layout controls to choose from. Come learn the differences and how to use them to create dynamic, multi-platform user interfaces.

FireMonkey Layouts with Delphi

FireMonkey Layouts with C++Builder

Understanding and using FireMonkey Layouts

FireMonkey and the FireUI makes it easy to build one form to rule all the platforms. Combining layout controls and making use of Anchors, Alignment, Padding and Margins it is easy to make one form that looks and works great on all platforms.

Anchors

  • Position relative to one or more edge(s) of parent:

    • Top
    • Bottom
    • Left
    • Right
  • Default is Top, Left
  • Moves with parent resize
  • Each control has 0 to 4 anchors

Alignment

  • Aligns control within parent, setting anchors, size and position.
  • Default is None.
  • Anchor and fill along edge:
    • Top, Bottom, Left, Right
  • Fill parent, but preserve aspect ratio:
    • Fit, FitLeft, FitRight
  • Fill along one side of the parent (priority over other edge alignments):
    • MostBottom, MostTop, MostLeft, MostRight
  • Resize only on one axis (width or height)
    • Vertical, VertCenter, Horizontal, HorzCenter
  • Miscellaneous
    • Client – Fills client area, less other children
    • Center – No resize, just centered
    • Contents – Fills client area, ignoring other children
    • Scale – resizes and moves to maintain the relative position and size

Spacing – Margins and Padding

  • Margins

    • Spacing for siblings (and parent edges)
  • Padding
    • Spacing for children

TFlowLayout

  • Arrange child controls like words in a paragraph
  • Controls arranged in order added to layout
    • Use “Move to Front” or “Send to Back” to reorder
  • Use TFlowLayoutBreak for forced line break

 

TGridLayout

  • Arranges child controls in a grid of equal sizes
  • Controls flow through grid as parent resizes
  • Use ItemWidth and ItemHeight properties
  • Customize margins of individual controls

 

TGridPanelLayout

  • Creates a grid of specified rows and columns
  • Does not change the anchor or size of child
  • Each cell can contain 1 child control
  • You set the Height, Width, Align, and Anchors of children
  • Controls can span multiple cells

 

TScaledLayout

  • Stretches child controls as it is resized at runtime
  • Doesn’t respect aspect ratios of controls
  • Set the Align of the TScaledLayout to Fit to maintain aspect ratio
  • Some styles look better zoomed than others. The font grows – it is not a bitmap scale.
  • Has properties for OriginalWidth and OriginalHeight – Compare to Width and Heightto determine scaling.

TScrollBox

TTabControl

  • Control to group child controls into tabs
  • Tabs are in a stack with one visible at a time
  • TabPosition := PlatformDefault to use platform default behavior
  • TabPosition := None to hide navigation
  • Use TTabChangeAction to animate transitions

Frames

  • Reusable pieces of User Interface

    • Includes

      • The layout
      • All the event handlers
      • All the code in the unit
  • Create 1 or more Frames, then reposition based on current layout
    • Examples:

      • In TTabControl for phone
      • Side-by-side for Tablet

TMultiView

  • One super panel with multiple modes
  • Supported modes
    • PlatformDefault
    • Drawer
    • NavigationPane
    • Panel
    • Popover
    • Custom
  • Point to MasterPane, DetailPane and definable MasterButton
  • PlatformDefault adapts to platform and orientation
  • Custom supports user defined layout and behavior

Learning Resources

ScaledLayout Helper

The AbsoluteToLocal and LocalToAbsolute for TScaledLayout don’t handle the scaling. I’ve created a class helper that adds new methods for dealing with scaling.


1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

{ TScaledLayoutHelper - interface }

type

  TScaledLayoutHelper = class helper for TScaledLayout

    function LocalToAbsoluteScaled(const Point: TPointF): TPointF;

    function AbsoluteToLocalScaled(const Point: TPointF): TPointF;

  end;

{ TScaledLayoutHelper - implementation }

function TScaledLayoutHelper.AbsoluteToLocalScaled( const Point: TPointF): TPointF;

begin

  Result.X := Self.Position.X

              + Point.X

              * Self.Width

              / Self.OriginalWidth;

  Result.Y := Self.Position.Y

              + Point.Y

              * Self.Height

              / Self.OriginalHeight;

end;

function TScaledLayoutHelper.LocalToAbsoluteScaled( const Point: TPointF): TPointF;

begin

  Result.X := Point.X

              / Self.Width

              / Self.OriginalWidth

              - Self.Position.X;

  Result.Y := Point.Y

              / Self.Height

              / Self.OriginalHeight

              - Self.Position.Y;

end;

If you look at the original implementations of AbsoluteToLocal and LocalToAbsoluteyou will see they have different execution paths and calculations based on private members, so there may be some circumstances where my new ones don’t work as expected. They did work in my tests, and I am open to feedback.

http://delphi.org/2015/12/skill-sprint-using-firemonkey-layouts/

时间: 2024-10-14 13:16:12

Using FireMonkey Layouts的相关文章

【转载】Understanding and using FireMonkey Layouts

http://delphi.org/2015/12/skill-sprint-using-firemonkey-layouts/?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+DelphiDotOrg+%28Delphi.org%29 Skill Sprint: Using FireMonkey Layouts Posted on 15-Dec-2015 by Jim McKeeth Understanding and

FireMonkey 使用Webbrowser

DELPHI XE5 源码PASCAL:http://files.cnblogs.com/xe2011/FireMonkey_Webbrowser.rar 为了这个用上webbrowser真是费太大劲了 要让窗体2位置和窗体1的PANEL坐标一致 窗体样式要为none Web坐标才会正确 但是fire monkey没有webbrowser控件 这个费了好长时间搞成这样了 现在还有个问题没有处理 1 unit Unit1; 2 3 interface 4 5 uses 6 Windows, Mes

Layouts

[Layouts] Each layout file must contain exactly one root element, which must be a View or ViewGroup object. After you've declared your layout in XML, save the file with the .xml extension, in your Android project's res/layout/ directory, so it will p

FireMonkey 源码学习(5)

(5)UpdateCharRec 该函数的源码分析如下: procedure TTextLayoutNG.UpdateCharRec(const ACanvas: TCanvas; NeedBitmap: Boolean; var NewRec: PCharRec; HasItem: Boolean; const CharDic: TCharDic; const AFont: TFont; const Ch: UCS4Char; const NeedPath: Boolean = False);

Designing CSS Layouts With Flexbox Is As Easy As Pie

This article is an updated excerpt of the chapter "Restyle, Recode, Reimagine With CSS3″ from our Smashing Book #3, written by Lea Verou and David Storey. - Ed. Flexible box layout (or flexbox) is a new box model optimized for UI layout. As one of th

firemonkey ListView DynamicAppearance

Go Up to FireMonkey Application Design Contents [hide] 1 Customizing the List View Appearance Properties 1.1 Footer properties 1.2 Header properties 1.3 List item properties 1.4 Edited list item properties 1.5 How to Modify List View Appearance Prope

Getting Text Metrics in Firemonkey(delphiscience的博客)

Firemonkey’s abstract TCanvas class has been providing the dimensions of the bounding rectangle of some text on itself. On recent updates it has deprecated providing text rectangle directly in the canvas, in stead encouraged users to use TTextLayout

Yii2系列教程二:MVC,Forms和Layouts

上一篇文章我们简单地实现了Yii2框架安装和Hello World,而在这一篇文章当中,我们会带着好奇之心去探索一下在Yii2中的几个重要的元素组成:MVC,Forms和Layouts. 本文的目标是创建一个小小的表单应用,就是实现一个简单的类似发微博的功能,但是我还不想牵扯到数据库那一块,因为其实数据库和表在Yii2框架之中其实还是有很多东西可以讲的,打算在下一篇的文章中会详细讲到. MVC 模型(Model)对于我个人的简单理解就是一个概念集合,在这个集合里面包含该概念集合的多种数据,比如一

Firemonkey 自定义Button的Style

这篇文章模仿HTML中基于CSS的Button,通过Style实现自定义样式的Button. 前言 主要模仿的CSS代码如下: CSS Code 123456789101112131415161718192021222324252627   a.button{    text-align:center;    display:block;    width:50px;    color:#fff;    text-decoration:none;    font-weight:700;    l