Skip to content

Commit

Permalink
gui: display button name when icon not found
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Sep 13, 2020
1 parent 6d75a5c commit df280f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/platform/windows/gui/images.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ std::optional<Image> loadImage(const std::string& file) {

auto rawdata = getFileContents(file);
if (rawdata.empty()) {
fmt::print("[ERROR] Cannot load {}\n", getFilenameExt(file));
fmt::print("Cannot load {}\n", getFilenameExt(file));
return {};
}

auto data = stbi_load_from_memory(rawdata.data(), rawdata.size(), &w, &h, &bit, 4);
if (data == nullptr) {
fmt::print("[ERROR] Cannot load {}\n", getFilenameExt(file));
fmt::print("Cannot load {}\n", getFilenameExt(file));
return {};
}

Expand Down
7 changes: 6 additions & 1 deletion src/platform/windows/gui/options/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ void button(int controller, const std::string& button, const char* tooltip = nul
std::string key = config.controller[ctrl].keys[button];

const float iconSize = 20.f;
drawImage(getImage(button, avocado::assetsPath("buttons/")), iconSize);
auto buttonImage = getImage(button, avocado::assetsPath("buttons/"));
if (buttonImage) {
drawImage(buttonImage, iconSize);
} else {
ImGui::TextUnformatted(button.c_str());
}
if (ImGui::IsItemHovered() && tooltip != nullptr) {
ImGui::BeginTooltip();
ImGui::TextUnformatted(tooltip);
Expand Down

0 comments on commit df280f3

Please sign in to comment.