gui: Trim string if length goes beyond screen

This commit is contained in:
Joel16 2021-03-21 12:47:23 -04:00
parent 543b607230
commit c3602f1fff
4 changed files with 14 additions and 7 deletions

View File

@ -33,7 +33,7 @@ typedef struct {
namespace GUI {
void ResetCheckbox(MenuItem *item);
void RecalcStorageSize(MenuItem *item);
void ProgressBar(const std::string &title, const std::string &message, u64 offset, u64 size);
void ProgressBar(const std::string &title, std::string message, u64 offset, u64 size);
void DownloadProgressBar(void *args);
Result Loop(void);

View File

@ -24,11 +24,11 @@ namespace GUI {
void DisplayFileBrowser(MenuItem *item) {
float filename_height = 0.f;
C2D::GetTextSize(0.45f, nullptr, &filename_height, cfg.cwd.c_str());
C2D::Text(5, 15 + ((25 - filename_height) / 2), 0.45f, WHITE, cfg.cwd.c_str());
C2D::Textf(5, 15 + ((25 - filename_height) / 2), 0.45f, WHITE, cfg.cwd.length() > 60? "%.60s..." : "%s", cfg.cwd.c_str());
// Storage bar
C2D::Rect(5, 28 + ((25 - filename_height) / 2), 390, 2, cfg.dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
float fill = (static_cast<double>(item->used_storage)/static_cast<double>(item->total_storage)) * 390.0;
float fill = (static_cast<double>(item->used_storage)/static_cast<double>(item->total_storage)) * 390.f;
C2D::Rect(5, 28 + ((25 - filename_height) / 2), fill, 2, cfg.dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR);
if (item->entries.empty()) {
@ -54,7 +54,8 @@ namespace GUI {
else
C2D::Image(file_icons[file_type], 20, start_y + (sel_dist * (i - start)));
C2D::Text(45, start_y + ((sel_dist - filename_height) / 2) + (i - start) * sel_dist, 0.45f, cfg.dark_theme? WHITE : BLACK, filename.c_str());
C2D::Textf(45, start_y + ((sel_dist - filename_height) / 2) + (i - start) * sel_dist, 0.45f, cfg.dark_theme? WHITE : BLACK,
filename.length() > 52? "%.52s..." : "%s", filename.c_str());
}
}

View File

@ -31,7 +31,12 @@ namespace GUI {
item->used_storage = FS::GetUsedStorage(archive == sdmc_archive? SYSTEM_MEDIATYPE_SD : SYSTEM_MEDIATYPE_CTR_NAND);
}
void ProgressBar(const std::string &title, const std::string &message, u64 offset, u64 size) {
void ProgressBar(const std::string &title, std::string message, u64 offset, u64 size) {
if (message.length() > 38) {
message.resize(38);
message.append("...");
}
C3D_FrameBegin(C3D_FRAME_SYNCDRAW);
C2D_TargetClear(bottom_screen, cfg.dark_theme? BLACK_BG : WHITE);
C2D_SceneBegin(bottom_screen);
@ -45,7 +50,7 @@ namespace GUI {
C2D::Text(((320 - (text_width)) / 2), ((240 - (dialog.subtex->height)) / 2) + 40 - 3, 0.42f, cfg.dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT, message.c_str());
C2D::Rect(((320 - (dialog.subtex->width)) / 2) + 20, ((240 - (dialog.subtex->height)) / 2) + 65, 240, 4, cfg.dark_theme? SELECTOR_COLOUR_DARK : SELECTOR_COLOUR_LIGHT);
C2D::Rect(((320 - (dialog.subtex->width)) / 2) + 20, ((240 - (dialog.subtex->height)) / 2) + 65, (static_cast<double>(offset) / static_cast<double>(size)) * 240.0,
C2D::Rect(((320 - (dialog.subtex->width)) / 2) + 20, ((240 - (dialog.subtex->height)) / 2) + 65, (static_cast<double>(offset) / static_cast<double>(size)) * 240.f,
4, cfg.dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR);
C2D::Render();

View File

@ -14,7 +14,8 @@ namespace GUI {
C2D::Image(cfg.dark_theme? properties_dialog_dark : properties_dialog, ((320 - (properties_dialog.subtex->width)) / 2), ((240 - (properties_dialog.subtex->height)) / 2) + 10);
C2D::Text(((320 - (properties_dialog.subtex->width)) / 2) + 6, ((240 - (properties_dialog.subtex->height)) / 2) + 13, 0.42f, cfg.dark_theme? TITLE_COLOUR_DARK : TITLE_COLOUR, "Properties");
C2D::Textf(66, 57, 0.42f, cfg.dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT, "Parent: %.20s", cfg.cwd.c_str());
C2D::Textf(66, 57, 0.42f, cfg.dark_theme? TEXT_MIN_COLOUR_DARK : TEXT_MIN_COLOUR_LIGHT,
cfg.cwd.length() > 22? "Parent: %.22s..." : "Parent: %s", cfg.cwd.c_str());
if (!(item->entries[item->selected].attributes & FS_ATTRIBUTE_DIRECTORY)) {
char utils_size[16];
Utils::GetSizeString(utils_size, static_cast<double>(item->entries[item->selected].fileSize));