SDRPlusPlus/core/src/gui/style.cpp

89 wiersze
2.9 KiB
C++
Czysty Zwykły widok Historia

2020-09-19 22:19:39 +00:00
#include <gui/style.h>
#include <imgui.h>
#include <imgui_internal.h>
#include <config.h>
2020-12-22 21:39:24 +00:00
#include <spdlog/spdlog.h>
#include <filesystem>
2020-08-16 01:39:05 +00:00
namespace style {
2020-11-30 20:17:36 +00:00
ImFont* baseFont;
ImFont* bigFont;
ImFont* hugeFont;
ImVector<ImWchar> baseRanges;
ImVector<ImWchar> bigRanges;
ImVector<ImWchar> hugeRanges;
2020-11-30 20:17:36 +00:00
#ifndef __ANDROID__
float uiScale = 1.0f;
#else
float uiScale = 3.0f;
#endif
2021-06-23 19:45:38 +00:00
bool loadFonts(std::string resDir) {
ImFontAtlas* fonts = ImGui::GetIO().Fonts;
2020-12-22 21:39:24 +00:00
if (!std::filesystem::is_directory(resDir)) {
2021-09-20 17:59:35 +00:00
spdlog::error("Invalid resource directory: {0}", resDir);
2020-12-22 21:39:24 +00:00
return false;
}
// Create base font range
ImFontGlyphRangesBuilder baseBuilder;
baseBuilder.AddRanges(fonts->GetGlyphRangesDefault());
baseBuilder.AddRanges(fonts->GetGlyphRangesCyrillic());
baseBuilder.BuildRanges(&baseRanges);
// Create big font range
ImFontGlyphRangesBuilder bigBuilder;
const ImWchar bigRange[] = { '.', '9', 0 };
bigBuilder.AddRanges(bigRange);
bigBuilder.BuildRanges(&bigRanges);
// Create huge font range
ImFontGlyphRangesBuilder hugeBuilder;
const ImWchar hugeRange[] = { 'S', 'S', 'D', 'D', 'R', 'R', '+', '+', ' ', ' ', 0 };
hugeBuilder.AddRanges(hugeRange);
hugeBuilder.BuildRanges(&hugeRanges);
// Add bigger fonts for frequency select and title
baseFont = fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 16.0f * uiScale, NULL, baseRanges.Data);
bigFont = fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 45.0f * uiScale, NULL, bigRanges.Data);
hugeFont = fonts->AddFontFromFileTTF(((std::string)(resDir + "/fonts/Roboto-Medium.ttf")).c_str(), 128.0f * uiScale, NULL, hugeRanges.Data);
2020-08-16 01:39:05 +00:00
2020-12-22 21:39:24 +00:00
return true;
2020-08-17 00:39:56 +00:00
}
2020-08-16 01:39:05 +00:00
void beginDisabled() {
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
2021-06-23 19:45:38 +00:00
auto& style = ImGui::GetStyle();
ImVec4* colors = style.Colors;
ImVec4 btnCol = colors[ImGuiCol_Button];
2021-06-23 20:24:58 +00:00
ImVec4 frameCol = colors[ImGuiCol_FrameBg];
ImVec4 textCol = colors[ImGuiCol_Text];
2021-06-23 19:45:38 +00:00
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);
2020-08-16 01:39:05 +00:00
}
void endDisabled() {
ImGui::PopItemFlag();
2020-08-17 00:39:56 +00:00
ImGui::PopStyleColor(3);
2020-08-16 01:39:05 +00:00
}
2021-08-31 16:39:48 +00:00
}
namespace ImGui {
2021-10-02 23:41:18 +00:00
void LeftLabel(const char* text) {
2021-08-31 16:39:48 +00:00
float vpos = ImGui::GetCursorPosY();
ImGui::SetCursorPosY(vpos + GImGui->Style.FramePadding.y);
ImGui::TextUnformatted(text);
2021-08-31 16:39:48 +00:00
ImGui::SameLine();
ImGui::SetCursorPosY(vpos);
}
2022-01-21 19:22:13 +00:00
void FillWidth() {
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
2022-01-21 19:22:13 +00:00
}
}