From 6b8ef00b4dadfcc54c832867a2c4c9c9aea04fdf Mon Sep 17 00:00:00 2001 From: Ryan Turner Date: Mon, 8 Jun 2026 11:09:42 -0500 Subject: [PATCH] ui: make vfo freq display easier to read Make it so that the VFO screen shows the frequency with a consistent set precision. Show the hundredths place in the full size font, then show the thousandths and ten-thousandths place in font two steps smaller. This way it's easier to scroll through frequencies and read where you are. Signed-off-by: Ryan Turner --- openrtx/include/core/graphics.h | 9 +++++++++ openrtx/src/core/graphics.c | 6 ++++++ openrtx/src/ui/default/ui_main.c | 31 ++++++++++++++++++++++++++----- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/openrtx/include/core/graphics.h b/openrtx/include/core/graphics.h index 4c54c65b..2ac3d544 100644 --- a/openrtx/include/core/graphics.h +++ b/openrtx/include/core/graphics.h @@ -235,6 +235,15 @@ point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment, uint16_t gfx_measureText(fontSize_t size, const char *buf, uint16_t start_x, uint16_t max_x, size_t char_count); +/** + * Measures the pixel width of a single line of text. + * + * @param size: text font size. + * @param buf: NUL-terminated string. + * @return width in pixels of the text line. + */ +uint16_t gfx_getTextWidth(fontSize_t size, const char *buf); + /** * Prints text from a char buffer into a clipped rectangular region. * diff --git a/openrtx/src/core/graphics.c b/openrtx/src/core/graphics.c index b07674fe..e59f9828 100644 --- a/openrtx/src/core/graphics.c +++ b/openrtx/src/core/graphics.c @@ -431,6 +431,12 @@ uint8_t gfx_getFontHeight(fontSize_t size) return glyph.height; } +uint16_t gfx_getTextWidth(fontSize_t size, const char *buf) +{ + GFXfont f = fonts[size]; + return get_line_size(f, buf, strlen(buf), CONFIG_SCREEN_WIDTH); +} + point_t gfx_printBuffer(point_t start, fontSize_t size, textAlign_t alignment, color_t color, const char *buf) { diff --git a/openrtx/src/ui/default/ui_main.c b/openrtx/src/ui/default/ui_main.c index 4ab00492..eed473aa 100644 --- a/openrtx/src/ui/default/ui_main.c +++ b/openrtx/src/ui/default/ui_main.c @@ -222,13 +222,34 @@ void _ui_drawFrequency() freq_t freq = platform_getPttStatus() ? last_state.channel.tx_frequency : last_state.channel.rx_frequency; - // Print big numbers frequency char freq_str[16] = {0}; - sniprintf(freq_str, sizeof(freq_str), "%lu.%06lu", (freq / 1000000lu), (freq % 1000000lu)); - stripTrailingZeroes(freq_str); + sniprintf(freq_str, sizeof(freq_str), "%03lu.%05lu", + (freq / 1000000lu), (freq % 1000000lu) / 10); - gfx_print(layout.line3_large_pos, layout.line3_large_font, TEXT_ALIGN_CENTER, - color_white, "%s", freq_str); + size_t len = strlen(freq_str); + char main_str[16] = {0}; + char small_str[3] = {0}; + strncpy(main_str, freq_str, len - 2); + strncpy(small_str, freq_str + len - 2, 2); + + fontSize_t small_font = FONT_SIZE_5PT; + if (layout.line3_large_font > FONT_SIZE_6PT) + { + small_font = (fontSize_t)(layout.line3_large_font - 2); + } + + uint16_t main_width = gfx_getTextWidth(layout.line3_large_font, main_str); + uint16_t small_width = gfx_getTextWidth(small_font, small_str); + uint16_t total_width = main_width + small_width; + int16_t start_x = (CONFIG_SCREEN_WIDTH - total_width) / 2; + + point_t main_pos = { (uint16_t)start_x, layout.line3_large_pos.y }; + gfx_print(main_pos, layout.line3_large_font, TEXT_ALIGN_LEFT, + color_white, "%s", main_str); + + point_t small_pos = { (uint16_t)(start_x + main_width), layout.line3_large_pos.y }; + gfx_print(small_pos, small_font, TEXT_ALIGN_LEFT, + color_white, "%s", small_str); } void _ui_drawVFOMiddleInput(ui_state_t* ui_state)