From 133ce45aeb94f9e96fb76e9900cc3e4596947798 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Thu, 3 Mar 2022 16:26:50 +0100 Subject: [PATCH] Fix not rendered style image. e.g. can't load font --- src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp | 27 ++++++++++++++++--------- src/slic3r/Utils/FontManager.cpp | 9 +++++++-- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp index a0690cb90a..7624de78c8 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoEmboss.cpp @@ -1078,16 +1078,20 @@ void GLGizmoEmboss::draw_style_list() { const FontItem & fi = item.font_item; const std::string &actual_style_name = fi.name; 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); - ImGuiSelectableFlags_ flags = - ImGuiSelectableFlags_AllowItemOverlap; // allow click buttons - const FontManager::StyleImage &img = *item.image; - ImVec2 select_size(0.f, std::max(img.tex_size.y, m_gui_cfg->min_style_image_height)); - if (ImGui::Selectable("##style_select", is_selected, flags, select_size)) { + ImVec2 select_size(0,0); // 0,0 --> calculate in draw + std::string selectable_name = "##style_select"; // ## --> no visible + 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)) { process(); select_stored_font_item(); @@ -1107,8 +1111,11 @@ void GLGizmoEmboss::draw_style_list() { } // draw style name - ImGui::SameLine(); - ImGui::Image(img.texture_id, img.tex_size, img.uv0, img.uv1); + if (item.image.has_value()) { + const FontManager::StyleImage &img = *item.image; + ImGui::SameLine(); + ImGui::Image(img.texture_id, img.tex_size, img.uv0, img.uv1); + } // delete button ImGui::SameLine(m_gui_cfg->delete_pos_x); diff --git a/src/slic3r/Utils/FontManager.cpp b/src/slic3r/Utils/FontManager.cpp index 35767c8569..fc9808739b 100644 --- a/src/slic3r/Utils/FontManager.cpp +++ b/src/slic3r/Utils/FontManager.cpp @@ -466,6 +466,7 @@ void FontManager::init_style_images(int max_width) { int offset_y = 0; int width = 0; for (Item &item : m_font_list) { + if (!item.image.has_value()) continue; StyleImage &image = *item.image; image.offset.y() = offset_y; offset_y += image.tex_size.y+1; @@ -474,6 +475,7 @@ void FontManager::init_style_images(int max_width) { } int height = offset_y; for (Item &item : m_font_list) { + if (!item.image.has_value()) continue; StyleImage &image = *item.image; const Point &o = image.offset; const ImVec2 &s = image.tex_size; @@ -497,10 +499,13 @@ void FontManager::init_style_images(int max_width) { // set up texture 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 - for (Item &item : m_font_list) { + for (Item &item : m_font_list) { + if (!item.image.has_value()) continue; StyleImage &image = *item.image; sla::Resolution resolution(image.tex_size.x, image.tex_size.y);