LISTWHEEL - Usage (Sample)
LISTWHEEL_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | LISTWHEEL_Usage.c |
This sample demonstrates the usage of a LISTWHEEL 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 : LISTWHEEL_Usage.c
Purpose : Sample that demonstrates the usage of LISTWHEEL widgets
in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Defines
*
**********************************************************************
*/
#define LINE_HEIGHT 20
#define Y_SIZE 110
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
static const char * _acText[] = {
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday",
"Sunday",
NULL
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
int NCode;
int Sel;
char acBuffer[64];
char acTemp[32];
static LISTWHEEL_Handle hListwheel;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Create listwheel widget
//
hListwheel = LISTWHEEL_CreateEx(10, 10, Y_SIZE, 100, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_LISTWHEEL0, _acText);
//
// Set snap position (position where the wheel stops)
//
LISTWHEEL_SetSnapPosition(hListwheel, (Y_SIZE - LINE_HEIGHT) / 2);
//
// Set some properties about the listwheel
//
LISTWHEEL_SetLineHeight(hListwheel, LINE_HEIGHT);
LISTWHEEL_SetTextAlign(hListwheel, GUI_TA_CENTER);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
//
// Draw currently selected day
//
Sel = LISTWHEEL_GetSel(hListwheel);
LISTWHEEL_GetItemText(hListwheel, Sel, acTemp, sizeof(acTemp));
sprintf(acBuffer, "Selected item: %s", acTemp);
GUI_DispStringAt(acBuffer, 150, 10);
break;
case WM_NOTIFY_PARENT:
NCode = pMsg->Data.v;
switch (NCode) {
case WM_NOTIFICATION_SEL_CHANGED:
//
// Get current selection
//
Sel = LISTWHEEL_GetPos(hListwheel);
LISTWHEEL_SetSel(hListwheel, Sel);
break;
}
WM_InvalidateWindow(pMsg->hWin);
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init GUI
//
GUI_Init();
//
// Enable multi-buffering
//
WM_MULTIBUF_Enable(1);
//
// Create a window
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/