All you need to do to make an input field is define a menu item for the input field.
After that, with the same code as the Basic usage, the AM_MenuExec function performs all character input and editing processing.
  1. Defines an input buffer for the input field.
    The string displayed in the input field is always stored in this buffer. The initial value displayed in the input field is read from this buffer. The result of entering a character is also written to this buffer.
    Sample
    static char UID_EditBuf[8+1] = {""};
    

  2. Defines the information required to control the input field with AM_EditParam structure .
    Set the following information.
    • Maximum number of characters.
    • Display color of the cursor when displaying the cursor.
    • Display color of candidate characters when using alphabetic mode.
    • Option flags that specify the details of the input operation
    • Pointer to the input buffer.
    • Length of the input buffer.
    • Other
    Sample
    static const AM_EditParam EditParamUID = {
        8,                  // MaxDigits
        RGB_WHITE,          // Cursor foregraund Color
        RGB_BLUE,           // Cursor backgraund Color
        RGB_WHITE,          // Shift mode foregraund Color
        RGB_BLUE,           // Shift mode backgraund Color
        AM_EDIT_NUMERIC|AM_EDIT_UNDERLINE|AM_EDIT_CLEAR_ON_FIRST_CHAR|AM_EDIT_NO_CURSOR,    // EditOption
        NULL,               // alphaCandidateTable
        UID_EditBuf,        // Value
        sizeof(UID_EditBuf) // ValueBufSize
    };
    

  3. For the menu item for the input field, set AM_TEXT_EDIT to showControl of the AM_MenuItem structure, and in menuText, specify the pointer that points to the above AM_EditParam structure.
    Sample
    static const AM_MenuItem SettingtMenuTable[] = {
    //   itemID,     y, x, menuText,              Palette, visible, enabled, selectable, showControl
        ...
    
        {SET_ID_UID, 6, 9, (void *)&EditParamUID, PX_EDIT, true,    true,    true,       AM_TEXT_EDIT},
    
        ...
    };
    

  4. After that, like the Basic usage, generate a menu resource with AM_CreateMenu function, display the screen with AM_ShowMenu function, wait for key input with AM_ExecMenu function and processes the event.

Tips

  • After generating the menu resource with the AM_CreateMenu function, you can use AM_GetText function or AM_SetText function to read and write the contents of the buffer.
  • In the above sample, AM_EDIT_NUMERIC is specified in the EditOption of the AM_EditParam structure as an input field for inputting numbers. If you want to enter alphabetic characters or symbols, remove AM_EDIT_NUMERIC. For details, refer to the description of the EditOption in the AM_EditParam structure.
  • When inputting alphabetic characters or symbols, press the [SHIFT] key to switch the input mode. You can display the current shift mode and candidate characters on the screen in the non numeric field if you set AM_SHIFT_MODE or AM_SHIFT_CANDIDATE in the showControl of the AM_MenuItem structure. Refer to the Sample Program and find edit_name() functionin for a coding example.
 

Sample

Numeric input sample

  ...

// Text field parameter
static char UID_EditBuf[8+1] = {""};
static const AM_EditParam EditParamUID = {
    8,                  // MaxDigits
    RGB_WHITE,          // Cursor foregraund Color
    RGB_BLUE,           // Cursor backgraund Color
    RGB_WHITE,          // Shift mode foregraund Color
    RGB_BLUE,           // Shift mode backgraund Color
    AM_EDIT_NUMERIC|AM_EDIT_UNDERLINE|AM_EDIT_CLEAR_ON_FIRST_CHAR|AM_EDIT_NO_CURSOR,    // EditOption
    NULL,               // alphaCandidateTable
    UID_EditBuf,        // Value
    sizeof(UID_EditBuf) // ValueBufSize
};

// Item ID
enum _SETTING_ITEM_ID {
    SET_ID_UID = 1,
    SET_ID_APPLY,
};

// Table of the menu items for the setting screen
static const AM_MenuItem SettingtMenuTable[] = {
//   itemID,       y,           x,          menuText,                 Palette,          visible, enabled, selectable, showControl
    {0,            0,           0,          "      Settings        ", PX_TITLE_SETTING, true,    true,    false,      AM_NO_CONTROL},
    {0,            6,           1,          "UserID:",                PX_BASE,          true,    true,    false,      AM_NO_CONTROL},
    {SET_ID_UID,   6,           9,          (void *)&EditParamUID,    PX_EDIT,          true,    true,    true,       AM_TEXT_EDIT},
    {0,            AM_PIX(129), 0,          "Cancel",                 PX_GUIDE,         true,    true,    false,      AM_CLEAR_ICON},
    {SET_ID_APPLY, AM_PIX(129), AM_PIX(64), "Apply",                  PX_APPLY,         true,    true,    false,      AM_ENT_ICON},
    {-1}
};

void settings(MENU_HANDLE hMain)
{
    MENU_HANDLE hMenu;
    int event;
    bool exit = false;

    hMenu = AM_CreateMenu(SettingtMenuTable, (const pAM_Option)&SettingOption);

    while(1){
        AM_ShowMenu(hMenu, AM_SELECT_ANY_ID);

        while(1){
            event = AM_ExecMenu(hMenu);
            if (event == CLR_KEY){
                exit = true;
                break;
            }else if (event == ENT_KEY){
                // Input string is stored in UID_EditBuf.
                  ...

                exit = true;
                break;
            }
        }
        if (exit){
            break;
        }
    }

    AM_ReleaseMenu(hMenu);
    return;
}

Alphabet input sample

  ...

void edit_name(char *namebuf, int length)
{
    /////////////////////////////////////////
    // Local definition of the menu items
    /////////////////////////////////////////
    static char name_EditBuf[20+1] = {""};
    static const AM_EditParam EditParamName = {
        20,                  // MaxDigits
        RGB_WHITE,           // Cursor foregraund Color
        RGB_BLUE,            // Cursor backgraund Color
        RGB_WHITE,           // Shift mode foregraund Color
        RGB_BLUE,            // Shift mode backgraund Color
        AM_EDIT_SET_ALPHA | AM_EDIT_MOVE_CURSOR_BY_Q1Q2,    // EditOption
        NULL,                // alphaCandidateTable
        name_EditBuf,        // Value
        sizeof(name_EditBuf) // ValueBufSize
    };

    // Item ID
    enum _SETTING_NAME_ITEM_ID {
        SET_ID_ENAME = 1,
        SET_ID_EAPPLY,
    };

    // Table of the menu items for the name screen
    static const AM_MenuItem SettingtNameTable[] = {
    //   itemID,       y,           x,          menuText,                Palette,          visible, enabled, selectable, showControl
        {0,            0,           0,          "        Name         ", PX_TITLE_SETTING, true,    true,    false,      AM_NO_CONTROL},
        {0,            2,           1,          "Name:",                 PX_BASE,          true,    true,    false,      AM_NO_CONTROL},
        {SET_ID_ENAME, 3,           1,          (void *)&EditParamName,  PX_EDIT,          true,    true,    true,       AM_TEXT_EDIT},
        {0,            5,           1,          "",                      PX_GUIDE,         true,    true,    false,      AM_SHIFT_MODE},
        {0,            5,           7,          "",                      PX_GUIDE,         true,    true,    false,      AM_SHIFT_CANDIDATE},
        {0,            AM_PIX(129), 0,          "Cancel",                PX_GUIDE,         true,    true,    false,      AM_CLEAR_ICON},
        {SET_ID_EAPPLY,AM_PIX(129), AM_PIX(64), "Apply",                 PX_APPLY,         true,    true,    false,      AM_ENT_ICON},
        {-1}
    };
    /////////////////////////////////////////

    MENU_HANDLE hMenu;
    int event;

    strncpy(name_EditBuf, namebuf, sizeof(name_EditBuf)-1);

    hMenu = AM_CreateMenu(SettingtNameTable, (const pAM_Option)&SettingOption);

    AM_ShowMenu(hMenu, AM_SELECT_ANY_ID);

    while(1){
        event = AM_ExecMenu(hMenu);
        if (event == CLR_KEY){
            break;
        }else if (event == ENT_KEY){
            memset(namebuf, 0, length);
            strncpy(namebuf, name_EditBuf, length - 1);
            break;
        }
    }
    AM_ReleaseMenu(hMenu);
    return;
}

See also

Last updated: 2020/10/09