Getting More from Components
出自OpenFace
Chapter 15. Getting More from Components
Part III. Fundamental Concepts
(该里面的内容是否保留,若保留,如何更改)
OpenLaszlo components are high-level objects that implement common user-interface functions.
Sources for LZ components are here.
Earlier chapters have shown simple usage of components. This chapter describes various more advanced ways to use components, and contains summary descriptions of how to extend components and create new ones. (These topics are covered in greater depth in later chapters.)
目录 |
Customizing components
All components have several attributes, such as background color and text color, to which you can assign different values to change the component's appearance. You can set individual values for a single component, and you can also set a "style" for a group.
Data-backed versus instance components
Many components, such as lists and combination, or "combo" boxes, are driven by data that is in XML format. For some components, you supply the data to the component "inline", that is, within the actual tag that defines an instance. For others, data comes from an associated dataset.
To see how these compare, inspect the reference pages for <combobox> and <datacombobox>. The choice of which to use depends on personal preference and the nature of the problem you're trying to solve. Data-backed components such as <datacombobox> provide a nice separation between data and presentation and make it easier to consume data from external sources. Instance components like <combobox> are conceptually simpler and often more convenient and easier to understand.
Building your own components
As you design more powerful applications you may find that the existing components do not meet your needs. In that situation you can build your own custom components. Designing your own components is a subject beyond the scope of this chapter, but here is a brief description of what's involved.
Implementing new components has two general aspects:
devising the component's behavior
devising its visual appearance.
Implementing behavior
To learn how to do this, first make sure that you understand classes and how to extend them, as explained in Chapter 25, Classes and Chapter 30, Extending Classes. Then read the Component Design Guide on extending components.
Implementing appearance
Designing the visual appearance of a new component requires a designer's eye and meticulous attention to detail—at the level of placement of individual pixels.
The role of the graphic designer on Laszlo projects is explained in the Designer's Guide. In addition, we recommend that you study the construction of the LZ components, as explained in Chapter 31, Designing Custom Components.
Example: Extending the <alert> component
As explained above, sometimes you can create your own new component by subclassing, or extending an existing component. Here the <alert> class is extended to create a new component called "myalert". It is trivially different from the default <alert>; its only difference is that it centers nicely over the survey box.
Example 15.2. extending a component
<class name="ma" x="${Math.max(survey.width-this.width,0)/2}" y="${Math.max(survey.height-this.height,0)/3}"> </class>

