Fix not rendered style image. e.g. can't load font

This commit is contained in:
Filip Sykala 2022-03-03 16:26:50 +01:00
parent f35065b77f
commit 133ce45aeb
2 changed files with 24 additions and 12 deletions

View File

@ -1078,16 +1078,20 @@ void GLGizmoEmboss::draw_style_list() {
const FontItem & fi = item.font_item; const FontItem & fi = item.font_item;
const std::string &actual_style_name = fi.name; const std::string &actual_style_name = fi.name;
ImGui::PushID(actual_style_name.c_str()); ImGui::PushID(actual_style_name.c_str());
std::string name_truncated =
ImGuiWrapper::trunc(actual_style_name, max_width);
bool is_selected = (&fi == &actual_font_item); bool is_selected = (&fi == &actual_font_item);
ImGuiSelectableFlags_ flags =
ImGuiSelectableFlags_AllowItemOverlap; // allow click buttons
const FontManager::StyleImage &img = *item.image; ImVec2 select_size(0,0); // 0,0 --> calculate in draw
ImVec2 select_size(0.f, std::max(img.tex_size.y, m_gui_cfg->min_style_image_height)); std::string selectable_name = "##style_select"; // ## --> no visible
if (ImGui::Selectable("##style_select", is_selected, flags, select_size)) { if (item.image.has_value()) {
const FontManager::StyleImage &img = *item.image;
select_size = ImVec2(0.f, std::max(img.tex_size.y, m_gui_cfg->min_style_image_height));
} else {
selectable_name = ImGuiWrapper::trunc(actual_style_name, max_width);
}
// allow click delete button
ImGuiSelectableFlags_ flags = ImGuiSelectableFlags_AllowItemOverlap;
if (ImGui::Selectable(selectable_name.c_str(), is_selected, flags, select_size)) {
if (m_font_manager.load_font(index)) { if (m_font_manager.load_font(index)) {
process(); process();
select_stored_font_item(); select_stored_font_item();
@ -1107,8 +1111,11 @@ void GLGizmoEmboss::draw_style_list() {
} }
// draw style name // draw style name
ImGui::SameLine(); if (item.image.has_value()) {
ImGui::Image(img.texture_id, img.tex_size, img.uv0, img.uv1); const FontManager::StyleImage &img = *item.image;
ImGui::SameLine();
ImGui::Image(img.texture_id, img.tex_size, img.uv0, img.uv1);
}
// delete button // delete button
ImGui::SameLine(m_gui_cfg->delete_pos_x); ImGui::SameLine(m_gui_cfg->delete_pos_x);

View File

@ -466,6 +466,7 @@ void FontManager::init_style_images(int max_width) {
int offset_y = 0; int offset_y = 0;
int width = 0; int width = 0;
for (Item &item : m_font_list) { for (Item &item : m_font_list) {
if (!item.image.has_value()) continue;
StyleImage &image = *item.image; StyleImage &image = *item.image;
image.offset.y() = offset_y; image.offset.y() = offset_y;
offset_y += image.tex_size.y+1; offset_y += image.tex_size.y+1;
@ -474,6 +475,7 @@ void FontManager::init_style_images(int max_width) {
} }
int height = offset_y; int height = offset_y;
for (Item &item : m_font_list) { for (Item &item : m_font_list) {
if (!item.image.has_value()) continue;
StyleImage &image = *item.image; StyleImage &image = *item.image;
const Point &o = image.offset; const Point &o = image.offset;
const ImVec2 &s = image.tex_size; const ImVec2 &s = image.tex_size;
@ -497,10 +499,13 @@ void FontManager::init_style_images(int max_width) {
// set up texture id // set up texture id
void *texture_id = (void *)(intptr_t) tex_id; void *texture_id = (void *)(intptr_t) tex_id;
for (Item &item : m_font_list) item.image->texture_id = texture_id; for (Item &item : m_font_list)
if (item.image.has_value())
item.image->texture_id = texture_id;
// upload sub textures // upload sub textures
for (Item &item : m_font_list) { for (Item &item : m_font_list) {
if (!item.image.has_value()) continue;
StyleImage &image = *item.image; StyleImage &image = *item.image;
sla::Resolution resolution(image.tex_size.x, image.tex_size.y); sla::Resolution resolution(image.tex_size.x, image.tex_size.y);