IQ.Pilot Release Commit @ 0798119
This commit is contained in:
27
tools/jotpluggler/icons.cc
Normal file
27
tools/jotpluggler/icons.cc
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "tools/jotpluggler/app.h"
|
||||
#include "tools/jotpluggler/common.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
void icon_add_font(float size, bool merge, const ImFont *base_font) {
|
||||
// IQ.Pilot patch: iqpilot's third_party/bootstrap is git-lfs and the TTF isn't
|
||||
// checked in, so we vendor the font alongside jotpluggler instead of relying on
|
||||
// third_party/bootstrap/bootstrap-icons.ttf.
|
||||
const std::filesystem::path ttf = repo_root() / "tools" / "jotpluggler" / "assets" / "bootstrap-icons.ttf";
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
ImFontConfig config;
|
||||
config.MergeMode = merge;
|
||||
config.GlyphMinAdvanceX = size;
|
||||
if (base_font != nullptr) {
|
||||
ImFontBaked *baked = const_cast<ImFont *>(base_font)->GetFontBaked(size);
|
||||
const float base_center = baked != nullptr ? (baked->Ascent + baked->Descent) * 0.5f : size * 0.5f;
|
||||
config.GlyphOffset.y = std::round(size * 0.5f - base_center);
|
||||
}
|
||||
static const ImWchar ranges[] = {0xF000, 0xF8FF, 0};
|
||||
io.Fonts->AddFontFromFileTTF(ttf.c_str(), size, &config, ranges);
|
||||
}
|
||||
|
||||
bool icon_menu_item(const char *glyph, const char *label, const char *shortcut, bool selected, bool enabled) {
|
||||
assert(glyph != nullptr && glyph[0] != '\0');
|
||||
return ImGui::MenuItem(util::string_format("%s %s", glyph, label).c_str(), shortcut, selected, enabled);
|
||||
}
|
||||
Reference in New Issue
Block a user