mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-09 17:57:11 +01:00
76 lines
2.3 KiB
C++
76 lines
2.3 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;
|
|
ImVector<ImWchar> ranges;
|
|
ImFontGlyphRangesBuilder builder;
|
|
|
|
#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;
|
|
}
|
|
|
|
// Create font range
|
|
ImFontAtlas* fonts = ImGui::GetIO().Fonts;
|
|
builder.AddRanges(fonts->GetGlyphRangesDefault());
|
|
builder.AddRanges(fonts->GetGlyphRangesCyrillic());
|
|
builder.BuildRanges(&ranges);
|
|
|
|
// Add bigger fonts for frequency select and title
|
|
baseFont = fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 16.0f * uiScale, NULL, ranges.Data);
|
|
bigFont = fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 45.0f * uiScale);
|
|
hugeFont = 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::GetContentRegionAvail().x);
|
|
}
|
|
}
|