Difference between revisions of "Subclassing List Class"
From MorphOS Library
Line 36: | Line 36: | ||
Setting the ''MUIA_Frame'' attribute to a ''List'' object to one of special values listed above, has an unexpected and undocumented sideeffect. The background for the object is set automatically according to the frame type. What is strange, this automatic setting cannot be overridden by passing ''MUIA_Background'' explicitly, the attribute is being ignored. | Setting the ''MUIA_Frame'' attribute to a ''List'' object to one of special values listed above, has an unexpected and undocumented sideeffect. The background for the object is set automatically according to the frame type. What is strange, this automatic setting cannot be overridden by passing ''MUIA_Background'' explicitly, the attribute is being ignored. | ||
− | A ''List'' object can change its both dimensions freely when a containing window is resized. For static lists, where the contents is known in advance, one can request that the object width is locked to the width of the longest item. It is also possible to lock the object height to the total height of all the items. To do this ''MUIA_List_AdjustWidth'' and MUIA_List_AdjustHeight'' attributes may be specified for the object construction. Both of them are boolean attributes, with the default value ''FALSE''. Let's add them to our ''List'' object: | + | A ''List'' object can change its both dimensions freely when a containing window is resized. For static lists, where the contents is known in advance, one can request that the object width is locked to the width of the longest item. It is also possible to lock the object height to the total height of all the items. To do this ''MUIA_List_AdjustWidth'' and ''MUIA_List_AdjustHeight'' attributes may be specified for the object construction. Both of them are boolean attributes, with the default value ''FALSE''. Let's add them to our ''List'' object: |
MUIA_List_AdjustWidth, TRUE, | MUIA_List_AdjustWidth, TRUE, | ||
MUIA_List_AdjustHeight, TRUE, | MUIA_List_AdjustHeight, TRUE, |
Revision as of 12:30, 5 February 2012
Grzegorz Kraszewski
List class is one of the most complex MUI classes. Its purpose is to display data as a list or table. Objects of List can be found in almost any MUI application. An example shown below is a List object from the Media Logger application, which shows Reggae event log. The event log list is the main item of the program window. The most important visible elements of a List object are marked with digits.
- A bar of column titles. This is an optional element, used usually when a list has multiple columns.
- Data rows. Usually contain textual information. Simple formatting like italicizing, emboldening, color change (shown on the example) may be applied. List class does not allow for more advanced formatting, for example font cannot be changed. There is a possibility for adding images however.
- Selected data rows. Selection can be done with mouse, keyboard, or from inside application using object attributes. There is a possibility of optional multiselection.
- The active row. It is selected as well usually, however in therory an item can be active, but not selected. There is even a separate setting in MUI preferences for that case.
- Horizontal scroller. Used when data do not fit horizontally. Horizontal scroller can be disabled, set to automatic (appears when needed), or always visible.
- Vertical scroller. Used when data do not fit vertically. The srcroller may be disabled.
Basic usage
The simplest case of List class usage is a single column list containing plain text strings. Then, the simplest way to define these texts is a static array. Such a List object is a static one. An array of strings is passed to the object with MUIA_List_SourceArray attribute. The attribute may be used only as an argument for a constructor. The array may be for example declared as a global variable:
STRPTR ListItems[] = { "first", "second", "third", "fourth", NULL };
The array must be terminated with a NULL pointer. The object is created as follows:
ListObj = MUI_NewObject(MUIC_List, MUIA_List_SourceArray, (ULONG)ListItems, MUIA_Frame, MUIV_Frame_ReadList, MUIA_Background, MUII_ReadListBack, MUIA_Font, MUIV_Font_List, TAG_END);
Except of MUIA_List_SourceArray attribute mentioned above, there are three attributes related to the object's appearance. They should be never omitted. MUIA_Frame defines the object frame. If not specified, the object will be frameless, which does not look good. There are two kinds of frame defined in the user preferences. MUIV_Frame_ReadList should be used for read-only lists (ones, which cannot be edited by user). Editable lists should have MUIV_Frame_InputList frame. In most of legacy Amiga GUI toolkits, read-only lists had recessed frames, while editable lists had embossed ones. Of course in MUI it is up to user, but on the application side the difference between two kinds of list frames should be maintained. The picture below shows an example appearance of a List object defined with the above code:
Setting the MUIA_Frame attribute to a List object to one of special values listed above, has an unexpected and undocumented sideeffect. The background for the object is set automatically according to the frame type. What is strange, this automatic setting cannot be overridden by passing MUIA_Background explicitly, the attribute is being ignored.
A List object can change its both dimensions freely when a containing window is resized. For static lists, where the contents is known in advance, one can request that the object width is locked to the width of the longest item. It is also possible to lock the object height to the total height of all the items. To do this MUIA_List_AdjustWidth and MUIA_List_AdjustHeight attributes may be specified for the object construction. Both of them are boolean attributes, with the default value FALSE. Let's add them to our List object:
MUIA_List_AdjustWidth, TRUE, MUIA_List_AdjustHeight, TRUE,