diff --git a/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.cpp b/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.cpp index 10c490b68..ff7e93ffd 100644 --- a/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.cpp +++ b/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.cpp @@ -131,7 +131,7 @@ void NoaaAptRxView::on_status(NoaaAptRxStatusDataMessage msg) { // this stores and displays the image. keep it as simple as you can. a bit more complexity will kill the sync void NoaaAptRxView::on_image(NoaaAptRxImageDataMessage msg) { - if ((line_num) >= screen_height - NOAA_IMG_START_ROW * 16) line_num = 0; // for draw reset + if ((line_num) >= UI_POS_HEIGHT_REMAINING(NOAA_IMG_START_ROW)) line_num = 0; // for draw reset for (uint16_t i = 0; i < msg.cnt; i += 1) { Color pxl = {msg.image[i], msg.image[i], msg.image[i]}; diff --git a/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.hpp b/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.hpp index 686ed20a0..a2db6b9bb 100644 --- a/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.hpp +++ b/firmware/application/external/noaaapt_rx/ui_noaaapt_rx.hpp @@ -81,22 +81,22 @@ class NoaaAptRxView : public View { {}}; RFAmpField field_rf_amp{ - {13 * 8, 0 * 16}}; + {UI_POS_X(13), UI_POS_Y(0)}}; LNAGainField field_lna{ - {15 * 8, 0 * 16}}; + {UI_POS_X(15), UI_POS_Y(0)}}; VGAGainField field_vga{ - {18 * 8, 0 * 16}}; + {UI_POS_X(18), UI_POS_Y(0)}}; RSSI rssi{ - {21 * 8, 0, 6 * 8, 4}}; + {UI_POS_X(21), UI_POS_Y(0), UI_POS_WIDTH(6), 4}}; AudioVolumeField field_volume{ - {screen_width - 2 * 8, 0 * 16}}; + {UI_POS_X_RIGHT(2), UI_POS_Y(0)}}; RxFrequencyField field_frequency{ - {0 * 8, 0 * 16}, + {UI_POS_X(0), UI_POS_Y(0)}, nav_}; RecordView record_view{ - {0 * 8, 2 * 16, screen_width, 1 * 16}, + {UI_POS_X(0), UI_POS_Y(2), UI_POS_MAXWIDTH, UI_POS_DEFAULT_HEIGHT}, u"AUD", u"AUDIO", RecordView::FileType::WAV, @@ -104,22 +104,17 @@ class NoaaAptRxView : public View { 4}; Checkbox check_wav{ - {0 * 8, 2 * 16}, + {UI_POS_X(0), UI_POS_Y(2)}, 12, "Save WAV too", true}; - /*Labels labels{ - {{1 * 8, 1 * 16}, "LPM:", Theme::getInstance()->fg_light->foreground}, - {{13 * 8, 1 * 16}, "IOC:", Theme::getInstance()->fg_light->foreground}, - };*/ - Text txt_status{ - {0 * 8, 1 * 16, 20 * 8, 16}, + {UI_POS_X(0), UI_POS_Y(1), UI_POS_WIDTH(20), UI_POS_DEFAULT_HEIGHT}, }; Button button_ss{ - {190, 1 * 16, 5 * 8, 16}, + {UI_POS_X_RIGHT(6), UI_POS_Y(1), UI_POS_WIDTH(5), UI_POS_DEFAULT_HEIGHT}, LanguageHelper::currentMessages[LANG_START]}; MessageHandlerRegistration message_handler_stats{ diff --git a/firmware/application/external/protoview/ui_protoview.hpp b/firmware/application/external/protoview/ui_protoview.hpp index 32d0efa51..ff78fa648 100644 --- a/firmware/application/external/protoview/ui_protoview.hpp +++ b/firmware/application/external/protoview/ui_protoview.hpp @@ -60,29 +60,29 @@ class ProtoView : public View { "rx_protoview", app_settings::Mode::RX}; RFAmpField field_rf_amp{ - {13 * 8, 0 * 16}}; + {UI_POS_X(13), UI_POS_Y(0)}}; LNAGainField field_lna{ - {15 * 8, 0 * 16}}; + {UI_POS_X(15), UI_POS_Y(0)}}; VGAGainField field_vga{ - {18 * 8, 0 * 16}}; + {UI_POS_X(18), UI_POS_Y(0)}}; RSSI rssi{ - {21 * 8, 0, 6 * 8, 4}}; + {UI_POS_X(21), UI_POS_Y(0), UI_POS_WIDTH(6), 4}}; AudioVolumeField field_volume{ - {screen_width - 2 * 8, 0 * 16}}; + {UI_POS_X_RIGHT(2), UI_POS_Y(0)}}; RxFrequencyField field_frequency{ - {0 * 8, 0 * 16}, + {UI_POS_X(0), UI_POS_Y(0)}, nav_}; // need to seperate because label shift need to hide independently Labels label_zoom{ - {{0 * 8, 1 * 16}, "Zoom: ", Theme::getInstance()->fg_light->foreground}}; + {{UI_POS_X(0), UI_POS_Y(1)}, "Zoom: ", Theme::getInstance()->fg_light->foreground}}; Labels label_shift{ - {{0 * 8, 2 * 16}, "Shift: ", Theme::getInstance()->fg_light->foreground}}; + {{UI_POS_X(0), UI_POS_Y(2)}, "Shift: ", Theme::getInstance()->fg_light->foreground}}; OptionsField options_zoom{ - {7 * 8, 1 * 16}, + {UI_POS_X(7), UI_POS_Y(1)}, 4, {{"1", 1}, {"2", 2}, @@ -96,22 +96,22 @@ class ProtoView : public View { {"1000", 1000}}}; NumberField number_shift{ - {7 * 8, 2 * 16}, + {UI_POS_X(7), UI_POS_Y(2)}, 5, {-MAXSIGNALBUFFER, MAXSIGNALBUFFER}, 1, ' '}; Button button_reset{ - {screen_width - 12 * 8, 1 * 16, 96, 24}, + {UI_POS_X_RIGHT(12), UI_POS_Y(1), UI_POS_WIDTH(12), UI_POS_HEIGHT(1.5)}, LanguageHelper::currentMessages[LANG_RESET]}; Button button_pause{ - {screen_width - 12 * 8, 1 * 16 + 24, 96, 24}, + {UI_POS_X_RIGHT(12), UI_POS_Y(2.5), UI_POS_WIDTH(12), UI_POS_HEIGHT(1.5)}, LanguageHelper::currentMessages[LANG_PAUSE]}; Waveform waveform{ - {0, 8 * 8, screen_width, 50}, + {UI_POS_X(0), UI_POS_Y(4), UI_POS_MAXWIDTH, (UI_POS_HEIGHT_REMAINING(5) / 4) - 4}, waveform_buffer, 0, 0, @@ -119,7 +119,7 @@ class ProtoView : public View { Theme::getInstance()->fg_yellow->foreground}; Waveform waveform2{ - {0, 8 * 8 + 55, screen_width, 50}, + {UI_POS_X(0), UI_POS_Y(4) + (UI_POS_HEIGHT_REMAINING(5) / 4), UI_POS_MAXWIDTH, (UI_POS_HEIGHT_REMAINING(5) / 4) - 4}, &waveform_buffer[MAXDRAWCNTPERWF], 0, 0, @@ -127,7 +127,7 @@ class ProtoView : public View { Theme::getInstance()->fg_yellow->foreground}; Waveform waveform3{ - {0, 8 * 8 + 110, screen_width, 50}, + {UI_POS_X(0), UI_POS_Y(4) + 2 * (UI_POS_HEIGHT_REMAINING(5) / 4), UI_POS_MAXWIDTH, (UI_POS_HEIGHT_REMAINING(5) / 4) - 4}, &waveform_buffer[MAXDRAWCNTPERWF * 2], 0, 0, @@ -135,7 +135,7 @@ class ProtoView : public View { Theme::getInstance()->fg_yellow->foreground}; Waveform waveform4{ - {0, 8 * 8 + 165, screen_width, 50}, + {UI_POS_X(0), UI_POS_Y(4) + 3 * (UI_POS_HEIGHT_REMAINING(5) / 4), UI_POS_MAXWIDTH, (UI_POS_HEIGHT_REMAINING(5) / 4) - 4}, &waveform_buffer[MAXDRAWCNTPERWF * 3], 0, 0, diff --git a/firmware/common/ui.hpp b/firmware/common/ui.hpp index 4a029cbda..edec2d404 100644 --- a/firmware/common/ui.hpp +++ b/firmware/common/ui.hpp @@ -26,6 +26,36 @@ namespace ui { +// Positioning helpers PER CHARACTERS (8*16) +// EACH parameters must be used az CHAR position, not PX coordinates. So If you wanna use the 8,16 coordinates (that is the second character in X and second character in Y you must use UI_POS_X(1) UI_POS_Y(1) (since we count from 0) + +// default font height +#define UI_POS_DEFAULT_HEIGHT 16 +// default font width +#define UI_POS_DEFAULT_WIDTH 8 +// px position of the linenum-th character (Y) +#define UI_POS_Y(linenum) ((int)((linenum)*UI_POS_DEFAULT_HEIGHT)) +// px position of the linenum-th character from the bottom of the screen (Y) (please calculate the +1 line top-bar to it too if that is visible!) +#define UI_POS_Y_BOTTOM(linenum) ((int)(screen_height - (linenum)*UI_POS_DEFAULT_HEIGHT)) +// px position of the linenum-th character from the left of the screen (X) +#define UI_POS_X(charnum) ((int)((charnum)*UI_POS_DEFAULT_WIDTH)) +// px position of the linenum-th character from the right of the screen (X) +#define UI_POS_X_RIGHT(charnum) ((int)(screen_width - ((charnum)*UI_POS_DEFAULT_WIDTH))) +// px position of the left character from the center of the screen (X) (for N character wide string) +#define UI_POS_X_CENTER(charnum) ((int)((screen_width / 2) - ((charnum)*UI_POS_DEFAULT_WIDTH / 2))) +// px width of N characters +#define UI_POS_WIDTH(charnum) ((int)((charnum)*UI_POS_DEFAULT_WIDTH)) +// px width of the screen +#define UI_POS_MAXWIDTH (screen_width) +// px height of N line +#define UI_POS_HEIGHT(linecount) ((int)((linecount)*UI_POS_DEFAULT_HEIGHT)) +// px height of the screen's percent +#define UI_POS_HEIGHT_PERCENT(percent) ((int)(screen_height * (percent) / 100)) +// remaining px from the linenum-th line to the bottom of the screen. (please calculate the +1 line top-bar to it too if that is visible!) +#define UI_POS_HEIGHT_REMAINING(linenum) ((int)(screen_height - ((linenum)*UI_POS_DEFAULT_HEIGHT))) +// remaining px from the charnum-th character to the right of the screen +#define UI_POS_WIDTH_REMAINING(charnum) ((int)(screen_width - ((charnum)*UI_POS_DEFAULT_WIDTH))) + // Escape sequences for colored text; second character is index into term_colors[] #define STR_COLOR_BLACK "\x1B\x00" #define STR_COLOR_DARK_BLUE "\x1B\x01"