Extending LiveCode Guide

Elanor Buchanan July 7, 2016 57

Extending LiveCode Introduction LiveCode 8.0 is the most exciting release in the history of the technology. It provides a simple way to extend the functionality or control set of LiveCode. Our focus in LiveCode 8.0 is extensibility. You can now build and share widgets (custom controls) and libraries that are treated by LiveCode as engine

Documenting the Widget

Elanor Buchanan July 5, 2016 58

Widget description A description of the widget can be included in a comment block at the top of the LCB file. This description will appear in the Dictionary stack under the API entry for the widget identifier. Add a comment block with a description of the Pie Chart widget at the start of the LCB

Installing and Including the Widget in a Standalone

Elanor Buchanan July 5, 2016 59

Installing the widget To install the widget: Open the Extension Builder from the Tools menu. Load the ‘pieChart.lcb’ file. Click Install. Select the icons. These are available in the Resources for this lesson. The Pie Chart widget will appear in the Tools Palette. Include the widget in a standalone When building a standalone that includes

Responding to Mouse Events

Elanor Buchanan July 5, 2016 60

Responding to user actions The Rotated Text widget responded to clicks by sending a mouseUp message. We could do the same with the Pie Chart widget but it would be more useful to tell the user which segment had been clicked on. To do this we will Work out which sector of the pie chart

The OnPaint Handler

Elanor Buchanan July 5, 2016 61

The OnPaint handler The OnPaint handler draws the widget. The Pie Chart is a fairly complex widget so drawing the widget consists of a number of steps. Get the width and  the height of the widget. Check if the labels are to be shown If the labels are not to be shown Work out the

The OnCreate Handler

Elanor Buchanan July 5, 2016 62

The OnCreate handler The OnCreate handler is sent to a widget when it is first created by LiveCode. This handler can be used to initialise default data and, where applicable, reduce the burden for calculating constants etc in the OnPaint handler. Add the OnCreate handler to the LCB file Define a variable, tSectors, to hold

Widget Properties

Elanor Buchanan July 5, 2016 63

Creating the LiveCode Builder file As with the Hello World Library and Rotated Text Widget we will start a new LiveCode Builder source file. Create a new directory. Create a new plain text file in the directory and save it to disk with the extension “lcb”. I am naming my file “pieChart.lcb” but you can

Documenting the Widget

Elanor Buchanan July 5, 2016 64

Extensions can provide an API (Dictionary) and User Guide as part of the installed package. They are installed and viewable through the LiveCode Dictionary stack. In Lesson 2 we documented a library extension, which involved documenting the handlers provided by the library. To document the widget we will document the properties and messages associated with