Difference between revisions of "SWIPELIST - 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 SWIPELIST widget. |
This sample demonstrates custom drawing of a SWIPELIST widget. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/SWIPELIST_Custom/SWIPELIST_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 == |
Latest revision as of 16:33, 7 March 2022
SWIPELIST_Custom.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | SWIPELIST_Custom.c |
This sample demonstrates custom drawing of a SWIPELIST 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 : SWIPELIST_Custom.c
Purpose : Sample that demonstrates the usage of SWIPELIST widgets
in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
#include <stdlib.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define ITEM_SIZE 28
#define SEPARATOR_SIZE 36
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* Sample bitmap
*/
const GUI_COLOR ColorsSmilie1[] = {
#if GUI_USE_ARGB
0xFFFFFFFF,0xFF000000,0xFFFFFF00
#else
0xFFFFFF,0x000000,0x00FFFF
#endif
};
const GUI_LOGPALETTE PalSmilie1 = {
3, // number of entries
1, // Has transparency
&ColorsSmilie1[0]
};
const unsigned char acSmilie1[] = {
0x00, 0x55, 0x40, 0x00,
0x01, 0xAA, 0x90, 0x00,
0x06, 0xAA, 0xA4, 0x00,
0x19, 0x6A, 0x59, 0x00,
0x69, 0x6A, 0x5A, 0x40,
0x6A, 0xA6, 0xAA, 0x40,
0x6A, 0xA6, 0xAA, 0x40,
0x6A, 0xA6, 0xAA, 0x40,
0x6A, 0xAA, 0xAA, 0x40,
0x1A, 0x6A, 0x69, 0x00,
0x06, 0x95, 0xA4, 0x00,
0x01, 0xAA, 0x90, 0x00,
0x00, 0x55, 0x40, 0x00
};
const GUI_BITMAP bmSmilie1 = {
13, // XSize
13, // YSize
4, // BytesPerLine
2, // BitsPerPixel
acSmilie1, // Pointer to picture data (indices)
&PalSmilie1 // Pointer to palette
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
static int _OwnerDrawSwipelist(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
const GUI_BITMAP * pBM;
char acBuffer[64];
int NumTexts;
int i;
switch (pDrawItemInfo->Cmd) {
case WIDGET_ITEM_DRAW_BACKGROUND:
//
// Draw background of swipelist
//
GUI_SetColor(GUI_WHITE);
GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
GUI_SetColor(GUI_BLACK);
GUI_DrawHLine(pDrawItemInfo->y1, pDrawItemInfo->x0, pDrawItemInfo->x1);
return 0;
case WIDGET_ITEM_DRAW_TEXT:
//
// Display texts
//
GUI_SetColor(GUI_BLACK);
GUI_SetTextMode(GUI_TM_TRANS);
NumTexts = SWIPELIST_GetNumText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex);
for (i = 0; i < NumTexts; i++) {
if (i == 0) {
GUI_SetFont(&GUI_Font16_1);
} else {
GUI_SetFont(&GUI_Font13_1);
}
SWIPELIST_GetText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex, i, acBuffer, sizeof(acBuffer));
GUI_DispStringAt(acBuffer, pDrawItemInfo->x0, pDrawItemInfo->y0 + (i * 15));
}
return 0;
case WIDGET_ITEM_DRAW_BITMAP:
//
// Draw bitmap if item has a bitmap attached to it
//
pBM = SWIPELIST_GetBitmap(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex);
if (pBM) {
GUI_DrawBitmap(pBM, pDrawItemInfo->x0, pDrawItemInfo->y0);
}
return 0;
case WIDGET_ITEM_DRAW_SEP:
//
// Draw separator line
//
GUI_SetColor(GUI_BLACK);
GUI_DrawHLine(pDrawItemInfo->y0 - SEPARATOR_SIZE - 4, pDrawItemInfo->x0, pDrawItemInfo->x1);
return 0;
default:
return SWIPELIST_OwnerDraw(pDrawItemInfo);
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
SWIPELIST_Handle hList;
char acBuffer[32];
int i;
//
// Init GUI
//
GUI_Init();
//
// Enable multi-buffering
// (Necessary for swipelist widget)
//
WM_MULTIBUF_Enable(1);
//
// Create a swipelist widget
//
hList = SWIPELIST_CreateEx(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_SWIPELIST0);
//
// Add a separator as header
//
SWIPELIST_AddSepItem(hList, "Separator", SEPARATOR_SIZE);
//
// Add items to swipelist
//
for (i = 1; i <= 10; i++) {
sprintf(acBuffer, "Item %d", i);
SWIPELIST_AddItem(hList, acBuffer, ITEM_SIZE);
sprintf(acBuffer, "Item description #%d...", i);
SWIPELIST_AddItemText(hList, i, acBuffer); // i + 1 since we added a separator above
//
// Add another separator in between
//
if (i == 5) {
SWIPELIST_AddSepItem(hList, "Another separator", SEPARATOR_SIZE);
i++;
}
}
//
// One item shall also draw a bitmap
//
SWIPELIST_SetBitmap(hList, 3, SWIPELIST_BA_LEFT | SWIPELIST_BA_VCENTER, &bmSmilie1);
//
// Set OwnerDraw function
//
SWIPELIST_SetOwnerDraw(hList, _OwnerDrawSwipelist);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/