From 17018c137f96b458c2bad5b7ddb0196b773c085c Mon Sep 17 00:00:00 2001 From: Bruno Herbelin Date: Fri, 31 Dec 2021 13:16:16 +0100 Subject: [PATCH] MultiLine text display --- ImGuiToolkit.cpp | 12 ++++++++++++ ImGuiToolkit.h | 1 + 2 files changed, 13 insertions(+) diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 428e01a..311d6b9 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -1721,3 +1721,15 @@ bool ImGuiToolkit::InputTextMultiline(const char* label, std::string* str, const } +void ImGuiToolkit::ShowTextMultiline(const char* label, const std::string &str, float width) +{ + size_t numlines = std::count(str.begin(), str.end(), '\n') + 1; + + ImGuiContext& g = *GImGui; + ImVec2 size(width, numlines * (g.FontSize + g.Style.ItemSpacing.y) + g.Style.FramePadding.y * 2.0f); + + ImGui::PushStyleColor(ImGuiCol_FrameBg, g.Style.Colors[ImGuiCol_FrameBgHovered]); + ImGui::InputTextMultiline(label, (char*)str.c_str(), str.capacity() + 1, size, ImGuiInputTextFlags_ReadOnly); + ImGui::PopStyleColor(); + +} diff --git a/ImGuiToolkit.h b/ImGuiToolkit.h index 73096e1..47edd3d 100644 --- a/ImGuiToolkit.h +++ b/ImGuiToolkit.h @@ -69,6 +69,7 @@ namespace ImGuiToolkit // text input bool InputText(const char* label, std::string* str); bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), int linesize = 0); + void ShowTextMultiline(const char* label, const std::string &str, float width); // accent color of UI typedef enum {