mirror of
https://github.com/wolfpld/tracy.git
synced 2025-03-20 07:40:02 +08:00
Update imguicolortextedit.
This commit is contained in:
parent
a10ec49a60
commit
476287b5f2
@ -269,7 +269,7 @@ TextEditor::Coordinates TextEditor::ScreenPosToCoordinates(const ImVec2& aPositi
|
|||||||
{
|
{
|
||||||
cumulatedStringWidth[1] = cumulatedStringWidth[0];
|
cumulatedStringWidth[1] = cumulatedStringWidth[0];
|
||||||
cumulatedString += line[columnCoord].mChar;
|
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]);
|
columnWidth = (cumulatedStringWidth[0] - cumulatedStringWidth[1]);
|
||||||
columnCoord++;
|
columnCoord++;
|
||||||
}
|
}
|
||||||
@ -618,7 +618,7 @@ void TextEditor::HandleMouseInputs()
|
|||||||
void TextEditor::Render()
|
void TextEditor::Render()
|
||||||
{
|
{
|
||||||
/* Compute mCharAdvance regarding to scaled font size (Ctrl + mouse wheel)*/
|
/* 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);
|
mCharAdvance = ImVec2(fontSize, ImGui::GetTextLineHeightWithSpacing() * mLineSpacing);
|
||||||
|
|
||||||
/* Update palette with the current alpha from style */
|
/* 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
|
// Deduce mTextStart by evaluating mLines size (global lineMax) plus two spaces as text width
|
||||||
char buf[16];
|
char buf[16];
|
||||||
snprintf(buf, 16, " %d ", globalLineMax);
|
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())
|
if (!mLines.empty())
|
||||||
{
|
{
|
||||||
auto fontScale = ImGui::GetFontSize() / ImGui::GetFont()->FontSize;
|
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)
|
while (lineNo <= lineMax)
|
||||||
{
|
{
|
||||||
@ -723,7 +723,8 @@ void TextEditor::Render()
|
|||||||
|
|
||||||
// Draw line number (right aligned)
|
// Draw line number (right aligned)
|
||||||
snprintf(buf, 16, "%d ", lineNo + 1);
|
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);
|
drawList->AddText(ImVec2(lineStartScreenPos.x + mTextStart - lineNoWidth, lineStartScreenPos.y), mPalette[(int)PaletteIndex::LineNumber], buf);
|
||||||
|
|
||||||
// Highlight the current line (where the cursor is)
|
// 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);
|
const ImVec2 newOffset(textScreenPos.x + bufferOffset.x, textScreenPos.y + bufferOffset.y);
|
||||||
drawList->AddText(newOffset, prevColor, buffer.c_str());
|
drawList->AddText(newOffset, prevColor, buffer.c_str());
|
||||||
auto textSize = ImGui::CalcTextSize(buffer.c_str());
|
auto textSize = ImGui::GetFont()->CalcTextSizeA(ImGui::GetFontSize(), FLT_MAX, -1.0f, buffer.c_str(), nullptr, nullptr);
|
||||||
bufferOffset.x += textSize.x + 1.0f * fontScale;
|
bufferOffset.x += textSize.x;
|
||||||
buffer.clear();
|
buffer.clear();
|
||||||
}
|
}
|
||||||
prevColor = color;
|
prevColor = color;
|
||||||
@ -1975,7 +1976,7 @@ float TextEditor::TextDistanceToLineStart(const Coordinates& aFrom) const
|
|||||||
auto& line = mLines[aFrom.mLine];
|
auto& line = mLines[aFrom.mLine];
|
||||||
float distance = 0.0f;
|
float distance = 0.0f;
|
||||||
auto fontScale = ImGui::GetFontSize() / ImGui::GetFont()->FontSize;
|
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)
|
for (size_t it = 0u; it < line.size() && it < (unsigned)aFrom.mColumn; ++it)
|
||||||
{
|
{
|
||||||
if (line[it].mChar == '\t')
|
if (line[it].mChar == '\t')
|
||||||
@ -1987,7 +1988,7 @@ float TextEditor::TextDistanceToLineStart(const Coordinates& aFrom) const
|
|||||||
char tempCString[2];
|
char tempCString[2];
|
||||||
tempCString[0] = line[it].mChar;
|
tempCString[0] = line[it].mChar;
|
||||||
tempCString[1] = '\0';
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user