mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
feat: Added ability to draw Bold and Italic text
This commit is contained in:
@@ -759,17 +759,29 @@ EXPORT_MODULE namespace hex {
|
||||
explicit Font(UnlocalizedString fontName);
|
||||
|
||||
void push(float size = 0.0F) const;
|
||||
void pushBold(float size = 0.0F) const;
|
||||
void pushItalic(float size = 0.0F) const;
|
||||
|
||||
void pop() const;
|
||||
|
||||
[[nodiscard]] operator ImFont*() const;
|
||||
private:
|
||||
void push(float size, ImFont *font) const;
|
||||
|
||||
private:
|
||||
UnlocalizedString m_fontName;
|
||||
};
|
||||
|
||||
struct FontDefinition {
|
||||
ImFont* regular;
|
||||
ImFont* bold;
|
||||
ImFont* italic;
|
||||
};
|
||||
|
||||
namespace impl {
|
||||
|
||||
const std::vector<MergeFont>& getMergeFonts();
|
||||
std::map<UnlocalizedString, ImFont*>& getFontDefinitions();
|
||||
std::map<UnlocalizedString, FontDefinition>& getFontDefinitions();
|
||||
|
||||
}
|
||||
|
||||
@@ -777,7 +789,7 @@ EXPORT_MODULE namespace hex {
|
||||
void loadFont(const std::string &name, const std::span<const u8> &data, Offset offset = {}, std::optional<u32> defaultSize = std::nullopt);
|
||||
|
||||
void registerFont(const UnlocalizedString &fontName);
|
||||
ImFont* getFont(const UnlocalizedString &fontName);
|
||||
FontDefinition getFont(const UnlocalizedString &fontName);
|
||||
|
||||
void setDefaultFont(const Font& font);
|
||||
const Font& getDefaultFont();
|
||||
|
||||
@@ -1011,8 +1011,8 @@ namespace hex {
|
||||
return *s_fonts;
|
||||
}
|
||||
|
||||
static AutoReset<std::map<UnlocalizedString, ImFont*>> s_fontDefinitions;
|
||||
std::map<UnlocalizedString, ImFont*>& getFontDefinitions() {
|
||||
static AutoReset<std::map<UnlocalizedString, FontDefinition>> s_fontDefinitions;
|
||||
std::map<UnlocalizedString, FontDefinition>& getFontDefinitions() {
|
||||
return *s_fontDefinitions;
|
||||
}
|
||||
|
||||
@@ -1028,8 +1028,18 @@ namespace hex {
|
||||
}
|
||||
|
||||
void Font::push(float size) const {
|
||||
auto font = getFont(m_fontName);
|
||||
push(size, getFont(m_fontName).regular);
|
||||
}
|
||||
|
||||
void Font::pushBold(float size) const {
|
||||
push(size, getFont(m_fontName).bold);
|
||||
}
|
||||
|
||||
void Font::pushItalic(float size) const {
|
||||
push(size, getFont(m_fontName).italic);
|
||||
}
|
||||
|
||||
void Font::push(float size, ImFont* font) const {
|
||||
if (font != nullptr) {
|
||||
if (size <= 0.0F) {
|
||||
size = font->LegacySize;
|
||||
@@ -1044,12 +1054,13 @@ namespace hex {
|
||||
ImGui::PushFont(font, size);
|
||||
}
|
||||
|
||||
|
||||
void Font::pop() const {
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
Font::operator ImFont*() const {
|
||||
return getFont(m_fontName);
|
||||
return getFont(m_fontName).regular;
|
||||
}
|
||||
|
||||
void loadFont(const std::fs::path &path, Offset offset, std::optional<u32> defaultSize) {
|
||||
@@ -1077,15 +1088,16 @@ namespace hex {
|
||||
}
|
||||
|
||||
void registerFont(const UnlocalizedString &fontName) {
|
||||
(*impl::s_fontDefinitions)[fontName] = nullptr;
|
||||
(*impl::s_fontDefinitions)[fontName] = {};
|
||||
}
|
||||
|
||||
ImFont* getFont(const UnlocalizedString &fontName) {
|
||||
FontDefinition getFont(const UnlocalizedString &fontName) {
|
||||
auto it = impl::s_fontDefinitions->find(fontName);
|
||||
|
||||
if (it == impl::s_fontDefinitions->end())
|
||||
return ImGui::GetDefaultFont();
|
||||
else
|
||||
if (it == impl::s_fontDefinitions->end()) {
|
||||
const auto defaultFont = ImGui::GetDefaultFont();
|
||||
return { defaultFont, defaultFont, defaultFont };
|
||||
} else
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user