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 <ryan@turnrye.com>
This commit is contained in:
Ryan Turner 2026-06-08 11:09:42 -05:00 committed by Silvano Seva
parent 9bf36b8a50
commit 6b8ef00b4d
3 changed files with 41 additions and 5 deletions

View file

@ -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.
*

View file

@ -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)
{

View file

@ -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)