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

Page 120

Advertising
background image

C H A P T E R 3

Views

3-36

Using Views

To remove a view created by

AddStepView

, use the

RemoveStepView

function.

This function takes two parameters: the parent view from which you want to
remove the child view, and the view (not its template) that you want to remove.

For details on an easy way to create a template dynamically, see “Creating
Templates” (page 3-36).

Using the BuildContext Function

3

Another function that is occasionally useful is

BuildContext

. It takes one

parameter, a template. It makes a view from the template and returns it. The view’s
parent is the root view. The template is not added to any

viewChildren

or

stepChildren

array. Basically, you get a free-agent view.

Normally, you won’t need to use

BuildContext

. It’s useful when you need to

create a view from code that isn’t part of an application (that is, there’s no base
view to use as a parent). For instance, if your

InstallScript

or

RemoveScript

needs to prompt the user with a slip, you use

BuildContext

to

create the slip.

BuildContext

is also useful for creating a view, such as a slip, that is larger than

your application base view.

For details on an easy way to create a template dynamically, see the next section,
“Creating Templates”

Creating Templates

3

The three immediately preceding techniques require you to create templates. You
can do this using NewtonScript to define a frame, but then you have to remember
which slots to include and what kinds of values they can have. It’s easy to make
a mistake.

A simple way of creating a template is to make a user proto in NTK and then use it
as a template. That allows you to take advantage of the slot editors in NTK.

If there are slots whose values you can’t compute ahead of time, it doesn’t matter.
Leave them out of the user proto, and then at run time, create a frame with those
slots set properly and include a

_proto

slot pointing to the user proto. A typical

example might be needing to compute the bounds of a view at run time. If you
defined all the static slots in a user proto in the file called

dynoTemplate

, you

could create the template you need using code like this:

template := {viewBounds: RelBounds(x, y, width, height),

_proto: GetLayout("DynoTemplate"),

}

This really shows off the advantage of a prototype-based object system. You create
a small object “on the fly” and the system uses inheritance to get the rest of the

Advertising