• Home >>
  • Curl - Developer FAQ - GUI Toolkit
Japanese
Curl, Inc. Logo
Richer Internet Applications
   Developers
      Code Samples
      XML Document Model
      Community
      Books
      FAQ
      Release Notes
         Curl Mac Beta
         Curl RTE 5.0.2
         Curl IDE 5.0.1002
         Curl RTE 4.0.4
         Curl RTE 3.0.10

FAQ - GUI Toolkit

GUI Toolkit 1

What is a graphic hierarchy?

  2

What are options?

  3

What is the difference between a local option and a nonlocal option?

  4

What is the difference in using local options vs. fields?

  5

What is the difference between the graphic hierarchy and the class hierarchy?

  6

I added a button to an HBox but it went somewhere else. Why?


 

1 What is a graphic hierarchy?

Answer:

A graphic hierarchy is defined by the nesting of graphical containers. If a graphic is any type of Box, it can contain other graphical objects. These objects are its children in the graphic hierarchy.

 

2 What are options?

Answer:

An option is one way to store a property of an object. (A field is another way.) An option can have a default value and if the value of the property is not set, it automatically has this default value. In this case, the Curl® language doesn't need to physically store a value on the object. This can result in a substantial space savings when the property is seldom set.

Change handlers can be attached to options. A change handler is a block of code that is run whenever the value of the option changes.

 

3 What is the difference between a local option and a nonlocal option?

Answer:

The value of a nonlocal option is inherited from the parent container if it is not set on the object itself. A local option is not inherited from its container. If its value is not set, it will have the default value specified when the option was declared.

Nonlocal (inherited) options are usually used when it is expected that most objects in a container will share the same value. For example, color is a nonlocal option because all text in a given document is usually the same color. Another way to look at it is this: if you are defining a property and you want to be able to change its value on a container and have all objects inside the container be affected at once, use a nonlocal option.

 

4 What is the difference in using local options vs. fields?

Answer:

Using a local option can save space if the property usually has the default value. A local option also allows you to specify a change handler. On the other hand, a local option is slower (both to set and to access) and it takes up more space if it is assigned a value. In short, both local and nonlocal options trade speed for convenience and space savings.

 

5 What is the difference between the graphic hierarchy and the class hierarchy?

Answer:

The class hierarchy is determined by inheritance and is defined at compile time. The graphic hierarchy is determined by physical containment of graphical objects within one another. It is undefined until runtime. It can change at runtime if objects are created, deleted, or moved.

 

6 I added a button to an HBox but it went somewhere else. Why?

Answer:

When a Graphic already has a parent, and then you attach it to a new parent, the Graphic is automatically detached from the old parent. This sometimes happens when you don't expect it to. For example, consider this fragment of a Curl applet:

{let h:HBox = {HBox "Click here:"}}
{h.add {CommandButton label="Hello"}}
{value h}

This surprisingly places the button before the "Click here" text. This is the most common example of the problem. Here's what happened:

At the top level of a Curl applet, each value is added to the file as it is computed. The CommandButton is added to the HBox, but the result of calling add is the thing that was added, so this is immediately removed from the HBox and added to the document. The {value h} expression then adds the HBox to the document, but by then all it contains is the text.

The solution is to surround all of the code in the value block:

{value
  {let h:HBox = {HBox "Click here:"}}
  {h.add {CommandButton label="Hello"}}
  h
}

The {value ...} expression returns only the last expression evaluated. Thus the result of h.add is ignored and the button is not moved.