Difference between revisions of "SPINBOX - 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 SPINBOX widget.
 
This sample demonstrates the usage of a SPINBOX widget.
  +
  +
== Demo ==
  +
  +
<html><iframe src="https://wiki.segger.com/demo/emwin/SPINBOX_Usage/SPINBOX_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:33, 7 March 2022

SPINBOX_Usage.c
SPINBOX Usage.gif
File(s) required
  • SPINBOX_Usage.c
Runs in simulation Yes
Runs on target Yes
Download SPINBOX_Usage.c

This sample demonstrates the usage of a SPINBOX 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        : SPINBOX_Usage.c
Purpose     : Sample that demonstrates the usage of SPINBOX widgets
              in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"
#include <stdio.h>

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/
/*********************************************************************
*
*       _cbWin
*/
static void _cbWin(WM_MESSAGE * pMsg) {
  char                  acBuffer[32];
  int                   Value;
  static SPINBOX_Handle hSpinbox;
  int                   NCode, Id;

  switch (pMsg->MsgId) {
  case WM_CREATE:
    //
    // Create spinbox widget
    //
    hSpinbox = SPINBOX_CreateEx(10, 10, 80, 30, pMsg->hWin, WM_CF_SHOW, GUI_ID_SPINBOX0, 0, 100);
    //
    // Manually edit the range
    //
    SPINBOX_SetRange(hSpinbox, -100, 100);
    //
    // Set step if required
    //
    SPINBOX_SetStep(hSpinbox, 2);
    //
    // Change appearance if wanted
    //
    SPINBOX_SetFont(hSpinbox, &GUI_Font13B_1);
    SPINBOX_SetTextColor(hSpinbox, SPINBOX_CI_ENABLED, GUI_RED);
    SPINBOX_SetBkColor(hSpinbox, SPINBOX_CI_ENABLED, GUI_GRAY_AA);
    break;
  case WM_PAINT:
    GUI_SetBkColor(GUI_BLACK);
    GUI_Clear();
    //
    // Display current value
    //
    Value = SPINBOX_GetValue(hSpinbox);
    sprintf(acBuffer, "The current value is: %d", Value);
    GUI_DispStringAt(acBuffer, 10, 50);
    break;
  case WM_NOTIFY_PARENT:
    Id    = WM_GetId(pMsg->hWinSrc);
    NCode = pMsg->Data.v;
    switch(Id) {
    case GUI_ID_SPINBOX0:
      switch (NCode) {
      case WM_NOTIFICATION_VALUE_CHANGED:
        //
        // Invalidate window once the value of the SPINBOX has changed.
        //
        WM_InvalidateWindow(pMsg->hWin);
        break;
      }
      break;
    }
    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 ****************************/