discoverpixy
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions
numupdown.c File Reference
#include "tft.h"
#include "touch.h"
#include "button.h"
#include "numupdown.h"
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
Include dependency graph for numupdown.c:

Go to the source code of this file.

Macros

#define BASE_COLOR   RGB(90,90,90)
 

Functions

void button_up_cb (void *button)
 
void button_down_cb (void *button)
 
static uint8_t calc_text_width (int16_t val)
 
bool gui_numupdown_add (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_remove (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_redraw (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_update (NUMUPDOWN_STRUCT *numupdown)
 

Macro Definition Documentation

#define BASE_COLOR   RGB(90,90,90)

Definition at line 31 of file numupdown.c.

Function Documentation

void button_down_cb ( void *  button)

Definition at line 50 of file numupdown.c.

51 {
52  //Get the pointer to the numupdown: subtract the offset of the buttonDown member in the struct from the button pointer
53  NUMUPDOWN_STRUCT* element = button - offsetof(NUMUPDOWN_STRUCT, buttonDown);
54 
55  if (element->value > element->min) { //old value lies above the minimum
56  element->value--; //let's decrease the value
57  gui_numupdown_update(element); //and redraw everything
58 
59  if (element->callback != NULL) { //the user provided a callback
60  element->callback(element, element->value); //Call the user callback with the new value
61  }
62  }
63 }
NUMUPDOWN_CALLBACK callback
Callback which is executed when the value changes.
Definition: numupdown.h:55
int16_t min
The minimum possible value (inclusive)
Definition: numupdown.h:53
void gui_numupdown_update(NUMUPDOWN_STRUCT *numupdown)
Definition: numupdown.c:154
int16_t value
The current/default value.
Definition: numupdown.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

void button_up_cb ( void *  button)

Definition at line 34 of file numupdown.c.

35 {
36  //Get the pointer to the numupdown: subtract the offset of the buttonUp member in the struct from the button pointer
37  NUMUPDOWN_STRUCT* element = button - offsetof(NUMUPDOWN_STRUCT, buttonUp);
38 
39  if (element->value < element->max) { //old value lies below the maximum
40  element->value++; //let's increase the value
41  gui_numupdown_update(element); //and redraw everything
42 
43  if (element->callback != NULL) { //the user provided a callback
44  element->callback(element, element->value); //Call the user callback with the new value
45  }
46  }
47 }
NUMUPDOWN_CALLBACK callback
Callback which is executed when the value changes.
Definition: numupdown.h:55
int16_t max
The maximum possible value (inclusive)
Definition: numupdown.h:54
void gui_numupdown_update(NUMUPDOWN_STRUCT *numupdown)
Definition: numupdown.c:154
int16_t value
The current/default value.
Definition: numupdown.h:52

Here is the call graph for this function:

Here is the caller graph for this function:

static uint8_t calc_text_width ( int16_t  val)
static

Definition at line 66 of file numupdown.c.

67 {
68  uint8_t width = 1 + (val < 0); //1 if positive, 2 if negative (to let space for sign)
69  val = abs(val); //Make the number positive
70 
71  while (val >= 10) { //while we have two or more digits
72  val /= 10; //remove one digit
73  width++; //add one character
74  }
75 
76  return width;
77 }
uint16_t width
Definition: pixy.h:82

Here is the caller graph for this function: