From e725a261b69e081cb747f32503c8099e73c8cfe5 Mon Sep 17 00:00:00 2001 From: itzandroidtab Date: Wed, 27 Mar 2024 22:15:13 +0100 Subject: [PATCH] added profile index to main screen --- ui/totp.hpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ui/totp.hpp b/ui/totp.hpp index 253acfc..8aeb8a4 100644 --- a/ui/totp.hpp +++ b/ui/totp.hpp @@ -41,6 +41,7 @@ namespace menu { char current_token_buf[16] = {}; char next_token_buf[16] = {}; char seconds_left_buf[7] = {}; + char index_buf[6] = {}; constexpr static uint32_t step_size = 2; using lookuptable = klib::lookuptable<360 / step_size, int>; @@ -239,6 +240,22 @@ namespace menu { klib::string::set_width(next_token_buf, static_cast(entry.digits), '0' ); + + // get the width we should use for the index string + const uint32_t index_width = klib::string::detail::count_chars(entries.size()); + + // only display it while we have less than 100 entries + if (entries.size() > 1 && index_width <= 2) { + // copy the current index to the buffer + klib::string::itoa(current + 1, index_buf); + klib::string::set_width(index_buf, index_width, ' '); + + klib::string::strcat(index_buf, "\\"); + + char *const ptr = index_buf + klib::string::strlen(index_buf); + klib::string::itoa(entries.size(), ptr); + klib::string::set_width(ptr, index_width, ' '); + } } // get the delta as a string @@ -356,6 +373,14 @@ namespace menu { } - offset.cast(), klib::graphics::white ); + + // draw using the large font + screen_base::small_text::template draw( + frame_buffer, + index_buf, + klib::vector2i{3, 3} - offset.cast(), + klib::graphics::white + ); } }; } \ No newline at end of file