Skip to content

Commit

Permalink
hack in extra decimal for progressbars
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky committed Oct 20, 2023
1 parent da19b0a commit dce42b8
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/chat_gui4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "./file_selector.hpp"

#include <cstdio>
#include <solanaceae/message3/components.hpp>
#include <solanaceae/tox_messages/components.hpp>
#include <solanaceae/contact/components.hpp>
Expand Down Expand Up @@ -545,9 +546,16 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
ImGui::TextUnformatted("down");
if (reg.all_of<Message::Components::Transfer::BytesReceived>(e)) {
ImGui::SameLine();

float fraction = float(reg.get<Message::Components::Transfer::BytesReceived>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size;

char overlay_buf[32];
std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f);

ImGui::ProgressBar(
float(reg.get<Message::Components::Transfer::BytesReceived>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size,
{-FLT_MIN, TEXT_BASE_HEIGHT}
fraction,
{-FLT_MIN, TEXT_BASE_HEIGHT},
overlay_buf
);
// TODO: numbers
}
Expand All @@ -559,9 +567,16 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) {
ImGui::TextUnformatted(" up");
if (reg.all_of<Message::Components::Transfer::BytesSent>(e)) {
ImGui::SameLine();

float fraction = float(reg.get<Message::Components::Transfer::BytesSent>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size;

char overlay_buf[32];
std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f);

ImGui::ProgressBar(
float(reg.get<Message::Components::Transfer::BytesSent>(e).total) / reg.get<Message::Components::Transfer::FileInfo>(e).total_size,
{-FLT_MIN, TEXT_BASE_HEIGHT}
fraction,
{-FLT_MIN, TEXT_BASE_HEIGHT},
overlay_buf
);
// TODO: numbers
}
Expand Down

0 comments on commit dce42b8

Please sign in to comment.