Add support of EditBox widget

Issue #251 new
Patryk Kubiak created an issue

Implementation reason

The system has to provide a possibility to edit string in gui providers such as cgraphic.

Generic Description

The goal of the task is to add support of EditBox widget in the WidgetScreen. The widget should check if there is a input device like keyboard and use it if it is possible. If it is not possible to use input keyboard device, the EditBox should use Keyboard Widget given in widget definition as Definition->TypeSpecific.EditBox.KeyboardIndex. The widget should show and hide graphic keyboard when needed. It also should allow for typing only enabled characters types.

cgraphic_keyboard_1.png

Required Interface

#!c

typedef enum
{
    oC_WidgetScreen_WidgetType_None        = 0 ,
    oC_WidgetScreen_WidgetType_EditBox ,
    oC_WidgetScreen_WidgetType_TextBox ,
    oC_WidgetScreen_WidgetType_PushButton ,
    oC_WidgetScreen_WidgetType_CheckBox ,
    oC_WidgetScreen_WidgetType_RadioButton ,
    oC_WidgetScreen_WidgetType_ProgressBar ,
    oC_WidgetScreen_WidgetType_Image ,
    oC_WidgetScreen_WidgetType_Keyboard ,

    oC_WidgetScreen_WidgetType_NumberOfTypes ,
} oC_WidgetScreen_WidgetType_t;

typedef enum
{
    WidgetType_TextBox          = oC_WidgetScreen_WidgetType_TextBox,
    WidgetType_EditBox          = oC_WidgetScreen_WidgetType_EditBox,
    WidgetType_PushButton       = oC_WidgetScreen_WidgetType_PushButton,
    WidgetType_CheckBox         = oC_WidgetScreen_WidgetType_CheckBox,
    WidgetType_RadioButton      = oC_WidgetScreen_WidgetType_RadioButton,
    WidgetType_ProgressBar      = oC_WidgetScreen_WidgetType_ProgressBar,
    WidgetType_Image            = oC_WidgetScreen_WidgetType_Image,
    WidgetType_Keyboard         = oC_WidgetScreen_WidgetType_Keyboard,

    WidgetType_NumberOfTypes    = oC_WidgetScreen_WidgetType_NumberOfTypes,
} WidgetType_t;

typedef enum
{
    oC_WidgetScreen_InputType_Letters   = (1<<0),
    oC_WidgetScreen_InputType_Numbers   = (1<<1),
    oC_WidgetScreen_InputType_Special   = (1<<2),
    oC_WidgetScreen_InputType_Function  = (1<<3),
} oC_WidgetScreen_InputType_t;
typedef struct
{
    oC_WidgetScreen_WidgetType_t            Type;
    oC_Pixel_Position_t                     Position;
    oC_Pixel_ResolutionUInt_t               Height;
    oC_Pixel_ResolutionUInt_t               Width;
    oC_WidgetScreen_ZPosition_t             ZPosition;
    const oC_WidgetScreen_Palette_t *       Palette;
    const oC_WidgetScreen_DrawStyle_t *     DrawStyle;
    oC_DefaultPathString_t                  ImagePath;
    oC_WidgetScreen_WidgetHandlers_t        Handlers;

    struct
    {
        oC_DefaultString_t                              DefaultString;
        oC_Font_t                                       Font;
        oC_WidgetScreen_TextAlign_t                     TextAlign;
        oC_WidgetScreen_VerticalTextAlign_t             VerticalTextAlign;
        oC_WidgetScreen_UpdateWidgetStringHandler_t     UpdateStringHandler;
        bool                                            Password; // Set it to true, if the input type should be of password type
    } String;

    union
    {
        struct
        {
            oC_WidgetScreen_PushButtonType_t    Type;
        } PushButton;
        struct
        {
            oC_Pixel_ResolutionUInt_t   OptionWidth;
            oC_Pixel_ResolutionUInt_t   OptionHeight;
            oC_Pixel_ResolutionUInt_t   HorizontalCellSpacing;
            oC_Pixel_ResolutionUInt_t   VerticalCellSpacing;
        } CheckBox, RadioButton;
        struct
        {
            const oC_WidgetScreen_KeyboardPageDefinition_t *    Pages[oC_WidgetScreen_KeyboardPage_Max];
            oC_Color_t                                          BackgroundColor;
            oC_ColorFormat_t                                    ColorFormat;
        } Keyboard;
        struct
        {
            oC_WidgetScreen_InputType_t     InputType;      // Type of allowed input
            oC_WidgetScreen_WidgetIndex_t   KeyboardIndex;  // Index of keyboard widget
        } EditBox;
    } TypeSpecific;
} oC_WidgetScreen_WidgetDefinition_t;


static void DrawEditBox                 ( Widget_t * Widget , oC_ColorMap_t * ColorMap, oC_Pixel_Position_t ScreenPosition );
static bool RegisterEditBoxActivity     ( Widget_t * Widget , oC_Pixel_Position_t ScreenPosition );
static bool UpdateEditBoxState          ( Widget_t * Widget , oC_Pixel_Position_t ScreenPosition );
static bool CheckEditBoxDefinition      ( const WidgetDefinition_t * Definition );

static const WidgetHandlersDefinition_t WidgetHandlersDefinition[oC_WidgetScreen_WidgetType_NumberOfTypes] =
{
    [ WidgetType_EditBox     ] = { .DrawWidget = DrawEditBox      , .UpdateState = UpdateEditBoxState       , .RegisterActivity = RegisterEditBoxActivity       , .CheckDefinition = CheckEditBoxDefinition         } ,
    [ WidgetType_TextBox     ] = { .DrawWidget = DrawTextBox      , .UpdateState = NULL                     , .RegisterActivity = NULL                          , .CheckDefinition = NULL                           } ,
...
};

Bitbucket

https://bitbucket.org/chocos/chocos/issues/251/add-support-of-editbox-widget

Trello

https://trello.com/c/na8OXhBm

Story

  • [ #240 ] - Preparation of the sample graphic program

List of requirements

  • [ #251 ] - WidgetScreen supports EditBox widget
  • [ #251 ] - EditBox widget uses input keyboard device if it exist
  • [ #251 ] - EditBox widget uses graphic keyboard widget if it is set
  • [ #251 ] - EditBox prints string as * if the Password in the widget definition is set to true.

Comments (5)

  1. Log in to comment