ENH:Bold font for preview title

Change-Id: I75c9b1ad0b1b7b07650b2038dbbc101b5a4fb4d7
This commit is contained in:
xiangdong.yang 2022-08-11 11:16:13 +08:00 committed by Lane.Wei
parent afc1395828
commit aa59c93eb5
3 changed files with 38 additions and 5 deletions

View file

@ -4160,10 +4160,10 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
auto append_headers = [&imgui](const std::array<std::string, 5>& texts, const std::array<float, 4>& offsets) {
size_t i = 0;
for (; i < offsets.size(); i++) {
imgui.text(texts[i]);
imgui.bold_text(texts[i]);
ImGui::SameLine(offsets[i]);
}
imgui.text(texts[i]);
imgui.bold_text(texts[i]);
ImGui::Separator();
};
@ -4267,7 +4267,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
ImGui::PopStyleColor(3);
ImGui::PopStyleVar(1);
ImGui::SameLine();
ImGui::Text(_u8L("Color Scheme").c_str());
imgui.bold_text(_u8L("Color Scheme"));
push_combo_style();
ImGui::SameLine();

View file

@ -1526,9 +1526,26 @@ void ImGuiWrapper::search_list(const ImVec2& size_, bool (*items_getter)(int, co
// check_box(_L("Search in English"), view_params.english);
}
void ImGuiWrapper::bold_text(const std::string& str)
{
if (bold_font){
ImGui::PushFont(bold_font);
text(str);
ImGui::PopFont();
} else {
text(str);
}
}
void ImGuiWrapper::title(const std::string& str)
{
text(str);
if (bold_font){
ImGui::PushFont(bold_font);
text(str);
ImGui::PopFont();
} else {
text(str);
}
ImGui::Separator();
}
@ -1690,6 +1707,7 @@ void ImGuiWrapper::init_font(bool compress)
//FIXME replace with io.Fonts->AddFontFromMemoryTTF(buf_decompressed_data, (int)buf_decompressed_size, m_font_size, nullptr, ranges.Data);
//https://github.com/ocornut/imgui/issues/220
ImFont* font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + "HarmonyOS_Sans_SC_Regular.ttf").c_str(), m_font_size, nullptr, ranges.Data);
if (font == nullptr) {
font = io.Fonts->AddFontDefault();
if (font == nullptr) {
@ -1697,6 +1715,15 @@ void ImGuiWrapper::init_font(bool compress)
}
}
ImFontConfig cfg = ImFontConfig();
cfg.OversampleH = 1;
bold_font = io.Fonts->AddFontFromFileTTF((Slic3r::resources_dir() + "/fonts/" + "HarmonyOS_Sans_SC_Bold.ttf").c_str(), m_font_size, &cfg);
if (bold_font == nullptr) {
bold_font = io.Fonts->AddFontDefault();
if (bold_font == nullptr) { throw Slic3r::RuntimeError("ImGui: Could not load deafult font"); }
}
#ifdef __APPLE__
ImFontConfig config;
config.MergeMode = true;

View file

@ -147,7 +147,12 @@ public:
bool combo(const wxString& label, const std::vector<std::string>& options, int& selection); // Use -1 to not mark any option as selected
bool undo_redo_list(const ImVec2& size, const bool is_undo, bool (*items_getter)(const bool, int, const char**), int& hovered, int& selected, int& mouse_wheel);
void search_list(const ImVec2& size, bool (*items_getter)(int, const char** label, const char** tooltip), char* search_str,
Search::OptionViewParameters& view_params, int& selected, bool& edited, int& mouse_wheel, bool is_localized);
Search::OptionViewParameters &view_params,
int & selected,
bool & edited,
int & mouse_wheel,
bool is_localized);
void bold_text(const std::string &str);
void title(const std::string& str);
void disabled_begin(bool disabled);
@ -204,6 +209,7 @@ private:
static void clipboard_set(void* user_data, const char* text);
LastSliderStatus m_last_slider_status;
ImFont* bold_font = nullptr;
};
class IMTexture