Difference between revisions of "LISTWHEEL - Usage (Sample)"

From SEGGER Wiki
Jump to: navigation, search
(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 the usage of a LISTWHEEL widget.
 
This sample demonstrates the usage of a LISTWHEEL widget.
  +
  +
== Demo ==
  +
  +
<html><iframe src="https://wiki.segger.com/demo/emwin/LISTWHEEL_Usage/LISTWHEEL_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:28, 7 March 2022

LISTWHEEL_Usage.c
LISTWHEEL Usage.png
File(s) required
  • LISTWHEEL_Usage.c
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 ****************************/