Difference between revisions of "DROPDOWN - Usage (Sample)"
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{| class="wikitable" style="float:right; margin-left: 10px; background-color: #f9f9f9;" |
{| class="wikitable" style="float:right; margin-left: 10px; background-color: #f9f9f9;" |
||
− | ! colspan="2" style="font-weight:bold; font-size:17px; font-family:Arial, Helvetica, sans-serif !important;; background-color:#ceceff;" | |
+ | ! colspan="2" style="font-weight:bold; font-size:17px; font-family:Arial, Helvetica, sans-serif !important;; background-color:#ceceff;" | DROPDOWN_Usage.c |
|- |
|- |
||
| colspan="2" | [[File:DROPDOWN Usage.gif | frame ]] |
| colspan="2" | [[File:DROPDOWN Usage.gif | frame ]] |
||
Line 16: | Line 16: | ||
|- |
|- |
||
| style="font-weight:bold; font-size:12px; font-family:Arial, Helvetica, sans-serif !important;;" | Download |
| style="font-weight:bold; font-size:12px; font-family:Arial, Helvetica, sans-serif !important;;" | Download |
||
− | | style="font-size:12px; font-family:Arial, Helvetica, sans-serif !important;;" | [https://wiki.segger.com/images/ |
+ | | style="font-size:12px; font-family:Arial, Helvetica, sans-serif !important;;" | [https://wiki.segger.com/images/d/df/DROPDOWN_Usage.c DROPDOWN_Usage.c] |
|} |
|} |
||
This sample demonstrates the usage of a DROPDOWN widget. |
This sample demonstrates the usage of a DROPDOWN widget. |
||
+ | |||
+ | == Demo == |
||
+ | |||
+ | <html><iframe src="https://wiki.segger.com/demo/emwin/DROPDOWN_Usage/DROPDOWN_Usage.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:19, 7 March 2022
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.
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 : 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 ****************************/