SDRPlusPlus/core/src/gui/style.cpp

67 wiersze
2.0 KiB
C++

#include <gui/style.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <config.h>
#include <options.h>
#include <spdlog/spdlog.h>
#include <filesystem>
namespace style {
ImFont* baseFont;
ImFont* bigFont;
ImFont* hugeFont;
#ifndef __ANDROID__
float uiScale = 1.0f;
#else
float uiScale = 3.0f;
#endif
bool loadFonts(std::string resDir) {
if (!std::filesystem::is_directory(resDir)) {
spdlog::error("Invalid resource directory: {0}", resDir);
return false;
}
baseFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 16.0f * uiScale);
bigFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 45.0f * uiScale);
hugeFont = ImGui::GetIO().Fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 128.0f * uiScale);
return true;
}
void beginDisabled() {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
auto& style = ImGui::GetStyle();
ImVec4* colors = style.Colors;
ImVec4 btnCol = colors[ImGuiCol_Button];
ImVec4 frameCol = colors[ImGuiCol_FrameBg];
ImVec4 textCol = colors[ImGuiCol_Text];
btnCol.w = 0.15f;
frameCol.w = 0.30f;
textCol.w = 0.65f;
ImGui::PushStyleColor(ImGuiCol_Button, btnCol);
ImGui::PushStyleColor(ImGuiCol_FrameBg, frameCol);
ImGui::PushStyleColor(ImGuiCol_Text, textCol);
}
void endDisabled() {
ImGui::PopItemFlag();
ImGui::PopStyleColor(3);
}
}
namespace ImGui {
void LeftLabel(const char* text) {
float vpos = ImGui::GetCursorPosY();
ImGui::SetCursorPosY(vpos + GImGui->Style.FramePadding.y);
ImGui::TextUnformatted(text);
ImGui::SameLine();
ImGui::SetCursorPosY(vpos);
}
void FillWidth() {
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvailWidth());
}
}