Add spacers to keep frequency display a fixed width
This commit is contained in:
parent
6313aa5adc
commit
6ddd46a853
17
nano_gui.cpp
17
nano_gui.cpp
@ -11,7 +11,8 @@ struct Point ts_point;
|
||||
/*
|
||||
* This formats the frequency given in f
|
||||
*/
|
||||
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
|
||||
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width)
|
||||
{
|
||||
memset(buff, 0, buff_size);
|
||||
|
||||
ultoa(freq, buff, DEC);
|
||||
@ -20,10 +21,20 @@ void formatFreq(uint32_t freq, char* buff, uint16_t buff_size) {
|
||||
const uint8_t num_leading_digits_raw = num_digits % 3;
|
||||
const uint8_t num_leading_digits = (0 == num_leading_digits_raw) ? 3 : num_leading_digits_raw;
|
||||
|
||||
if(0 == num_spacers){
|
||||
return;
|
||||
if(0 < fixed_width){
|
||||
while(0 < fixed_width - num_digits - num_spacers){
|
||||
if(0 == fixed_width % 4){
|
||||
buff[0] = '\x81';//separator size
|
||||
}
|
||||
else{
|
||||
buff[0] = '\x80';//digit size
|
||||
}
|
||||
--fixed_width;
|
||||
++buff;
|
||||
}
|
||||
}
|
||||
|
||||
ultoa(freq, buff, DEC);
|
||||
buff += num_leading_digits;
|
||||
num_digits -= num_leading_digits;
|
||||
for(int i = num_digits-1; i >= 0; --i){
|
||||
|
@ -17,7 +17,7 @@ void displayFillrect(unsigned int x,unsigned int y,unsigned int w,unsigned int h
|
||||
void displayChar(int16_t x, int16_t y, unsigned char c, uint16_t color, uint16_t bg);
|
||||
void displayText(char *text, int x1, int y1, int w, int h, int color, int background, int border);
|
||||
|
||||
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size);
|
||||
void formatFreq(uint32_t freq, char* buff, uint16_t buff_size, uint8_t fixed_width = 0);
|
||||
|
||||
/* touch functions */
|
||||
boolean readTouch();
|
||||
|
Loading…
Reference in New Issue
Block a user