The Podcast at Delphi.org

The Podcast about the Delphi programming language, tools, news and community.

15 2015

Skill Sprint: Using FireMonkey Layouts

by Jim McKeeth

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

https://youtu.be/XBRACAW_sAc

FireMonkey Layouts with C++Builder

https://youtu.be/oIimgJAlJDM

 

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

Alignment

Spacing – Margins and Padding

TFlowLayout

FlowLayout1 FlowLayout2

TGridLayout

GridLayout2 GridLayout1

TGridPanelLayout

GridPanelLayout2 GridPanelLayout1

TScaledLayout

ScaledLayout-Stretch

TScrollBox

TTabControl

Frames

TMultiView

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.

[delphi]

{ 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; [/delphi]

If you look at the original implementations of AbsoluteToLocal and LocalToAbsolute you 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.

tags: FireMonkey - Layouts - Skill Sprint - webinar