From 476287b5f26d28d7e0ddf8cfe728a4e4e4eff089 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 15 Mar 2019 01:06:27 +0100 Subject: [PATCH] Update imguicolortextedit. --- imguicolortextedit/TextEditor.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/imguicolortextedit/TextEditor.cpp b/imguicolortextedit/TextEditor.cpp index 4553658e..e3b878f1 100644 --- a/imguicolortextedit/TextEditor.cpp +++ b/imguicolortextedit/TextEditor.cpp @@ -269,7 +269,7 @@ TextEditor::Coordinates TextEditor::ScreenPosToCoordinates(const ImVec2& aPositi { cumulatedStringWidth[1] = cumulatedStringWidth[0]; cumulatedString += line[columnCoord].mChar; - cumulatedStringWidth[0] = ImGui::CalcTextSize(cumulatedString.c_str()).x; + cumulatedStringWidth[0] = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, cumulatedString.c_str(), nullptr, nullptr).x; columnWidth = (cumulatedStringWidth[0] - cumulatedStringWidth[1]); columnCoord++; } @@ -618,7 +618,7 @@ void TextEditor::HandleMouseInputs() void TextEditor::Render() { /* Compute mCharAdvance regarding to scaled font size (Ctrl + mouse wheel)*/ - const float fontSize = ImGui::CalcTextSize("#").x; + const float fontSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, "#", nullptr, nullptr).x; mCharAdvance = ImVec2(fontSize, ImGui::GetTextLineHeightWithSpacing() * mLineSpacing); /* Update palette with the current alpha from style */ @@ -653,12 +653,12 @@ void TextEditor::Render() // Deduce mTextStart by evaluating mLines size (global lineMax) plus two spaces as text width char buf[16]; snprintf(buf, 16, " %d ", globalLineMax); - mTextStart = ImGui::CalcTextSize(buf).x + mLeftMargin; + mTextStart = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buf, nullptr, nullptr).x + mLeftMargin; if (!mLines.empty()) { auto fontScale = ImGui::GetFontSize() / ImGui::GetFont()->FontSize; - float spaceSize = ImGui::CalcTextSize(" ").x + 1.0f * fontScale; + float spaceSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, " ", nullptr, nullptr).x; while (lineNo <= lineMax) { @@ -723,7 +723,8 @@ void TextEditor::Render() // Draw line number (right aligned) snprintf(buf, 16, "%d ", lineNo + 1); - auto lineNoWidth = ImGui::CalcTextSize(buf).x; + + auto lineNoWidth = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buf, nullptr, nullptr).x; drawList->AddText(ImVec2(lineStartScreenPos.x + mTextStart - lineNoWidth, lineStartScreenPos.y), mPalette[(int)PaletteIndex::LineNumber], buf); // Highlight the current line (where the cursor is) @@ -769,8 +770,8 @@ void TextEditor::Render() { const ImVec2 newOffset(textScreenPos.x + bufferOffset.x, textScreenPos.y + bufferOffset.y); drawList->AddText(newOffset, prevColor, buffer.c_str()); - auto textSize = ImGui::CalcTextSize(buffer.c_str()); - bufferOffset.x += textSize.x + 1.0f * fontScale; + auto textSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buffer.c_str(), nullptr, nullptr); + bufferOffset.x += textSize.x; buffer.clear(); } prevColor = color; @@ -1975,7 +1976,7 @@ float TextEditor::TextDistanceToLineStart(const Coordinates& aFrom) const auto& line = mLines[aFrom.mLine]; float distance = 0.0f; auto fontScale = ImGui::GetFontSize() / ImGui::GetFont()->FontSize; - float spaceSize = ImGui::CalcTextSize(" ").x + 1.0f * fontScale; + float spaceSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, " ", nullptr, nullptr).x; for (size_t it = 0u; it < line.size() && it < (unsigned)aFrom.mColumn; ++it) { if (line[it].mChar == '\t') @@ -1987,7 +1988,7 @@ float TextEditor::TextDistanceToLineStart(const Coordinates& aFrom) const char tempCString[2]; tempCString[0] = line[it].mChar; tempCString[1] = '\0'; - distance += ImGui::CalcTextSize(tempCString).x + 1.0f * fontScale; + distance += ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, tempCString, nullptr, nullptr).x; } }