discoverpixy
Data Structures | Typedefs | Functions
NummericUpDown
Collaboration diagram for NummericUpDown:

Data Structures

struct  NUMUPDOWN_STRUCT
 

Typedefs

typedef void(* NUMUPDOWN_CALLBACK) (void *numupdown, int16_t value)
 

Functions

bool gui_numupdown_add (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_remove (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_update (NUMUPDOWN_STRUCT *numupdown)
 
void gui_numupdown_redraw (NUMUPDOWN_STRUCT *numupdown)
 

Detailed Description

The NummericUpDown Gui Element

Typedef Documentation

typedef void(* NUMUPDOWN_CALLBACK) (void *numupdown, int16_t value)

Prototype for Event Listeners (called when the NummericUpDown value has changed)

Note
You should NOT execute long running things in this callback nor should you update the gui. But you can call gui_screen_navigate() for instance.
Parameters
numupdownThe pointer to the NUMUPDOWN_STRUCT where to corresponding NummericUpDown has changed it's value
valueThe new value of the NummericUpDown

Definition at line 43 of file numupdown.h.

Function Documentation

bool gui_numupdown_add ( NUMUPDOWN_STRUCT numupdown)

Adds a NummericUpDown. Your Callback will be called from now on, if the numupdown's value changes

Parameters
numupdownA Pointer to the preinitialized NUMUPDOWN_STRUCT
Returns
true on success

Definition at line 80 of file numupdown.c.

81 {
82  if (touch_have_empty(2)) { //Check if the touch module can handle two additional areas
83  if (numupdown->min > numupdown->max) { //min is bigger than max?
84  return false; //invalid parameter
85  }
86 
87  if (numupdown->value < numupdown->min) { //value is smaller than min?
88  numupdown->value = numupdown->min; //normalize value
89  } else if (numupdown->value > numupdown->max) { //value is bigger than max?
90  numupdown->value = numupdown->max; //normalize value
91  }
92 
93  uint8_t tw1 = calc_text_width(numupdown->max); //Calculate character width to render maximum value
94  uint8_t tw2 = calc_text_width(numupdown->min); //Calculate character width to render minimum value
95 
96  if (tw2 > tw1) {
97  tw1 = tw2; //ensure tw1 contains the larger number of the two
98  }
99 
100  uint8_t width = tft_font_width(0) * (tw1 + 1); //Calculate width of the number area
101 
102  //Add "minus" button to the left side of the number area
103  numupdown->buttonDown.base.x1 = numupdown->x;
104  numupdown->buttonDown.base.y1 = numupdown->y;
105  numupdown->buttonDown.base.x2 = AUTO;
106  numupdown->buttonDown.base.y2 = numupdown->y + tft_font_height(0) * 2;
107  numupdown->buttonDown.text = "-";
108  numupdown->buttonDown.font = 0;
109  numupdown->buttonDown.bgcolor = BASE_COLOR;
110  numupdown->buttonDown.txtcolor = WHITE;
111  numupdown->buttonDown.callback = button_down_cb;
112  gui_button_add(&numupdown->buttonDown);
113 
114  //Add "plus" button to the right side of the number area
115  numupdown->buttonUp.base.x1 = numupdown->buttonDown.base.x2 + width + 2;
116  numupdown->buttonUp.base.y1 = numupdown->y;
117  numupdown->buttonUp.base.x2 = AUTO;
118  numupdown->buttonUp.base.y2 = numupdown->y + tft_font_height(0) * 2;
119  numupdown->buttonUp.text = "+";
120  numupdown->buttonUp.font = 0;
121  numupdown->buttonUp.bgcolor = BASE_COLOR;
122  numupdown->buttonUp.txtcolor = WHITE;
123  numupdown->buttonUp.callback = button_up_cb;
124  gui_button_add(&numupdown->buttonUp);
125 
126  //Draw background and label of the number area
127  tft_fill_rectangle(numupdown->buttonDown.base.x2 + 2, numupdown->y, numupdown->buttonDown.base.x2 + width, numupdown->buttonUp.base.y2, BASE_COLOR);
128  tft_print_formatted(numupdown->buttonDown.base.x2 + 2 + tft_font_width(0) / 2, numupdown->y + tft_font_height(0) / 2, numupdown->fgcolor, BASE_COLOR, 0, "%*d", tw1, numupdown->value);
129 
130  return true;
131  }
132 
133  return false; //not enough touch areas left
134 }
uint8_t tft_font_height(uint8_t fontnum)
Definition: tft.c:87
const char * text
The label of the button.
Definition: button.h:61
uint8_t tft_font_width(uint8_t fontnum)
Definition: tft.c:92
uint16_t txtcolor
The 16-bit text color.
Definition: button.h:59
#define AUTO
Use this value instead of x2, y2 in the BUTTON_STRUCT to autocalculate the button width/height...
Definition: button.h:65
uint16_t x
The x-Coordinate of the Top-Left Starting Point.
Definition: numupdown.h:49
uint16_t y1
Top Left Y-Coordinate of Area.
Definition: touch.h:75
void tft_print_formatted(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *format,...)
Definition: tft.c:111
bool gui_button_add(BUTTON_STRUCT *button)
Definition: button.c:133
uint16_t x1
Top Left X-Coordinate of Area.
Definition: touch.h:74
uint16_t bgcolor
The 16-bit background color of the button.
Definition: button.h:57
TOUCH_AREA_STRUCT base
Basic geometry of the button. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: button.h:56
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
void button_down_cb(void *button)
Definition: numupdown.c:50
static uint8_t calc_text_width(int16_t val)
Definition: numupdown.c:66
uint16_t y
The y-Coordinate of the Top-Left Starting Point.
Definition: numupdown.h:50
int16_t max
The maximum possible value (inclusive)
Definition: numupdown.h:54
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
int16_t min
The minimum possible value (inclusive)
Definition: numupdown.h:53
#define WHITE
Definition: tft.h:53
void tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:67
uint16_t width
Definition: pixy.h:82
uint16_t fgcolor
The 16-bit color of the value-text.
Definition: numupdown.h:51
BUTTON_STRUCT buttonDown
For internal use, don't change, don't initialize.
Definition: numupdown.h:58
void button_up_cb(void *button)
Definition: numupdown.c:34
int16_t value
The current/default value.
Definition: numupdown.h:52
BUTTON_CALLBACK callback
Callback which is executed when the button is pressed.
Definition: button.h:58
bool touch_have_empty(unsigned char num)
Definition: touch.c:165
uint8_t font
The number of the font to use.
Definition: button.h:60
#define BASE_COLOR
Definition: numupdown.c:31
BUTTON_STRUCT buttonUp
For internal use, don't change, don't initialize.
Definition: numupdown.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

void gui_numupdown_redraw ( NUMUPDOWN_STRUCT numupdown)

Redraws the NummericUpDown. Call this method if you have to redraw the entire screen or if you want to draw a numupdown on top of an image.

Parameters
numupdownA Pointer to the NUMUPDOWN_STRUCT

Definition at line 144 of file numupdown.c.

145 {
146  //redraw the two buttons
147  gui_button_redraw(&numupdown->buttonUp);
148  gui_button_redraw(&numupdown->buttonDown);
149 
150  //call update method which will take care of the number-area rendering
151  gui_numupdown_update(numupdown);
152 }
void gui_button_redraw(BUTTON_STRUCT *button)
Definition: button.c:164
BUTTON_STRUCT buttonDown
For internal use, don't change, don't initialize.
Definition: numupdown.h:58
void gui_numupdown_update(NUMUPDOWN_STRUCT *numupdown)
Definition: numupdown.c:154
BUTTON_STRUCT buttonUp
For internal use, don't change, don't initialize.
Definition: numupdown.h:57

Here is the call graph for this function:

void gui_numupdown_remove ( NUMUPDOWN_STRUCT numupdown)

Removes the NummericUpDown. You will no longer receive events for this numupdown. This function will not overdraw the region where the numupdown was located.

Parameters
numupdownA Pointer to the NUMUPDOWN_STRUCT

Definition at line 136 of file numupdown.c.

137 {
138  //remove the two buttons, we have no other allocated resources
139  gui_button_remove(&numupdown->buttonUp);
140  gui_button_remove(&numupdown->buttonDown);
141 }
void gui_button_remove(BUTTON_STRUCT *button)
Definition: button.c:184
BUTTON_STRUCT buttonDown
For internal use, don't change, don't initialize.
Definition: numupdown.h:58
BUTTON_STRUCT buttonUp
For internal use, don't change, don't initialize.
Definition: numupdown.h:57

Here is the call graph for this function:

Here is the caller graph for this function:

void gui_numupdown_update ( NUMUPDOWN_STRUCT numupdown)

Updates the NummericUpDown. Call this function when you change the value/min/max of the numupdown through code.

Parameters
numupdownA Pointer to the NUMUPDOWN_STRUCT

Definition at line 154 of file numupdown.c.

155 {
156  //Calculate the number area width again (see above)
157  uint8_t tw1 = calc_text_width(numupdown->max);
158  uint8_t tw2 = calc_text_width(numupdown->min);
159 
160  if (tw2 > tw1) {
161  tw1 = tw2;
162  }
163 
164  uint8_t width = tft_font_width(0) * (tw1 + 1);
165 
166  //Draw background and label of the number area
167  tft_fill_rectangle(numupdown->buttonDown.base.x2 + 2, numupdown->y, numupdown->buttonDown.base.x2 + width, numupdown->buttonUp.base.y2, BASE_COLOR);
168  tft_print_formatted(numupdown->buttonDown.base.x2 + 2 + tft_font_width(0) / 2, numupdown->y + tft_font_height(0) / 2, numupdown->fgcolor, BASE_COLOR, 0, "%*d", tw1, numupdown->value);
169 }
uint8_t tft_font_height(uint8_t fontnum)
Definition: tft.c:87
uint8_t tft_font_width(uint8_t fontnum)
Definition: tft.c:92
void tft_print_formatted(uint16_t x, uint16_t y, uint16_t color, uint16_t bgcolor, uint8_t font, const char *format,...)
Definition: tft.c:111
TOUCH_AREA_STRUCT base
Basic geometry of the button. You only need to set the x1, y1, x2, y2 members of this struct...
Definition: button.h:56
uint16_t y2
Bottom Right Y-Coordinate of Area.
Definition: touch.h:77
static uint8_t calc_text_width(int16_t val)
Definition: numupdown.c:66
uint16_t y
The y-Coordinate of the Top-Left Starting Point.
Definition: numupdown.h:50
int16_t max
The maximum possible value (inclusive)
Definition: numupdown.h:54
uint16_t x2
Bottom Right X-Coordinate of Area.
Definition: touch.h:76
int16_t min
The minimum possible value (inclusive)
Definition: numupdown.h:53
void tft_fill_rectangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
Definition: tft.c:67
uint16_t width
Definition: pixy.h:82
uint16_t fgcolor
The 16-bit color of the value-text.
Definition: numupdown.h:51
BUTTON_STRUCT buttonDown
For internal use, don't change, don't initialize.
Definition: numupdown.h:58
int16_t value
The current/default value.
Definition: numupdown.h:52
#define BASE_COLOR
Definition: numupdown.c:31
BUTTON_STRUCT buttonUp
For internal use, don't change, don't initialize.
Definition: numupdown.h:57

Here is the call graph for this function:

Here is the caller graph for this function: