diff --git a/GUI/inc/SGUI_VariableBox.h b/GUI/inc/SGUI_VariableBox.h index e72741c..9c416db 100644 --- a/GUI/inc/SGUI_VariableBox.h +++ b/GUI/inc/SGUI_VariableBox.h @@ -27,7 +27,7 @@ typedef struct SGUI_SIZE Width; SGUI_SIZE FocusIndex; SGUI_SIZE MaxTextLength; - SGUI_PSZSTR Value; + SGUI_PSZSTR Value; }SGUI_TEXT_VARBOX_STRUCT; typedef enum diff --git a/GUI/src/SGUI_VariableBox.c b/GUI/src/SGUI_VariableBox.c index eaf0ed7..b85b223 100644 --- a/GUI/src/SGUI_VariableBox.c +++ b/GUI/src/SGUI_VariableBox.c @@ -151,18 +151,14 @@ void SGUI_TextVariableBox_UpdateCharacter(SGUI_TEXT_VARBOX_STRUCT* pstTextValue, if(pstTextValue->MaxTextLength > VARBOX_TEXT_LENGTH_MAX) { pstTextValue->MaxTextLength = VARBOX_TEXT_LENGTH_MAX; - uiFocusIndexMax = VARBOX_TEXT_LENGTH_MAX-1; - } - else - { - uiFocusIndexMax = pstTextValue->MaxTextLength-1; } + uiFocusIndexMax = pstTextValue->MaxTextLength-1; // Ignore too long text string. uiTextLength = SGUI_Common_StringLength(pstTextValue->Value); if(uiTextLength > pstTextValue->MaxTextLength) { uiTextLength = pstTextValue->MaxTextLength; - *(pstTextValue->Value+uiFocusIndexMax) = '\0'; + *(pstTextValue->Value+uiTextLength) = '\0'; // Point at to last character position if index is more then string length. if(pstTextValue->FocusIndex > uiFocusIndexMax) { diff --git a/HMI/src/HMI_Demo05_VariableBox.c b/HMI/src/HMI_Demo05_VariableBox.c index e0a56e1..3185faf 100644 --- a/HMI/src/HMI_Demo05_VariableBox.c +++ b/HMI/src/HMI_Demo05_VariableBox.c @@ -40,7 +40,7 @@ static void HMI_DemoVariableBox_DrawFrame(SGUI_PSZSTR szTitle); //=======================================================================// static SGUI_INT_VARBOX_STRUCT stNumberVariableBox = {VARIABLE_BOX_POSX+2, VARIABLE_BOX_NUMBER_POSY+2, VARIABLE_BOX_WIDTH, -50, 100, 0}; static char arrTextVariable[TEXT_VARIABLE_LENGTH+1] = {"ABCDEFG"}; -static SGUI_TEXT_VARBOX_STRUCT stTextVariableBox = {VARIABLE_BOX_POSX+2, VARIABLE_BOX_TEXT_POSY+2, VARIABLE_BOX_WIDTH, 0, TEXT_VARIABLE_LENGTH-1, arrTextVariable}; +static SGUI_TEXT_VARBOX_STRUCT stTextVariableBox = {VARIABLE_BOX_POSX+2, VARIABLE_BOX_TEXT_POSY+2, VARIABLE_BOX_WIDTH, 0, TEXT_VARIABLE_LENGTH, arrTextVariable}; static const char stFrameTitleDefault[] = {"数值/文本编辑演示"}; static const char* szFrameTitle = stFrameTitleDefault; static uint16_t uiFocusedFlag; @@ -205,7 +205,7 @@ int32_t HMI_DemoVariableBox_OnExternalEvent(uint32_t uiScreenID,const void* pstP { if(1 == uiFocusedFlag) { - if(stTextVariableBox.FocusIndex < (TEXT_VARIABLE_LENGTH)) + if(stTextVariableBox.FocusIndex < (stTextVariableBox.MaxTextLength-1)) { stTextVariableBox.FocusIndex++; SGUI_TextVariableBox_ChangeCharacter(&stTextVariableBox, GUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NONE);