Saving and Loading Widgets

Elanor Buchanan July 5, 2016 65

Saving and loading widgets Creating, saving and loading widgets In Lesson 3 we looked at the core handlers but so far we have only implemented the OnPaint and OnCreate handlers. In this lesson we will implement the OnSave and OnLoad handlers. OnSave: Sent when your widget is about to be destroyed and enables the widget to save

Handling Mouse Events

Elanor Buchanan July 5, 2016 66

You will often want to create widgets that can respond to user actions. LiveCode Builder provides a range of messages, similar to LiveCode even messages, some examples are: OnMouseDown OnMouseUp OnDoubleClick OnKeyPress You can choose which of these messages your widget will handle and how to handle them. Note that the event names are all one

Integrating Properties

Elanor Buchanan July 5, 2016 67

In Lesson 3 we defined the rotation property of the widget. Properties are shown in the Basic pane of the Property Inspector. The name of the property is shown as the label in the Property Inspector. A standard editor is shown for the property. property “rotation” get mRotation set setRotation You can more fully define

Installing the Widget and adding it to a Stack

Elanor Buchanan July 5, 2016 68

Installing the Widget and Adding it to a Stack To install a widget we use the Extension Builder. Open the Extension Builder from the Tools Palette. Select the Open button. Load the ‘rotatedtext.lcb’ file. Click Install. Choose the icon and high-resolution icons. These can be found under the Resources tab of this lesson. Put the icon

Compiling and Testing the Widget

Elanor Buchanan July 5, 2016 69

Testing the Widget Now we have completed the OnPaint handler we are ready to test the widget. This is the full code of the widget, so far. widget community.livecode.elanorb.rotatedtext use com.livecode.canvas use com.livecode.widget use com.livecode.engine use com.livecode.library.widgetutils metadata title is “Rotated Text” metadata author is “Elanor Buchanan” metadata version is “1.0.0” private variable mRotation as

Defining a Widget

Elanor Buchanan July 5, 2016 70

2Creating a LiveCode Builder Widget Just like libraries widgets are written in a text editor. Start by creating a plain text file in a new directory and save it to disk with the extension “.lcb”. I am naming my file “rotatedText.lcb” but you can name your file anything suitable. Note: The extension builder currently relies

Introduction

Elanor Buchanan July 5, 2016 71

Introduction The second type of extension that that be created is a widget. A widget is a custom control that is treated as an engine level element. Widgets appear in the Tools Palette and can be added as controls to any LiveCode stack. The Rotated Text Widget displays text and allows the user to set

Conclusion

Elanor Buchanan July 5, 2016 72

Contratulations You have completed this lesson, you can now Use explicit typing Perform type conversion Use LCB lists and arrays Pass parameters to library handlers Add documentation to libraries Tweet this lesson Share on Facebook Discussion forum