Text Class: Buttons, Textfields, Labels

From MorphOS Library

Revision as of 09:24, 5 January 2011 by Krashan (talk | contribs) (Initial import, chapters.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Grzegorz Kraszewski


Introduction

Labels

Textfields

The Text MUI class is used not only for creating static texts or labels (like in the "Hello World!" example), but also framed readonly text gadgets and textual buttons. All these object differ only in attributes. A read-only framed text field has a specific background and frame:

Object* create_resdisplay(void)
{
  Object *obj;

  obj = MUI_NewObject(MUIC_Text,
    MUIA_Frame, MUIV_Frame_Text,
    MUIA_Background, MUII_TextBack,
  TAG_END);

  return obj;
}

Buttons

As said above, a text button is an instance of the Text class too. It has more attributes than a plain label however. MUIA_Text_PreParse attribute centers the text in the object using a control code of the MUI text engine. After setting a frame and a background, a proper font is also specified with MUIA_Font. Forgetting this attribute is one of common interface design errors. Next four attributes are related to user input. MUIA_InputMode attribute defines type of button (push or toggle one). MUIA_CycleChain makes the button reachable with keyboard. Incomplete keyboard support for GUI is another common error and should be avoided. All gadgets receiving user input should have MUIA_CycleChain set. Most important gadgets should be also reachable with single keys. MUIA_ControlChar sets a key, which activates the gadget. For textual gadgets a letter of this key should be also underlined with MUIA_Text_HiChar. It implies that the character used should be present in the gadget label. Both these attributes should be set to small letters. MUIA_ControlChar set to a capital letter will force user to press SHIFT. MUIA_Text_HiChar is case insensitive. Digits can be also used for control characters, if button labels contain them. Using other characters is strongly discouraged.

The function is called six times in the code, and creates six pushbuttons. The toggle button "Large Data" is created by very similar create_datasize_button() function, which differs in MUIA_InputMode value. As it is used once only, the button label and control character are hardcoded inside the function and not passed as arguments.

MUIA_HorizWeight and MUIA_Text_SetMax attributes are used for layout control. They are described in the autodoc of Area and Text class respectively.

Object* create_button(char *label, char control)
{
  Object *obj;

  obj = MUI_NewObject(MUIC_Text,
    MUIA_Text_Contents, (ULONG)label,
    MUIA_Text_PreParse, "\33c",
    MUIA_Frame, MUIV_Frame_Button,
    MUIA_Background, MUII_ButtonBack,
    MUIA_Font, MUIV_Font_Button,
    MUIA_InputMode, MUIV_InputMode_RelVerify,
    MUIA_Text_HiChar, control,
    MUIA_ControlChar, control,
    MUIA_CycleChain, TRUE,
    MUIA_HorizWeight, 1,
  TAG_END);

  return obj;
}