VCL Features in Firemonkey 2 by Marco Cantù, Senior Product Manager, Embarcadero
Total Page:16
File Type:pdf, Size:1020Kb
25_26_TXD 28_1_Layout 1 1/10/13 9:16 AM Page 25 TECH BRIEF VCL Features In FireMonkey 2 by Marco Cantù, Senior Product Manager, Embarcadero When the FireMonkey library made its debut The same is true for the action objects (here listed from base to derived in Delphi XE 2 and RAD Studio XE 2, many class), declared in the following units: developers were excited about its potential • TBasicAction in System.Classes but some were wary of adopting a new • TContainedAction in System.Actions framework. Some of the concerns might • TCustomAction and TAction in FMX.ActnList have been due to a lack of understanding of the architecture of the new library, or being In terms of features, actions in FireMonkey are almost identical to their unsure how to get by without some classic VCL counterpart, offering predefined actions, direct hooks to visual VCL features that they were accustomed to. controls, and much more. Notice, though, that I’m referring to the plain Delphi XE 3 and RAD Studio XE 3 change all ActionList component, not the more sophisticated ActionManager, that and give Delphi and RAD Studio users which is not available in FireMonkey. new reasons to look at multi-device and In Figure 1 there is a snapshot of one of the official demos, showing multi-platform development. the actions list editor and the set of standard actions in FireMonkey Now with the release of the second version (captured on a beta version, so the final content might change). of FireMonkey in Delphi XE 3, a number I really like the overall ActionList architecture a lot, so I’m quite happy of the limitations of the first release have to see it available in FireMonkey. Notice that this architecture is also the been overcome. The architecture hasn’t change much, but has been fine tuned and improved in a few areas, and many missing pieces have been introduced matching a lot of features found in the VCL. Embarcadero choose to name the new version of the library “ FireMonkey FM 2” to underline the fact this is now a more robust and complete library. In this article I’ll provide an overview of the changes and extensions of FM 2, focusing exclusively on features that were traditionally available in the VCL and have been moved over to the new user interface library. Other new features, from Video support to Pixel- Perfect styles, and from Sensors to Metropolis UI, will be worth another article. ACTIONS AND ACTIONLIST I think that the most relevant features of the Figure 1 - FireMonkey now has an ActionList component, with its editor and a set of standard actions. VCL that has been asked for since FireMonkey was released and that is now available is the foundation of other building blocks of the VCL, like gestures, which in use of Actions connected with user interface fact are tied to Actions also in FireMonkey. elements. In FM 2 there is now a TActionList non-visual component, which works very TOUCH AND GESTURES similarly to its VCL counterpart (but they are In the VCL, actions have been a foundation for gestures management, and technically different components). To be more the lack of actions (and possibly also the lack of time) prevented this key precise, the FireMonkey TActionList class feature to be available in the first version of FireMonkey. Needless to say, inherits from the base class the focus on modern architectures and on phones and devices makes it TCustomActionList , both declared in the compulsory to have a good support for gestures, movements of the FMX.ActnList unit and specific to the library. finger (or mouse) over a portion of the form of the application. The base class of TCustomActionList , As you certainly know if you looked into gestures in the VCL, a gesture however, is called TContainedActionList . is a movement of the finder or mouse, which is compared against a set This class is part of the RTL (specifically of predefined ones or custom ones defined by the user. This is done System.Actions) shared with the VCL. The VCL either using a native Windows gesture engine or a custom one available TActionList component, in fact, also inherits in Delphi. It seems this engine has been fine-tuned differently from the from this base class. TECHXTEND .COM 800.445.7899 25 25_26_TXD 28_1_Layout 1 1/10/13 9:17 AM Page 26 TECH BRIEF past to recognize more imprecise gestures made with Another feature related to controls positioning is the fingers (“fat-fingers” recognition). availability of a new set of layouts. These are controls As you drop in a GestureManager component in a containers in which the position of the contained controls is FireMonkey form, you can use the form Touch property, not an absolute position ( X and Y), but depends on the position of other elements. The basic flow control is like in hook in the GestureManager sub-property, and then pick one or more gestures connecting them to actions an HTML page, where elements just follow each other (with in an ActionList component. You can see a very rough optional spacing). sample in Figure 2 . The new version of FireMonkey introduces several layouts: a TFlowLayout , a TFlowLayoutBreak (which lets you customize the breaks between rows), and a TGridLayout (which doesn’t look as complete as the VCL counterpart). As an example of a FlowLayout you can see Figure 3 . Figure 2 - FireMonkey has gesture support, much like the VCL, which lets you connect gestures to actions. You can also handle gestures at a lower level, with the OnGesture event. In this case you’ll notice some Figure 3 - A FireMonkey form with a FlowLayout differences from the past, as the TGestureEventInfo control hosting a few check boxes. structure passed as parameter has new information, The FlowLayout control has a few specific properties, like the like the inertia vector and the tap location: following (taken from the demo used to capture Figure 3): TGestureEventInfo = record Justify = fjLeft GestureID: TGestureID; JustifyLastLine = fjLeft Location: TPointF; FlowDirection = fdLeftToRight Flags: TInteractiveGestureFlags; HorizontalGap = 3. Angle: Double; 000000000000000000 VerticalGap = 3. InertiaVector: TPointF; 000000000000000000 Distance: Integer; CONCLUSION TapLocation: TPointF; Now that we have FireMonkey FM 2, we can start to assess the end; library and its role much better than for the first version. So There is also support for multi-touch gestures (called we can now ask ourselves if this is a worthwhile alternative interactive gestures, like in the VCL), which require a to VCL for new applications or maybe also to move existing multi-touch screen or touch pad. Again, gesture support ones over. Of course this mainly depends on your needs, on is very relevant for phones and tables, while few PCs the importance of supporting the Mac OS X operating system have a touch screen these days. However, kiosk for your applications, on the number of complex third party applications really need gesture management, and touch components you are currently using in the VCL, on any monitors might as well become much more common Windows API calls you are currently making, and much more. with Windows 8. What is quite obvious from looking at FM 2 features is that CONTROLS POSITIONING Embarcadero is investing heavily in FireMonkey as a user- In the second version of FireMonkey, there are also a few interface library, for desktop and (soon) for mobile platforms. features related with controls positioning and sizing that And it is the mobile platform where FireMonkey will really come from the VCL. One of them is the use of Anchors, shine, opening up many new possibilities. Having a single which let you keep the position of a control tied to the library (and in many cases a single source code) you can use right side of the hosting form, rather than the left one for native Windows, Mac OS X, iOS, and Android apps could be (or the bottom side rather than the top one). You can a dream come true for Delphi (and C++Builder) developers. also select both left and right anchors to make the control resize along with the hosting control or form. See all Embarcadero products & pricing at techxtend.com/embarcadero If you used this feature in the VCL, you’ll find it very similar in FireMonkey. Very appreciated, I think, as anchors give a lot of flexibility in building the user interface. 26 800.445.7899 TECHXTEND .COM.