beautypg.com

Apple Newton Programmer’s Newton 2.0 (for Newton 2.0) User Manual

Page 225

background image

C H A P T E R 6

Pickers, Pop-up Views, and Overviews

Overview Protos

6-25

You also need to define the following slot in your

protoOverview

:

cursor

This should be a cursor-like object.

You use the object stored in this slot to encapsulate your data. The cursor-like
object must support the methods

Entry

,

Next

,

Move

, and

Clone

. An example is

given below.

In addition, you must provide a mechanism to find an actual data item given an
index of a displayed item. In general, you need some sort of saved index that
corresponds to the first displayed item. See the example code in “HitItem”
(page 5-88) in Newton Programmer’s Reference for an example of how this is used.

You also should provide a mechanism to track the currently highlighted item,
which is distinct from a selected item.

Since your data is probably in an array, you can use a “cursor” object like this:

{

items: nil,

index: 0,

Entry:func()

begin

if index < Length(items) then

items[index];

end,

Next: func()

if index < Length(items)-1 then

begin

index := index + 1;

items[index];

end,

Move: func(delta)

begin

index := Min(Max(index + delta, 0),

kNumItems-1) ;

items[index];

end,

Clone:func()

Clone(self)}

The methods that you need to have in the cursor-like object are:

Entry

, which returns the item pointed to by the “cursor.”

Next

, which moves the “cursor” to the next item and returns that item or, if

there is no next item,

nil

.