mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-15 08:15:59 +08:00
Fix issue with invalid imgui font
This commit is contained in:
parent
6dd5e21f59
commit
72ac201c60
@ -27,19 +27,10 @@ void FontManager::swap(size_t i1, size_t i2) {
|
|||||||
|
|
||||||
// fix selected index
|
// fix selected index
|
||||||
if (!is_activ_font()) return;
|
if (!is_activ_font()) return;
|
||||||
bool change_selected = false;
|
|
||||||
if (m_font_selected == i1) {
|
if (m_font_selected == i1) {
|
||||||
m_font_selected = i2;
|
m_font_selected = i2;
|
||||||
change_selected = true;
|
|
||||||
} else if (m_font_selected == i2) {
|
} else if (m_font_selected == i2) {
|
||||||
m_font_selected = i1;
|
m_font_selected = i1;
|
||||||
change_selected = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// something went wrong with imgui font when swap
|
|
||||||
// Hot fix is regenerate imgui font
|
|
||||||
if (change_selected) {
|
|
||||||
m_font_list[m_font_selected].imgui_font_index.reset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +39,7 @@ void FontManager::duplicate(size_t index) {
|
|||||||
if (index >= m_font_list.size()) return;
|
if (index >= m_font_list.size()) return;
|
||||||
Item item = m_font_list[index]; // copy
|
Item item = m_font_list[index]; // copy
|
||||||
make_unique_name(item.font_item.name);
|
make_unique_name(item.font_item.name);
|
||||||
|
item.truncated_name.clear();
|
||||||
|
|
||||||
// take original font imgui pointer
|
// take original font imgui pointer
|
||||||
//ImFont *imgui_font = get_imgui_font(index);
|
//ImFont *imgui_font = get_imgui_font(index);
|
||||||
@ -249,8 +241,9 @@ ImFont *FontManager::get_imgui_font(size_t item_index, const std::string &text)
|
|||||||
if (font == nullptr) return nullptr;
|
if (font == nullptr) return nullptr;
|
||||||
if (!font->IsLoaded()) return nullptr;
|
if (!font->IsLoaded()) return nullptr;
|
||||||
if (font->Scale <= 0.f) return nullptr;
|
if (font->Scale <= 0.f) return nullptr;
|
||||||
|
// automatic extend range
|
||||||
if (!text.empty() && !is_text_in_ranges(font, text))
|
if (!text.empty() && !is_text_in_ranges(font, text))
|
||||||
extend_imgui_font_range(item_index, text);
|
return extend_imgui_font_range(item_index, text);
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
@ -355,16 +348,17 @@ bool FontManager::is_text_in_ranges(const ImWchar *ranges, const std::string &te
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FontManager::extend_imgui_font_range(size_t index, const std::string& text)
|
ImFont* FontManager::extend_imgui_font_range(size_t index, const std::string& text)
|
||||||
{
|
{
|
||||||
auto &font_index_opt = m_font_list[m_font_selected].imgui_font_index;
|
auto &font_index_opt = m_font_list[m_font_selected].imgui_font_index;
|
||||||
if (!font_index_opt.has_value()) load_imgui_font(index, text);
|
if (!font_index_opt.has_value())
|
||||||
|
return load_imgui_font(index, text);
|
||||||
|
|
||||||
// TODO: start using merge mode
|
// TODO: start using merge mode
|
||||||
// ImFontConfig::MergeMode = true;
|
// ImFontConfig::MergeMode = true;
|
||||||
|
|
||||||
free_imgui_fonts();
|
free_imgui_fonts();
|
||||||
load_imgui_font(index, text);
|
return load_imgui_font(index, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "libslic3r/SLA/AGGRaster.hpp"
|
#include "libslic3r/SLA/AGGRaster.hpp"
|
||||||
|
@ -171,7 +171,8 @@ private:
|
|||||||
|
|
||||||
// extend actual imgui font when exist unknown char in text
|
// extend actual imgui font when exist unknown char in text
|
||||||
// NOTE: imgui_font has to be unused
|
// NOTE: imgui_font has to be unused
|
||||||
void extend_imgui_font_range(size_t font_index, const std::string &text);
|
// return true when extend range otherwise FALSE
|
||||||
|
ImFont *extend_imgui_font_range(size_t font_index, const std::string &text);
|
||||||
|
|
||||||
// Move to imgui utils
|
// Move to imgui utils
|
||||||
static bool is_text_in_ranges(const ImFont *font, const std::string &text);
|
static bool is_text_in_ranges(const ImFont *font, const std::string &text);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user