2017-05-29 07:54:57 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Copyright. **/
|
2017-10-08 16:03:05 +00:00
|
|
|
/** FileName: SGUI_List.c **/
|
2017-05-29 07:54:57 +00:00
|
|
|
/** Author: XuYulin **/
|
|
|
|
/** Version: 1.0.0.0 **/
|
|
|
|
/** Description: Draw list interface. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
//=======================================================================//
|
|
|
|
//= Include files. =//
|
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
#include "SGUI_Common.h"
|
|
|
|
#include "SGUI_Basic.h"
|
|
|
|
#include "SGUI_Text.h"
|
|
|
|
#include "SGUI_ScrollBar.h"
|
|
|
|
#include "SGUI_List.h"
|
|
|
|
#include "SGUI_Frame.h"
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
2017-06-02 12:33:13 +00:00
|
|
|
//= User Macro definition. =//
|
2017-05-29 07:54:57 +00:00
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
// User settings
|
2017-05-29 07:54:57 +00:00
|
|
|
#define LIST_EDGE_MULTIPLE (1)
|
2017-08-02 14:24:26 +00:00
|
|
|
#define LIST_ITEM_TEXT_BLANK_EDGEX (2)
|
|
|
|
#define LIST_ITEM_TEXT_BLANK_EDGEY (1)
|
|
|
|
#define LIST_ITEM_PARAMETER_SPLIT_WIDTH (4)
|
|
|
|
#define LIST_ITEM_PARAMETER_TEXT_LENGTH_MAX (16)
|
2017-05-29 07:54:57 +00:00
|
|
|
#define LIST_SCROLLBAR_WIDTH (5)
|
2017-08-02 14:24:26 +00:00
|
|
|
// Automatic calculation
|
|
|
|
#if(LIST_EDGE_MULTIPLE == 0)
|
|
|
|
#define LIST_EDGE_SIZE (0)
|
|
|
|
#else
|
|
|
|
#define LIST_EDGE_SIZE (LIST_EDGE_MULTIPLE*2-1)
|
|
|
|
#endif
|
2017-10-08 16:03:05 +00:00
|
|
|
#define LIST_TITLE_HEIGHT(FONT) (g_stFontSize[FONT].Height+2)
|
2017-05-29 07:54:57 +00:00
|
|
|
#define LIST_SCROLLBAR_POSX (LCD_SIZE_WIDTH-LIST_EDGE_SIZE-LIST_SCROLLBAR_WIDTH)
|
|
|
|
#define LIST_ITEM_RECT_POSX (LIST_EDGE_SIZE+2)
|
|
|
|
#define LIST_ITEM_RECT_WIDTH (LCD_SIZE_WIDTH-(LIST_ITEM_RECT_POSX*2)-LIST_SCROLLBAR_WIDTH)
|
|
|
|
#define LIST_ITEM_TEXT_AREA_WIDTH (LIST_ITEM_RECT_WIDTH-(LIST_ITEM_TEXT_BLANK_EDGEX*2))
|
|
|
|
#define LIST_ITEM_PARAMETER_AREA_WIDTH ((LIST_ITEM_TEXT_AREA_WIDTH/2)-LIST_ITEM_PARAMETER_SPLIT_WIDTH)
|
|
|
|
#define LIST_ITEM_PARAMETER_STARTX (LIST_ITEM_RECT_POSX+LIST_ITEM_TEXT_BLANK_EDGEX+(LIST_ITEM_TEXT_AREA_WIDTH-LIST_ITEM_PARAMETER_AREA_WIDTH))
|
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Static function declaration. =//
|
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
static inline void SGUI_LIST_RefreshListItems(SGUI_LIST_STRUCT* pstList);
|
|
|
|
static inline void SGUI_LIST_DrawItem(SGUI_LIST_STRUCT* pstList, SGUI_SIZE uiIndex);
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Function implementation. =//
|
|
|
|
//=======================================================================//
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_InitializeListData **/
|
|
|
|
/** Purpose: Initialize a list control data. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list data will be initialized. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: None. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_InitializeListData(SGUI_LIST_STRUCT* pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_CONTROL* pstListControl;
|
|
|
|
SGUI_LIST_DATA* pstListData;
|
|
|
|
SGUI_LIST_SUBELEMENT* pstSubElement;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
// Initialize member object pointer.
|
2017-05-29 07:54:57 +00:00
|
|
|
pstListControl = &(pstList->ControlVariable);
|
|
|
|
pstListData = &(pstList->Data);
|
|
|
|
pstSubElement = &(pstList->SubElement);
|
2017-10-11 10:59:56 +00:00
|
|
|
// Initialize visible area control parameter.
|
|
|
|
pstListControl->ListTitleHeight = LIST_TITLE_HEIGHT(pstList->FontSize); // List title height, Include border.
|
2017-05-29 07:54:57 +00:00
|
|
|
pstListControl->PageStartIndex = 0;
|
|
|
|
pstListControl->SelectIndex = 0;
|
|
|
|
pstListControl->ItemPosYOffSet = 0;
|
|
|
|
pstListControl->FirstVisibleItemPosY = LIST_EDGE_SIZE;
|
2017-10-08 16:03:05 +00:00
|
|
|
pstListControl->ListItemHeight = g_stFontSize[pstList->FontSize].Height + (LIST_ITEM_TEXT_BLANK_EDGEY*2);
|
2017-05-29 07:54:57 +00:00
|
|
|
pstListControl->VisibleItemsAreaHeight = LCD_SIZE_HEIGHT-LIST_EDGE_SIZE*2;
|
|
|
|
if(NULL != pstList->Data.Title)
|
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
pstListControl->FirstVisibleItemPosY += LIST_TITLE_HEIGHT(pstList->FontSize) + 1;
|
|
|
|
pstListControl->VisibleItemsAreaHeight -= LIST_TITLE_HEIGHT(pstList->FontSize) + 1;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
pstListControl->VisibleIntegralItemsNum = pstListControl->VisibleItemsAreaHeight/(pstListControl->ListItemHeight);
|
|
|
|
if(pstListControl->VisibleIntegralItemsNum > pstList->Data.Count)
|
|
|
|
{
|
|
|
|
pstListControl->VisibleIntegralItemsNum = pstList->Data.Count;
|
|
|
|
}
|
|
|
|
pstListControl->VisibleItemsNum = (pstListControl->VisibleItemsAreaHeight-1)/pstListControl->ListItemHeight+1;
|
|
|
|
|
2017-10-11 10:59:56 +00:00
|
|
|
// Initialize scroll bar.
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSubElement->ScrollBar.Parameter.eDirection = SGUI_SCROLLBAR_VERTICAL;
|
2017-05-29 07:54:57 +00:00
|
|
|
pstSubElement->ScrollBar.Parameter.PosX = LIST_SCROLLBAR_POSX;
|
|
|
|
pstSubElement->ScrollBar.Parameter.PosY = pstListControl->FirstVisibleItemPosY;
|
|
|
|
pstSubElement->ScrollBar.Parameter.Width = LIST_SCROLLBAR_WIDTH;
|
|
|
|
pstSubElement->ScrollBar.Parameter.Height = pstListControl->VisibleItemsAreaHeight;
|
|
|
|
pstSubElement->ScrollBar.Data.Index = 0;
|
|
|
|
pstSubElement->ScrollBar.Parameter.MaxIndex = (pstListData->Count>pstListControl->VisibleIntegralItemsNum)?(pstListData->Count-pstListControl->VisibleIntegralItemsNum-1):0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_RefreshListItems **/
|
|
|
|
/** Purpose: Refresh all visible list item display. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list data will be refreshed. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: This only refresh visible items and scrollbar. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_RefreshListItems(SGUI_LIST_STRUCT* pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_CONTROL* pstListControl;
|
|
|
|
SGUI_LIST_SUBELEMENT* pstSubElement;
|
|
|
|
SGUI_LIST_DATA* pstListData;
|
|
|
|
SGUI_SIZE uiCurrentItemIndex;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
pstListControl = &(pstList->ControlVariable);
|
|
|
|
pstListData = &(pstList->Data);
|
|
|
|
pstSubElement = &(pstList->SubElement);
|
|
|
|
|
|
|
|
uiCurrentItemIndex = pstListControl->PageStartIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
if(pstList->Data.Count > 0)
|
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-07-31 13:29:09 +00:00
|
|
|
// Recalculate scroll bar parameter.
|
|
|
|
pstListControl->VisibleIntegralItemsNum = pstListControl->VisibleItemsAreaHeight/(pstListControl->ListItemHeight);
|
|
|
|
if(pstListControl->VisibleIntegralItemsNum > pstList->Data.Count)
|
|
|
|
{
|
|
|
|
pstListControl->VisibleIntegralItemsNum = pstList->Data.Count;
|
|
|
|
}
|
|
|
|
pstSubElement->ScrollBar.Parameter.MaxIndex = (pstListData->Count>pstListControl->VisibleIntegralItemsNum)?(pstListData->Count-pstListControl->VisibleIntegralItemsNum-1):0;
|
2017-10-08 16:03:05 +00:00
|
|
|
#endif
|
2017-05-29 07:54:57 +00:00
|
|
|
// Clear list item display area.
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_Basic_DrawRectangle(LIST_ITEM_RECT_POSX, pstListControl->FirstVisibleItemPosY, LIST_ITEM_RECT_WIDTH, pstListControl->VisibleItemsAreaHeight, SGUI_COLOR_BKGCLR, SGUI_COLOR_BKGCLR);
|
2017-05-31 12:35:32 +00:00
|
|
|
// Refresh scroll bar
|
2017-05-29 07:54:57 +00:00
|
|
|
pstSubElement->ScrollBar.Data.Index = pstListControl->PageStartIndex;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_ScrollBar_RefreshScrollBar(&(pstSubElement->ScrollBar));
|
2017-05-29 07:54:57 +00:00
|
|
|
// Draw all visible items.
|
|
|
|
while((uiCurrentItemIndex < pstListControl->PageStartIndex+pstListControl->VisibleItemsNum) && (uiCurrentItemIndex < pstListData->Count))
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_DrawItem(pstList, uiCurrentItemIndex++);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
// High light focused items.
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet,
|
2017-05-29 07:54:57 +00:00
|
|
|
LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_RefreshList **/
|
|
|
|
/** Purpose: Refresh list display. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list data will be refreshed. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: This function will refresh all list display on **/
|
|
|
|
/** screen, include edge, items, title and scrollbar. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_RefreshList(SGUI_LIST_STRUCT* pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_BOX_FRAME_STRUCT stFrameData;
|
|
|
|
SGUI_LIST_DATA *pstListData;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
pstListData = &(pstList->Data);
|
|
|
|
// Draw frame
|
2017-06-07 13:50:51 +00:00
|
|
|
stFrameData.Parameter.EdgeLayers = LIST_EDGE_MULTIPLE;
|
2017-10-08 16:03:05 +00:00
|
|
|
stFrameData.Parameter.FontSize = pstList->FontSize;
|
2017-06-07 13:50:51 +00:00
|
|
|
stFrameData.Data.Title = pstListData->Title;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Frame_DrawFullScreenFrame(&stFrameData);
|
2017-05-29 07:54:57 +00:00
|
|
|
// Draw list items
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_RefreshListItems(pstList);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_SelectUpItem **/
|
|
|
|
/** Purpose: Select previous list item if existed. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be selected. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: None. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_SelectUpItem(SGUI_LIST_STRUCT* pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_CONTROL *pstListControl;
|
|
|
|
SGUI_LIST_DATA *pstListData;
|
|
|
|
SGUI_UINT16 uiReverseBlockPosY;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
pstListControl = &(pstList->ControlVariable);
|
|
|
|
pstListData = &(pstList->Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if((pstListControl->SelectIndex > 0) && (pstListData->Count > 1))
|
|
|
|
{
|
|
|
|
//Focused item and select item is visible and Integral;
|
|
|
|
if((pstListControl->SelectIndex>pstListControl->PageStartIndex+1) && (pstListControl->VisibleIntegralItemsNum>1))
|
|
|
|
{
|
|
|
|
// Unfocused current item.
|
|
|
|
uiReverseBlockPosY = pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, uiReverseBlockPosY, LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
2017-05-29 07:54:57 +00:00
|
|
|
pstListControl->SelectIndex--;
|
|
|
|
// Focused previous item.
|
|
|
|
uiReverseBlockPosY = pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, uiReverseBlockPosY, LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pstListControl->SelectIndex--;
|
|
|
|
if(pstListControl->PageStartIndex == pstListControl->SelectIndex)
|
|
|
|
{
|
|
|
|
pstListControl->ItemPosYOffSet = 0;
|
|
|
|
}
|
|
|
|
if(pstListControl->SelectIndex < pstListControl->PageStartIndex)
|
|
|
|
{
|
|
|
|
pstListControl->PageStartIndex--;
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_RefreshListItems(pstList);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_SelectDownItem **/
|
|
|
|
/** Purpose: Select next list item if existed. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be selected. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: None. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_SelectDownItem(SGUI_LIST_STRUCT* pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_CONTROL *pstListControl;
|
|
|
|
SGUI_LIST_DATA *pstListData;
|
|
|
|
SGUI_UINT16 uiReverseBlockPosY;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
pstListControl = &(pstList->ControlVariable);
|
|
|
|
pstListData = &(pstList->Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if((pstListControl->SelectIndex < pstListData->Count-1) && (pstListData->Count > 1))
|
|
|
|
{
|
|
|
|
//Focused item and select item is visible and Integral;
|
|
|
|
if((pstListControl->VisibleIntegralItemsNum>1) && ((pstListControl->SelectIndex)<(pstListControl->PageStartIndex+pstListControl->VisibleIntegralItemsNum-1)))
|
|
|
|
{
|
|
|
|
// Unfocused current item.
|
|
|
|
uiReverseBlockPosY = pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, uiReverseBlockPosY, LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
2017-05-29 07:54:57 +00:00
|
|
|
pstListControl->SelectIndex++;
|
|
|
|
// Focused previous item.
|
|
|
|
uiReverseBlockPosY = pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, uiReverseBlockPosY, LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pstListControl->SelectIndex++;
|
|
|
|
if((pstListControl->SelectIndex-pstListControl->PageStartIndex+1) == pstListControl->VisibleItemsNum)
|
|
|
|
{
|
|
|
|
pstListControl->ItemPosYOffSet = pstListControl->ListItemHeight-pstListControl->VisibleItemsAreaHeight%pstListControl->ListItemHeight;
|
|
|
|
}
|
|
|
|
if((pstListControl->SelectIndex-pstListControl->PageStartIndex+1) > pstListControl->VisibleItemsNum)
|
|
|
|
{
|
|
|
|
pstListControl->PageStartIndex++;
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_RefreshListItems(pstList);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_DrawItem **/
|
|
|
|
/** Purpose: Draw a visible list item. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be selected. **/
|
|
|
|
/** @uiIndex[in]: List item index will be draw. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: This function only draw visible items, it's **/
|
|
|
|
/** depending on the first visible item index and count **/
|
|
|
|
/** of visible items. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_DrawItem(SGUI_LIST_STRUCT* pstList, SGUI_SIZE uiIndex)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_RECT_AREA stItemTextDisplayArea;
|
|
|
|
SGUI_RECT_AREA stItemTextDataArea;
|
|
|
|
SGUI_LIST_CONTROL* pstListControl;
|
|
|
|
SGUI_LIST_ITEM* pstListItemPointer;
|
|
|
|
SGUI_CHAR szParameterStringBuffer[LIST_ITEM_PARAMETER_TEXT_LENGTH_MAX];
|
|
|
|
SGUI_SIZE uiParameterTextWidth;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
pstListControl = &(pstList->ControlVariable);
|
2017-08-02 14:24:26 +00:00
|
|
|
pstListItemPointer = SGUI_LIST_GetListItemPtr(pstList, uiIndex);
|
2017-05-29 07:54:57 +00:00
|
|
|
szParameterStringBuffer[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
|
|
|
if((uiIndex >= pstListControl->PageStartIndex) && (uiIndex < pstListControl->PageStartIndex+pstListControl->VisibleItemsNum))
|
|
|
|
{
|
|
|
|
// Prepare draw list item text.
|
|
|
|
stItemTextDataArea.PosX = 0;
|
|
|
|
stItemTextDataArea.PosY = LIST_ITEM_TEXT_BLANK_EDGEY;
|
|
|
|
stItemTextDisplayArea.PosX = LIST_ITEM_RECT_POSX + LIST_ITEM_TEXT_BLANK_EDGEX;
|
|
|
|
stItemTextDisplayArea.Width = LIST_ITEM_TEXT_AREA_WIDTH;
|
|
|
|
|
|
|
|
if(uiIndex == pstListControl->PageStartIndex)
|
|
|
|
{
|
|
|
|
stItemTextDataArea.PosY -= pstListControl->ItemPosYOffSet;
|
|
|
|
stItemTextDisplayArea.PosY = pstListControl->FirstVisibleItemPosY;
|
|
|
|
stItemTextDisplayArea.Height = pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet;
|
|
|
|
}
|
|
|
|
else if(uiIndex == pstListControl->PageStartIndex+pstListControl->VisibleItemsNum-1)
|
|
|
|
{
|
|
|
|
stItemTextDisplayArea.PosY = pstListControl->FirstVisibleItemPosY+pstListControl->ListItemHeight*(uiIndex-pstListControl->PageStartIndex)-pstListControl->ItemPosYOffSet;
|
|
|
|
|
|
|
|
if((0==pstListControl->ItemPosYOffSet) && (0 != pstListControl->VisibleItemsAreaHeight%pstListControl->ListItemHeight))
|
|
|
|
{
|
|
|
|
stItemTextDisplayArea.Height = (pstListControl->VisibleItemsAreaHeight%pstListControl->ListItemHeight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stItemTextDisplayArea.Height = pstListControl->ListItemHeight;
|
|
|
|
}
|
|
|
|
//stItemTextDisplayArea.Height = (0==pstListControl->ItemPosYOffSet)?(pstListControl->VisibleItemsAreaHeight%pstListControl->ListItemHeight):(pstListControl->ListItemHeight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stItemTextDisplayArea.PosY = pstListControl->FirstVisibleItemPosY+pstListControl->ListItemHeight*(uiIndex-pstListControl->PageStartIndex)-pstListControl->ItemPosYOffSet;
|
|
|
|
stItemTextDisplayArea.Height = pstListControl->ListItemHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw list item text.
|
2017-10-08 16:03:05 +00:00
|
|
|
SGUI_Text_DrawSingleLineText( pstListItemPointer->Text, pstList->FontSize,
|
2017-10-11 10:59:56 +00:00
|
|
|
&stItemTextDisplayArea, &stItemTextDataArea, SGUI_DRAW_NORMAL);
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
// Prepare draw parameter text.
|
|
|
|
stItemTextDataArea.PosX = LIST_ITEM_PARAMETER_SPLIT_WIDTH+1;
|
|
|
|
stItemTextDisplayArea.PosX = LIST_ITEM_PARAMETER_STARTX;
|
|
|
|
stItemTextDisplayArea.Width = LIST_ITEM_PARAMETER_AREA_WIDTH;
|
|
|
|
if(LIST_ITEM_NORMAL != pstListItemPointer->Type)
|
|
|
|
{
|
2017-05-29 12:33:35 +00:00
|
|
|
if(pstListItemPointer->Valid.Value > pstListItemPointer->Valid.Max)
|
|
|
|
{
|
|
|
|
pstListItemPointer->Valid.Value = pstListItemPointer->Valid.Max;
|
|
|
|
}
|
|
|
|
else if(pstListItemPointer->Valid.Value < pstListItemPointer->Valid.Min)
|
|
|
|
{
|
|
|
|
pstListItemPointer->Valid.Value = pstListItemPointer->Valid.Min;
|
|
|
|
}
|
|
|
|
if(pstListItemPointer->Decimal.Value > pstListItemPointer->Decimal.Max)
|
|
|
|
{
|
|
|
|
pstListItemPointer->Decimal.Value = pstListItemPointer->Decimal.Max;
|
|
|
|
}
|
|
|
|
else if(pstListItemPointer->Decimal.Value < pstListItemPointer->Decimal.Min)
|
|
|
|
{
|
|
|
|
pstListItemPointer->Decimal.Value = pstListItemPointer->Decimal.Min;
|
|
|
|
}
|
|
|
|
|
2017-05-29 07:54:57 +00:00
|
|
|
switch(pstListItemPointer->Type)
|
|
|
|
{
|
|
|
|
case LIST_ITEM_ENUM:
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Common_StringLengthCopy(szParameterStringBuffer, pstListItemPointer->EnumerationValues[pstListItemPointer->Valid.Value], LIST_ITEM_PARAMETER_TEXT_LENGTH_MAX-1);
|
2017-05-29 07:54:57 +00:00
|
|
|
szParameterStringBuffer[LIST_ITEM_PARAMETER_TEXT_LENGTH_MAX-1] = '\0';
|
2017-10-08 16:03:05 +00:00
|
|
|
uiParameterTextWidth = SGUI_Text_GetTextGraphicsWidth(szParameterStringBuffer, pstList->FontSize);
|
2017-05-29 07:54:57 +00:00
|
|
|
if(uiParameterTextWidth < LIST_ITEM_PARAMETER_AREA_WIDTH)
|
|
|
|
{
|
|
|
|
stItemTextDataArea.PosX += (LIST_ITEM_PARAMETER_AREA_WIDTH-LIST_ITEM_PARAMETER_SPLIT_WIDTH)-uiParameterTextWidth;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LIST_ITEM_DIGIT:
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Common_IntegerToStringWithDecimalPoint(pstListItemPointer->Valid.Value, pstListItemPointer->Decimal.Value, szParameterStringBuffer, 0, ' ');
|
2017-10-08 16:03:05 +00:00
|
|
|
uiParameterTextWidth = SGUI_Text_GetTextGraphicsWidth(szParameterStringBuffer, pstList->FontSize);
|
2017-05-29 07:54:57 +00:00
|
|
|
if(uiParameterTextWidth < LIST_ITEM_PARAMETER_AREA_WIDTH)
|
|
|
|
{
|
|
|
|
stItemTextDataArea.PosX += (LIST_ITEM_PARAMETER_AREA_WIDTH-LIST_ITEM_PARAMETER_SPLIT_WIDTH)-uiParameterTextWidth;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
// Undefined list item type, no any process.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Draw parameter text.
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_Text_DrawSingleLineText(szParameterStringBuffer, pstList->FontSize, &stItemTextDisplayArea, &stItemTextDataArea, SGUI_DRAW_NORMAL);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_SetListItemValue **/
|
|
|
|
/** Purpose: Set list parameter value if supported. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be selected. **/
|
|
|
|
/** @iItemIndex[in]: Index of list item index will be changed. **/
|
|
|
|
/** @iSetValid[in]: Valid value will be set. **/
|
|
|
|
/** @iSetDecimal[in]: Decimal value will be set. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: The bind value will update if existed. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_SetListItemValue(SGUI_LIST_STRUCT* pstList, SGUI_INDEX iItemIndex, int32_t iSetValid, int32_t iSetDecimal)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstSelectedListItem;
|
|
|
|
SGUI_LIST_CONTROL *pstListControl;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
pstSelectedListItem = NULL;
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(iItemIndex < pstList->Data.Count)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSelectedListItem = SGUI_LIST_GetListItemPtr(pstList, iItemIndex);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
pstListControl = &(pstList->ControlVariable);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstSelectedListItem)
|
|
|
|
{
|
|
|
|
// Set valid.
|
|
|
|
if(iSetValid > pstSelectedListItem->Valid.Max)
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Valid.Value = pstSelectedListItem->Valid.Max;
|
|
|
|
}
|
|
|
|
else if(iSetValid < pstSelectedListItem->Valid.Min)
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Valid.Value = pstSelectedListItem->Valid.Min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Valid.Value = iSetValid;
|
|
|
|
}
|
|
|
|
// Sync bind if existed.
|
|
|
|
if(NULL != pstSelectedListItem->Valid.Bind)
|
|
|
|
{
|
|
|
|
*(pstSelectedListItem->Valid.Bind) = pstSelectedListItem->Valid.Value;
|
|
|
|
}
|
|
|
|
// Set decimal.
|
|
|
|
if(iSetDecimal > pstSelectedListItem->Decimal.Max)
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Decimal.Value = pstSelectedListItem->Decimal.Max;
|
|
|
|
}
|
|
|
|
else if(iSetDecimal < pstSelectedListItem->Decimal.Min)
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Decimal.Value = pstSelectedListItem->Decimal.Min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Decimal.Value = iSetDecimal;
|
|
|
|
}
|
|
|
|
// Sync bind if existed.
|
|
|
|
if(NULL != pstSelectedListItem->Decimal.Bind)
|
|
|
|
{
|
|
|
|
*(pstSelectedListItem->Decimal.Bind) = pstSelectedListItem->Decimal.Value;
|
|
|
|
}
|
|
|
|
// Clear list item area.
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_DrawRectangle(LIST_ITEM_RECT_POSX, pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet,
|
2017-10-11 10:59:56 +00:00
|
|
|
LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight, SGUI_COLOR_BKGCLR, SGUI_COLOR_BKGCLR);
|
2017-05-29 07:54:57 +00:00
|
|
|
// refresh list item
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_DrawItem(pstList, iItemIndex);
|
2017-05-29 07:54:57 +00:00
|
|
|
// High light selected item.
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Basic_ReverseBlockColor(LIST_ITEM_RECT_POSX, pstListControl->FirstVisibleItemPosY+(pstListControl->SelectIndex-pstListControl->PageStartIndex)*pstListControl->ListItemHeight-pstListControl->ItemPosYOffSet,
|
2017-05-29 07:54:57 +00:00
|
|
|
LIST_ITEM_RECT_WIDTH, pstListControl->ListItemHeight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_GetListItemValue **/
|
|
|
|
/** Purpose: Get list parameter value if supported. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be read. **/
|
|
|
|
/** @iItemIndex[in]: Index of list item index will be read. **/
|
|
|
|
/** @piValid[out]: Valid value will be read. **/
|
|
|
|
/** @piDecimal[out]: Decimal value will be read. **/
|
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: None. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_GetListItemValue(SGUI_LIST_STRUCT* pstList, SGUI_INDEX iItemIndex, int32_t* piValid, int32_t* piDecimal)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstSelectedListItem;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
|
|
|
pstSelectedListItem = NULL;
|
|
|
|
if(NULL != pstList)
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(iItemIndex < pstList->Data.Count)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSelectedListItem = SGUI_LIST_GetListItemPtr(pstList, iItemIndex);
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstSelectedListItem)
|
|
|
|
{
|
|
|
|
// Read valid value.
|
|
|
|
if(NULL != piValid)
|
|
|
|
{
|
|
|
|
*piValid = pstSelectedListItem->Valid.Value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read decimal value.
|
|
|
|
if(NULL != piDecimal)
|
|
|
|
{
|
|
|
|
*piDecimal = pstSelectedListItem->Decimal.Value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_BindData **/
|
|
|
|
/** Purpose: Bind a 32-bit integer variable by pointer. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be read. **/
|
|
|
|
/** @iItemIndex[in]: Index of list item index will be read. **/
|
2017-10-08 16:03:05 +00:00
|
|
|
/** @piValid[in]: Valid variable pointer. **/
|
|
|
|
/** @piDecimal[in]: Decimal variable pointer. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Return: None. **/
|
|
|
|
/** Notice: Variable pointer and decimal variable can be NULL. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
void SGUI_LIST_BindData(SGUI_LIST_STRUCT* pstList, SGUI_INDEX iItemIndex, SGUI_INT32* piValid, SGUI_INT32* piDecimal)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstSelectedListItem;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSelectedListItem = NULL;
|
2017-05-29 07:54:57 +00:00
|
|
|
if(NULL != pstList)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSelectedListItem = SGUI_LIST_GetListItemPtr(pstList, iItemIndex);
|
2017-07-31 13:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstSelectedListItem)
|
|
|
|
{
|
|
|
|
pstSelectedListItem->Valid.Bind = piValid;
|
|
|
|
pstSelectedListItem->Decimal.Bind = piDecimal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_GetListItemPtr **/
|
|
|
|
/** Purpose: Get list item data pointer by index. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be read. **/
|
|
|
|
/** @iItemIndex[in]: Index of list item index will be read. **/
|
2017-10-08 16:03:05 +00:00
|
|
|
/** Return: Selected list item data structure pointer. **/
|
2017-08-02 14:24:26 +00:00
|
|
|
/** Notice: Variable pointer and decimal variable can be NULL. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
SGUI_LIST_ITEM* SGUI_LIST_GetListItemPtr(SGUI_LIST_STRUCT* pstList, SGUI_INDEX iItemIndex)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstSelectedListItem;
|
2017-10-08 16:03:05 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_SIZE uiItemCounter;
|
2017-10-08 16:03:05 +00:00
|
|
|
#endif
|
2017-08-02 14:24:26 +00:00
|
|
|
|
2017-07-31 13:29:09 +00:00
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
pstSelectedListItem = NULL;
|
2017-10-08 16:03:05 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-08-02 14:24:26 +00:00
|
|
|
uiItemCounter = 0;
|
2017-10-08 16:03:05 +00:00
|
|
|
#endif
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
if(NULL != pstList)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
if(iItemIndex < pstList->Data.Count)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-10-08 16:03:05 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-07-31 13:29:09 +00:00
|
|
|
pstSelectedListItem = pstList->Data.Items;
|
|
|
|
if(NULL != pstSelectedListItem)
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
while((pstList->Data.Count > 0) && (NULL != pstSelectedListItem->NextItem) && (uiItemCounter < iItemIndex))
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
|
|
|
pstSelectedListItem = pstSelectedListItem->NextItem;
|
|
|
|
uiItemCounter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2017-10-08 16:03:05 +00:00
|
|
|
pstSelectedListItem = pstList->Data.Items+iItemIndex;
|
|
|
|
#endif
|
2017-07-31 13:29:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return pstSelectedListItem;
|
|
|
|
}
|
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_InsertItem **/
|
|
|
|
/** Purpose: Insert a new item to list. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be read. **/
|
|
|
|
/** @pstNewItem[in]: New item data pointer. **/
|
|
|
|
/** @iItemIndex[in]: Index of new list item. **/
|
|
|
|
/** Return: **/
|
|
|
|
/** @TRUE Insert success. **/
|
|
|
|
/** @FALSE Insert failed. **/
|
|
|
|
/** Notice: This function only supported when the dynamic list **/
|
|
|
|
/** item enabled, and new item index cannot greater **/
|
|
|
|
/** then list item count. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
SGUI_BOOL SGUI_LIST_InsertItem(SGUI_LIST_STRUCT* pstList, SGUI_LIST_ITEM* pstNewItem, SGUI_INDEX iNewItemIndex)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstListItemDataSource;
|
|
|
|
SGUI_LIST_ITEM *pstNewListItem, *pstPosItem;
|
|
|
|
SGUI_LIST_DATA *pstListData;
|
|
|
|
SGUI_BOOL bResult;
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
pstListItemDataSource = pstNewItem;
|
|
|
|
pstNewListItem = NULL;
|
|
|
|
pstPosItem = NULL;
|
|
|
|
bResult = SGUI_TRUE;
|
|
|
|
pstListData = &(pstList->Data);
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
if(iNewItemIndex > pstList->Data.Count)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
bResult = SGUI_FALSE;
|
2017-07-31 13:29:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstNewListItem = (SGUI_LIST_ITEM*)SGUI_Common_Allocate(sizeof(SGUI_LIST_ITEM));
|
2017-07-31 13:29:09 +00:00
|
|
|
if(NULL != pstNewListItem)
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Common_MemoryCopy(pstNewListItem, pstListItemDataSource, sizeof(SGUI_LIST_ITEM));
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
if(0 == pstList->Data.Count)
|
|
|
|
{
|
|
|
|
pstNewListItem->NextItem = NULL;
|
|
|
|
pstNewListItem->PrevItem = NULL;
|
|
|
|
pstListData->Items = pstNewListItem;
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
else if(iNewItemIndex == pstList->Data.Count)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstPosItem = SGUI_LIST_GetListItemPtr(pstList, iNewItemIndex-1);
|
2017-07-31 13:29:09 +00:00
|
|
|
pstPosItem->NextItem = pstNewListItem;
|
|
|
|
pstNewListItem->PrevItem = pstPosItem;
|
|
|
|
pstNewListItem->NextItem = NULL;
|
|
|
|
}
|
|
|
|
else //if((uiNewItemIndex>0)&&(uiNewItemIndex<pstListData->Count))
|
|
|
|
{
|
2017-08-02 14:24:26 +00:00
|
|
|
pstPosItem = SGUI_LIST_GetListItemPtr(pstList, iNewItemIndex);
|
2017-07-31 13:29:09 +00:00
|
|
|
pstNewListItem->PrevItem = pstPosItem->PrevItem;
|
|
|
|
pstNewListItem->NextItem = pstPosItem;
|
|
|
|
if(NULL != pstPosItem->PrevItem)
|
|
|
|
{
|
|
|
|
pstPosItem->PrevItem->NextItem = pstNewListItem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Insert to list head, repointer the list head pointer.
|
|
|
|
pstListData->Items = pstNewListItem;
|
|
|
|
}
|
|
|
|
pstPosItem->PrevItem = pstNewListItem;
|
|
|
|
}
|
|
|
|
pstList->Data.Count++;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
|
|
|
}
|
2017-07-31 13:29:09 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
2017-08-02 14:24:26 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Function Name: SGUI_LIST_RemoveItem **/
|
|
|
|
/** Purpose: Remove a item from list. **/
|
|
|
|
/** Params: **/
|
|
|
|
/** @pstList[in]: Pointer of list will be read. **/
|
|
|
|
/** @uiItemIndex[in]: Index of list item will be removed. **/
|
|
|
|
/** Return: **/
|
|
|
|
/** @TRUE Remove success. **/
|
|
|
|
/** @FALSE Remove failed. **/
|
|
|
|
/** Notice: This function only supported when the dynamic list **/
|
|
|
|
/** item enabled, and index of removed item cannot **/
|
|
|
|
/** greater then list item count. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
SGUI_BOOL SGUI_LIST_RemoveItem(SGUI_LIST_STRUCT* pstList, SGUI_INDEX iItemIndex)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM *pstRemoveListItem;
|
|
|
|
SGUI_BOOL bResult;
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-08-02 14:24:26 +00:00
|
|
|
pstRemoveListItem = SGUI_LIST_GetListItemPtr(pstList, iItemIndex);
|
|
|
|
bResult = SGUI_TRUE;
|
2017-05-29 07:54:57 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-07-31 13:29:09 +00:00
|
|
|
if(NULL != pstRemoveListItem)
|
2017-05-29 07:54:57 +00:00
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
if(NULL != pstRemoveListItem->PrevItem)
|
|
|
|
{
|
|
|
|
pstRemoveListItem->PrevItem->NextItem = pstRemoveListItem->NextItem;
|
|
|
|
}
|
|
|
|
if(NULL != pstRemoveListItem->NextItem)
|
|
|
|
{
|
|
|
|
pstRemoveListItem->NextItem->PrevItem = pstRemoveListItem->PrevItem;
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
if(0 == iItemIndex)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
|
|
|
pstList->Data.Items = pstRemoveListItem->NextItem;
|
|
|
|
}
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_Common_Free(pstRemoveListItem);
|
2017-07-31 13:29:09 +00:00
|
|
|
pstList->Data.Count--;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
2017-07-31 13:29:09 +00:00
|
|
|
return bResult;
|
2017-05-29 07:54:57 +00:00
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
#endif
|