DROPDOWN - Usage (Sample)
DROPDOWN_Usage.c | |
---|---|
File(s) required |
|
Runs in simulation | Yes |
Runs on target | Yes |
Download | DROPDOWN_Usage.c |
This sample demonstrates the usage of a DROPDOWN widget.
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 : DROPDOWN_Usage.c
Purpose : Sample that demonstrates the usage of DROPDOWN widgets
in emWin.
Requirements: WindowManager - (x)
MemoryDevices - ( )
AntiAliasing - ( )
VNC-Server - ( )
PNG-Library - ( )
TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/
#include "DIALOG.h"
#include <stdio.h>
/*********************************************************************
*
* Static data
*
**********************************************************************
*/
/*********************************************************************
*
* _acContent
*/
static const char * _acContent[] = {
"English",
"Deutsch",
"Espanol",
"Francais",
"Italiano",
"Dansk",
"Eesti",
"Hrvatski",
"Portugues",
"Suomi"
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
/*********************************************************************
*
* _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
char acBuffer[128];
int Sel;
static DROPDOWN_Handle hDropdown;
int i;
int NCode, Id;
int NumItems;
switch (pMsg->MsgId) {
case WM_CREATE:
//
// Create listbox widget
// The flag DROPDOWN_CF_AUTOSCROLLBAR makes sure that a scrollbar is added, if the text is too big
//
hDropdown = DROPDOWN_CreateEx(10, 10, 200, 150, pMsg->hWin, WM_CF_SHOW, DROPDOWN_CF_AUTOSCROLLBAR, GUI_ID_DROPDOWN0);
//
// Add items to widget
//
for (i = 0; i < GUI_COUNTOF(_acContent); i++) {
DROPDOWN_AddString(hDropdown, *(_acContent + i));
}
//
// Edit some properties
//
DROPDOWN_SetFont(hDropdown, &GUI_Font20B_1);
DROPDOWN_SetItemSpacing(hDropdown, 5);
DROPDOWN_SetTextColor(hDropdown, DROPDOWN_CI_UNSEL, GUI_LIGHTRED);
break;
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
GUI_SetFont(&GUI_Font13B_1);
GUI_SetTextMode(GUI_TM_TRANS);
//
// Display current selection
//
Sel = DROPDOWN_GetSel(hDropdown);
sprintf(acBuffer, "Currently selected item (%d): %s", Sel, *(_acContent + Sel));
GUI_DispStringAt(acBuffer, 250, 10);
//
// Display number of items
//
NumItems = DROPDOWN_GetNumItems(hDropdown);
sprintf(acBuffer, "Number of items: %d", NumItems);
GUI_DispStringAt(acBuffer, 250, 30);
break;
case WM_NOTIFY_PARENT:
//
// Save ID of sender window and notification code
//
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case GUI_ID_DROPDOWN0:
switch(NCode) {
case WM_NOTIFICATION_SEL_CHANGED:
//
// Invalidate parent window when a new item has been selected to display the new selection.
//
WM_InvalidateWindow(pMsg->hWin);
break;
}
break;
}
break;
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* MainTask
*/
void MainTask(void) {
//
// Init GUI
//
GUI_Init();
//
// Create parent window
//
WM_CreateWindowAsChild(0, 0, LCD_GetXSize(), LCD_GetYSize(), WM_HBKWIN, WM_CF_SHOW, _cbWin, 0);
while (1) {
GUI_Delay(100);
}
}
/*************************** End of file ****************************/