Add custom button label

Use adaptive button size depend from count mode
Removed_REF_marker
DiSlord 5 years ago
parent 147612d9f7
commit 045d6f4000

41
ui.c

@ -64,7 +64,11 @@ static uint16_t last_button = 0b0000;
static uint32_t last_button_down_ticks; static uint32_t last_button_down_ticks;
static uint32_t last_button_repeat_ticks; static uint32_t last_button_repeat_ticks;
//static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); #define MENU_USE_AUTOHEIGHT
#ifdef MENU_USE_AUTOHEIGHT
static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN);
#endif
volatile uint8_t operation_requested = OP_NONE; volatile uint8_t operation_requested = OP_NONE;
int8_t previous_marker = MARKER_INVALID; int8_t previous_marker = MARKER_INVALID;
@ -641,6 +645,8 @@ enum {
//#define MT_LEAVE 0x20 //#define MT_LEAVE 0x20
#define MT_MASK(x) (0xF & (x)) #define MT_MASK(x) (0xF & (x))
#define MT_CUSTOM_LABEL 0
// Call back functions for MT_CALLBACK type // Call back functions for MT_CALLBACK type
typedef void (*menuaction_cb_t)(int item, uint16_t data); typedef void (*menuaction_cb_t)(int item, uint16_t data);
#define UI_FUNCTION_CALLBACK(ui_function_name) void ui_function_name(int item, uint16_t data) #define UI_FUNCTION_CALLBACK(ui_function_name) void ui_function_name(int item, uint16_t data)
@ -820,7 +826,9 @@ ensure_selection(void)
if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1; if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1;
if (i < MENU_BUTTON_MIN) i = MENU_BUTTON_MIN; if (i < MENU_BUTTON_MIN) i = MENU_BUTTON_MIN;
if (i >= MENU_BUTTON_MAX) i = MENU_BUTTON_MAX; if (i >= MENU_BUTTON_MAX) i = MENU_BUTTON_MAX;
// menu_button_height = MENU_BUTTON_HEIGHT_N(i); #ifdef MENU_USE_AUTOHEIGHT
menu_button_height = MENU_BUTTON_HEIGHT_N(i);
#endif
} }
static void static void
@ -1118,6 +1126,7 @@ static int
menu_is_multiline(const char *label) menu_is_multiline(const char *label)
{ {
int n = 1; int n = 1;
if (label)
while (*label) while (*label)
if (*label++ == '\n') if (*label++ == '\n')
n++; n++;
@ -1343,11 +1352,13 @@ static const uint8_t check_box[] = {
static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"}; static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"};
static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" }; static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" };
#ifdef TINYS4 #ifndef MENU_USE_AUTOHEIGHT
#ifdef TINYSA4
#define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/10 : LCD_HEIGHT/12 ) #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/10 : LCD_HEIGHT/12 )
#else #else
#define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/8 : LCD_HEIGHT/10 ) #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/8 : LCD_HEIGHT/10 )
#endif #endif
#endif
static void static void
draw_menu_buttons(const menuitem_t *menu, int only) draw_menu_buttons(const menuitem_t *menu, int only)
@ -1390,22 +1401,26 @@ draw_menu_buttons(const menuitem_t *menu, int only)
// Need replace this obsolete bad function on new MT_ADV_CALLBACK variant // Need replace this obsolete bad function on new MT_ADV_CALLBACK variant
menu_item_modify_attribute(menu, i, &button); // before plot_printf to create status text menu_item_modify_attribute(menu, i, &button); // before plot_printf to create status text
char *text;
// MT_ADV_CALLBACK - allow change button data in callback, more easy and correct // MT_ADV_CALLBACK - allow change button data in callback, more easy and correct
if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK){ if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK){
menuaction_acb_t cb = (menuaction_acb_t)menu[i].reference; menuaction_acb_t cb = (menuaction_acb_t)menu[i].reference;
if (cb) (*cb)(i, menu[i].data, &button); if (cb) (*cb)(i, menu[i].data, &button);
// Apply custom text, from button label and
if (menu[i].label != MT_CUSTOM_LABEL)
plot_printf(button.text, sizeof(button.text), menu[i].label, button.param_1.u);
text = button.text;
} }
else
text = menu[i].label;
// Only keypad retrieves value // Only keypad retrieves value
if (menu[i].type & MT_FORM && MT_MASK(menu[i].type) == MT_KEYPAD) { if (menu[i].type & MT_FORM && MT_MASK(menu[i].type) == MT_KEYPAD) {
keypad_mode = menu[i].data; keypad_mode = menu[i].data;
fetch_numeric_target(); fetch_numeric_target();
button.param_1.text = uistat.text; plot_printf(button.text, sizeof button.text, menu[i].label, uistat.text);
text = button.text;
} }
// Prepare button label
plot_printf(button.text, sizeof button.text, menu[i].label, button.param_1.u, button.param_2.u);
if (menu[i].type & MT_FORM) { if (menu[i].type & MT_FORM) {
int button_width = MENU_FORM_WIDTH; int button_width = MENU_FORM_WIDTH;
int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen
@ -1454,8 +1469,8 @@ draw_menu_buttons(const menuitem_t *menu, int only)
goto draw_slider; goto draw_slider;
} }
} }
// ili9341_drawstring_size(button.text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); // ili9341_drawstring_size(text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2);
ili9341_drawstring_10x14(button.text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); ili9341_drawstring_10x14(text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift);
} else { } else {
int button_width = MENU_BUTTON_WIDTH; int button_width = MENU_BUTTON_WIDTH;
int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH;
@ -1466,12 +1481,12 @@ draw_menu_buttons(const menuitem_t *menu, int only)
ili9341_blitBitmap(button_start+2, y+(button_height-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); ili9341_blitBitmap(button_start+2, y+(button_height-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]);
text_offs = button_start+2+ICON_WIDTH; text_offs = button_start+2+ICON_WIDTH;
} }
int lines = menu_is_multiline(button.text); int lines = menu_is_multiline(text);
#define BIG_BUTTON_FONT 1 #define BIG_BUTTON_FONT 1
#ifdef BIG_BUTTON_FONT #ifdef BIG_BUTTON_FONT
ili9341_drawstring_7x13(button.text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2); ili9341_drawstring_7x13(text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2);
#else #else
ili9341_drawstring(button.text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); ili9341_drawstring(text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2);
#endif #endif
} }
y += menu_button_height; y += menu_button_height;

@ -747,12 +747,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb)
(void)item; (void)item;
if(b){ if(b){
setting_t *p = caldata_pointer(data); setting_t *p = caldata_pointer(data);
char *t = (char *)spi_buffer;
if (p) if (p)
plot_printf(t, 64, "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1);//\n%d-drstx8 plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1);
else else
plot_printf(t, 64, "EMPTY %d", (int)data); plot_printf(b->text, sizeof(b->text), "EMPTY %d", (int)data);
b->param_1.text = t;
return; return;
} }
if (caldata_recall(data) == -1) { if (caldata_recall(data) == -1) {
@ -923,10 +921,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){
(void)data; (void)data;
if(b){ if(b){
if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL) if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL)
b->param_1.text = menu_modulation_text[setting.modulation]; plot_printf(b->text, sizeof b->text, "MOD: %s", menu_modulation_text[setting.modulation]);
else { else {
plot_printf(uistat.text, sizeof uistat.text, "%5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); plot_printf(b->text, sizeof b->text, "MOD: %5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]);
b->param_1.text = uistat.text;
} }
return; return;
} }
@ -1970,11 +1967,11 @@ static const menuitem_t menu_store_preset_high[8] =
static const menuitem_t menu_load_preset_high[] = static const menuitem_t menu_load_preset_high[] =
{ {
{ MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb},
{ MT_ADV_CALLBACK, 5, "LOAD %s", menu_load_preset_acb}, { MT_ADV_CALLBACK, 5, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 6, "LOAD %s", menu_load_preset_acb}, { MT_ADV_CALLBACK, 6, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 7, "LOAD %s", menu_load_preset_acb}, { MT_ADV_CALLBACK, 7, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 8, "LOAD %s", menu_load_preset_acb}, { MT_ADV_CALLBACK, 8, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_SUBMENU, 0, "STORE" , menu_store_preset_high}, { MT_SUBMENU, 0, "STORE" , menu_store_preset_high},
{ MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_CANCEL, 255, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -1995,11 +1992,11 @@ static const menuitem_t menu_store_preset[] =
static const menuitem_t menu_load_preset[] = static const menuitem_t menu_load_preset[] =
{ {
{ MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb},
{ MT_ADV_CALLBACK, 1, "%s" , menu_load_preset_acb}, { MT_ADV_CALLBACK, 1, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 2, "%s" , menu_load_preset_acb}, { MT_ADV_CALLBACK, 2, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 3, "%s" , menu_load_preset_acb}, { MT_ADV_CALLBACK, 3, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_ADV_CALLBACK, 4, "%s" , menu_load_preset_acb}, { MT_ADV_CALLBACK, 4, MT_CUSTOM_LABEL, menu_load_preset_acb},
{ MT_SUBMENU, 0, "STORE" , menu_store_preset}, { MT_SUBMENU, 0, "STORE" , menu_store_preset},
{ MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_CANCEL, 0, S_LARROW" BACK", NULL },
{ MT_NONE, 0, NULL, NULL } // sentinel { MT_NONE, 0, NULL, NULL } // sentinel
@ -2054,7 +2051,7 @@ static const menuitem_t menu_lowoutputmode[] = {
// { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, // { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb},
{ MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("10kHz..350MHz","10kHz..850MHz")}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("10kHz..350MHz","10kHz..850MHz")},
{ MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text},
{ MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb},
{ MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb},
#ifdef __SWEEP_RESTART__ #ifdef __SWEEP_RESTART__
{ MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb},
@ -2071,7 +2068,7 @@ static const menuitem_t menu_highoutputmode[] = {
{ MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb},
{ MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("240MHz..960MHz",range_text)}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("240MHz..960MHz",range_text)},
{ MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */}, { MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */},
{ MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb},
{ MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb},
#ifdef __SWEEP_RESTART__ #ifdef __SWEEP_RESTART__
{ MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb},

Loading…
Cancel
Save

Powered by TurnKey Linux.