build: Update ImGui to v1.92.1 (#2325)

Update ImGui to the latest version and rewrite most of the font handling
code
This commit is contained in:
Nik
2025-07-10 10:00:39 +02:00
committed by GitHub
parent fa62a675dc
commit d1840a2184
50 changed files with 9932 additions and 5654 deletions

View File

@@ -1006,35 +1006,48 @@ namespace hex {
namespace impl {
static AutoReset<std::vector<Font>> s_fonts;
const std::vector<Font>& getFonts() {
static AutoReset<std::vector<MergeFont>> s_fonts;
const std::vector<MergeFont>& getMergeFonts() {
return *s_fonts;
}
static float s_fontSize = DefaultFontSize;
void setFontSize(float size) {
s_fontSize = size;
}
static AutoReset<ImFontAtlas*> s_fontAtlas;
void setFontAtlas(ImFontAtlas* fontAtlas) {
s_fontAtlas = fontAtlas;
}
static ImFont *s_boldFont = nullptr;
static ImFont *s_italicFont = nullptr;
void setFonts(ImFont *bold, ImFont *italic) {
s_boldFont = bold;
s_italicFont = italic;
}
static AutoReset<std::map<UnlocalizedString, ImFont*>> s_fontDefinitions;
std::map<UnlocalizedString, ImFont*>& getFontDefinitions() {
return *s_fontDefinitions;
}
static AutoReset<const Font*> s_defaultFont;
}
Font::Font(UnlocalizedString fontName) : m_fontName(std::move(fontName)) {
Fonts::registerFont(m_fontName);
if (impl::s_defaultFont == nullptr)
impl::s_defaultFont = this;
}
void Font::push(float size) const {
auto font = getFont(m_fontName);
if (size <= 0.0F) {
size = font->LegacySize;
}
size *= System::getGlobalScale();
ImGui::PushFont(font, size);
}
void Font::pop() const {
ImGui::PopFont();
}
Font::operator ImFont*() const {
return getFont(m_fontName);
}
GlyphRange glyph(const char *glyph) {
u32 codepoint;
ImTextCharFromUtf8(&codepoint, glyph, nullptr);
@@ -1075,7 +1088,7 @@ namespace hex {
return;
}
impl::s_fonts->emplace_back(Font {
impl::s_fonts->emplace_back(MergeFont {
wolv::util::toUTF8String(path.filename()),
fontFile.readVector(),
glyphRanges,
@@ -1087,7 +1100,7 @@ namespace hex {
}
void loadFont(const std::string &name, const std::span<const u8> &data, const std::vector<GlyphRange> &glyphRanges, Offset offset, u32 flags, std::optional<bool> scalable, std::optional<u32> defaultSize) {
impl::s_fonts->emplace_back(Font {
impl::s_fonts->emplace_back(MergeFont {
name,
{ data.begin(), data.end() },
glyphRanges,
@@ -1098,14 +1111,6 @@ namespace hex {
});
}
float getFontSize() {
return impl::s_fontSize;
}
ImFontAtlas* getFontAtlas() {
return impl::s_fontAtlas;
}
void registerFont(const UnlocalizedString &fontName) {
(*impl::s_fontDefinitions)[fontName] = nullptr;
}
@@ -1114,12 +1119,12 @@ namespace hex {
return (*impl::s_fontDefinitions)[fontName];
}
ImFont* Bold() {
return impl::s_boldFont;
void setDefaultFont(const Font& font) {
impl::s_defaultFont = &font;
}
ImFont* Italic() {
return impl::s_italicFont;
const Font& getDefaultFont() {
return **impl::s_defaultFont;
}
float getDpi() {