Skip to content

Commit fcd87a0

Browse files
committed
Better size display
1 parent 824f1c9 commit fcd87a0

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

source/views/game_view.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
#include "views/game_view.hpp"
22
#include "activity/main_activity.hpp"
33

4+
#include <iomanip>
5+
46
using namespace brls::literals;
57

8+
std::string convertSizeToString(const int size) {
9+
const int kio = 1024;
10+
const int mio = kio * kio;
11+
const int gio = mio * kio;
12+
13+
std::string string_size;
14+
15+
if (size < kio) {
16+
string_size = std::to_string(size) + " octets";
17+
} else if (size < mio) {
18+
string_size = std::to_string(static_cast<double>(size) / kio) + " Ko";
19+
} else if (size < gio) {
20+
string_size = std::to_string(static_cast<double>(size) / mio) + " Mo";
21+
} else {
22+
string_size = std::to_string(static_cast<double>(size) / gio) + " Go";
23+
}
24+
25+
return string_size;
26+
}
27+
628
GameView::GameView(Game game) : game(game)
729
{
830
this->inflateFromXMLRes("xml/views/game.xml");
@@ -36,8 +58,10 @@ GameView::GameView(Game game) : game(game)
3658
publisher->setText(fmt::format("{} : N/A", "app/game/publisher"_i18n));
3759

3860
//SIZE
39-
if(game.getSize() > 0)
40-
size->setText(fmt::format("{} : {}", "app/game/size"_i18n, game.getSize()));
61+
if(game.getSize() > 0) {
62+
std::string size_str = convertSizeToString(game.getSize());
63+
size->setText(fmt::format("{} : {}", "app/game/size"_i18n, size_str));
64+
}
4165
else
4266
size->setText(fmt::format("{} : N/A", "app/game/size"_i18n));
4367

0 commit comments

Comments
 (0)