Difference between revisions of "SLIDER - Custom (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 custom drawing of a SLIDER widget.
 
This sample demonstrates custom drawing of a SLIDER widget.
  +
  +
== Demo ==
  +
  +
<html><iframe src="https://wiki.segger.com/demo/emwin/SLIDER_Custom/SLIDER_Custom.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:31, 7 March 2022

SLIDER_Custom.c
SLIDER Custom.png
File(s) required
  • SLIDER_Custom.c
Runs in simulation Yes
Runs on target Yes
Download SLIDER_Custom.c

This sample demonstrates custom drawing of a SLIDER 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        : SLIDER_Custom.c
Purpose     : Sample that demonstrates how to give a custom look to a
              SLIDER widget in emWin.
Requirements: WindowManager - (x)
              MemoryDevices - ( )
              AntiAliasing  - ( )
              VNC-Server    - ( )
              PNG-Library   - ( )
              TrueTypeFonts - ( )
---------------------------END-OF-HEADER------------------------------
*/

#include "DIALOG.h"

/*********************************************************************
*
*       Defines
*
**********************************************************************
*/

/*********************************************************************
*
*       Static data
*
**********************************************************************
*/
/*********************************************************************
*
*       _PropsUnpressed: Properties for slider in unpressed state.
*/
static const SLIDER_SKINFLEX_PROPS _PropsUnpressed = {
  { GUI_LIGHTRED, GUI_GRAY_9A },                   // [0] Outer frame color, [1] Inner frame color
  { GUI_WHITE, GUI_LIGHTBLUE },                    // [0] Top color of gradient, [1] Bottom color of gradient
  { GUI_BLACK, GUI_GRAY_60, GUI_GRAY_AA },         // [0] First frame color of shaft, [1] Second frame color of shaft, [2] Inner color of shaft
  GUI_BLACK,                                       // Color of tick marks.
  GUI_GRAY_3F,                                     // Color of focus rectangle.
  4,                                               // Size of tick marks.
  3                                                // Size of shaft.
};

/*********************************************************************
*
*       _PropsPressed: Properties for slider in pressed state.
*/
static const SLIDER_SKINFLEX_PROPS _PropsPressed = {
  { GUI_RED, GUI_GRAY_9A },                        // [0] Outer frame color, [1] Inner frame color
  { GUI_GRAY_7C, GUI_LIGHTBLUE },                  // [0] Top color of gradient, [1] Bottom color of gradient
  { GUI_BLACK, GUI_GRAY_60, GUI_GRAY_AA },         // [0] First frame color of shaft, [1] Second frame color of shaft, [2] Inner color of shaft
  GUI_BLACK,                                       // Color of tick marks.
  GUI_GRAY_3F,                                     // Color of focus rectangle.
  4,                                               // Size of tick marks.
  3                                                // Size of shaft.
};

/*********************************************************************
*
*       Static code
*
**********************************************************************
*/

/*********************************************************************
*
*       Public code
*
**********************************************************************
*/
/*********************************************************************
*
*       MainTask
*/
void MainTask(void) {
  //
  // Init emWin.
  //
  GUI_Init();
  //
  // Set desktop color, so the background will be redrawn when the slider is moved.
  //
  WM_SetDesktopColor(GUI_WHITE);
  //
  // Multi-buffering assures flicker-free movement of the slider's thumb.
  //
  WM_MULTIBUF_Enable(1);
  //
  // Create slider
  //
  SLIDER_CreateEx(10, 10, 150, 30, WM_HBKWIN, WM_CF_SHOW, SLIDER_CF_HORIZONTAL, GUI_ID_SLIDER0);
  //
  // Set slider properties for different states.
  //
  SLIDER_SetSkinFlexProps(&_PropsUnpressed, SLIDER_SKINFLEX_PI_UNPRESSED);
  SLIDER_SetSkinFlexProps(&_PropsPressed, SLIDER_SKINFLEX_PI_PRESSED);

  while (1) {
    GUI_Delay(100);
  }
}

/*************************** End of file ****************************/