Skip to content

Commit

Permalink
added profile index to main screen
Browse files Browse the repository at this point in the history
  • Loading branch information
itzandroidtab committed Mar 27, 2024
1 parent 1559b56 commit e725a26
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions ui/totp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand Down Expand Up @@ -239,6 +240,22 @@ namespace menu {
klib::string::set_width(next_token_buf,
static_cast<uint8_t>(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
Expand Down Expand Up @@ -356,6 +373,14 @@ namespace menu {
} - offset.cast<int32_t>(),
klib::graphics::white
);

// draw using the large font
screen_base::small_text::template draw<FrameBuffer>(
frame_buffer,
index_buf,
klib::vector2i{3, 3} - offset.cast<int32_t>(),
klib::graphics::white
);
}
};
}

0 comments on commit e725a26

Please sign in to comment.