Difference between revisions of "LISTVIEW - Custom (Sample)"
(Created page with "{| class="wikitable" style="float:right; margin-left: 10px; background-color: #f9f9f9;" ! colspan="2" style="font-weight:bold; font-size:17px; font-family:Arial, Helvetica, sa...") |
|||
Line 20: | Line 20: | ||
This sample demonstrates custom drawing of a LISTVIEW widget. |
This sample demonstrates custom drawing of a LISTVIEW widget. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/LISTVIEW_Custom/LISTVIEW_Custom.html" width="480" height="272" style="border: 1px #c0c0c0 solid;" marginwidth="0" marginheight="0" hspace="0" vspace="0" scrolling="no"> </iframe></html> |
||
== Code == |
== Code == |
Revision as of 16:24, 7 March 2022
LISTVIEW_Custom.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | LISTVIEW_Custom.c |
This sample demonstrates custom drawing of a LISTVIEW widget.
Demo
Code
/*********************************************************************
* SEGGER Microcontroller GmbH *
* Solutions for real time microcontroller applications *
**********************************************************************
* *
* (c) 1996 - 2020 SEGGER Microcontroller GmbH *
* *
* Internet: www.segger.com Support: support@segger.com *
* *
**********************************************************************
** emWin V6.10 - Graphical user interface for embedded applications **
emWin is protected by international copyright laws. Knowledge of the
source code may not be used to write a similar product. This file may
only be used in accordance with a license and should not be re-
distributed in any way. We appreciate your understanding and fairness.
----------------------------------------------------------------------
File : LISTVIEW_Custom.c
Purpose : Sample that demonstrates how to give LISTVIEW widgets
in emWin a custom look.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const char * _acContent[][4] = {
{ "1002", "Murphy", "Diane", "President", },
{ "1056", "Patterson", "Mary", "VP Sales", },
{ "1076", "Firrelli", "Jeff", "VP Marketing", },
{ "1088", "Patterson", "William", "Sales Manager (APAC)", },
{ "1102", "Bondur", "Gerard", "Sale Manager (EMEA)", },
{ "1143", "Bow", "Anthony", "Sales Manager (NA)", },
{ "1165", "Jennings", "Leslie", "Sales Rep", },
{ "1166", "Thompson", "Leslie", "Sales Rep", },
{ "1188", "Firrelli", "Julie", "Sales Rep", },
{ "1216", "Patterson", "Steve", "Sales Rep", },
{ "1286", "Tseng", "Foon Yue", "Sales Rep", },
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
static int _OwnerDrawListview(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
char acBuffer[64];
int Sel;
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_GET_XSIZE:
//
// Return x-size of item
//
return LISTVIEW_OwnerDraw(pDrawItemInfo);
case WIDGET_ITEM_GET_YSIZE:
//
// Return y-size of item
//
return LISTVIEW_OwnerDraw(pDrawItemInfo);
case WIDGET_ITEM_DRAW:
//
// Draw item / row
//
GUI_SetTextMode(GUI_TM_TRANS);
LISTVIEW_GetItemText(pDrawItemInfo->hWin, pDrawItemInfo->Col, pDrawItemInfo->ItemIndex, acBuffer, sizeof(acBuffer));
Sel = LISTVIEW_GetSel(pDrawItemInfo->hWin);
if(Sel == pDrawItemInfo->ItemIndex) {
GUI_SetColor(GUI_WHITE);
} else {
GUI_SetColor(GUI_BLACK);
}
GUI_DispStringAt(acBuffer, pDrawItemInfo->x0, pDrawItemInfo->y0);
return 0;
case WIDGET_ITEM_DRAW_BACKGROUND:
GUI_SetColor(GUI_BLACK);
GUI_DrawHLine(pDrawItemInfo->y0, pDrawItemInfo->x0, pDrawItemInfo->x1);
//
// Draw item / row background
//
GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_GRAY_C8, GUI_GRAY_D0);
return 0;
default:
return LISTVIEW_OwnerDraw(pDrawItemInfo);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
LISTVIEW_Handle hListview;
int i;
//
// Init GUI
//
GUI_Init();
//
// Create listview widget
//
hListview = LISTVIEW_CreateEx(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_LISTVIEW0);
//
// Add columns to listview
//
LISTVIEW_AddColumn(hListview, 45, "Emp. Nr.", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 60, "Last Name", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 60, "First Name", GUI_TA_LEFT);
LISTVIEW_AddColumn(hListview, 110, "Title", GUI_TA_LEFT);
//
// Add rows to listview
//
for (i = 0; i < GUI_COUNTOF(_acContent); i++) {
LISTVIEW_AddRow(hListview, _acContent[i]);
}
//
// Enable scrollbar if needed
//
LISTVIEW_SetAutoScrollH(hListview, 1);
LISTVIEW_SetAutoScrollV(hListview, 1);
//
// Set OwnerDraw function
//
LISTVIEW_SetOwnerDraw(hListview, _OwnerDrawListview);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/