mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-12 06:21:50 +00:00
fix multiline textbox wrappping
This commit is contained in:
parent
2db80051fd
commit
99c66c61bb
2 changed files with 14 additions and 9 deletions
|
|
@ -48,17 +48,18 @@ void LabelCache::update(std::wstring_view text, bool multiline, bool wrap) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (multiline) {
|
if (multiline) {
|
||||||
size_t len = 0;
|
size_t lineStart = 0;
|
||||||
for (size_t i = 0; i < text.length(); i++, len++) {
|
for (size_t i = 0; i < text.length(); i++) {
|
||||||
if (text[i] == L'\n') {
|
if (text[i] == L'\n') {
|
||||||
lines.push_back(LineScheme {i+1, false});
|
lines.push_back(LineScheme {i + 1, false});
|
||||||
len = 0;
|
lineStart = i + 1;
|
||||||
} else if (i > 0 && i+1 < text.length() && wrap && text[i+1] != L'\n') {
|
} else if (i + 1 < text.length() && wrap && text[i + 1] != L'\n') {
|
||||||
size_t width = metrics.calcWidth(text, i-len-1, i-(i-len)+2);
|
size_t width =
|
||||||
|
metrics.calcWidth(text, lineStart, i - lineStart + 2);
|
||||||
if (width >= wrapWidth) {
|
if (width >= wrapWidth) {
|
||||||
// starting a fake line
|
// starting a fake line
|
||||||
lines.push_back(LineScheme {i+1, true});
|
lines.push_back(LineScheme {i + 1, true});
|
||||||
len = 0;
|
lineStart = i + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -646,7 +646,11 @@ void TextBox::reposition() {
|
||||||
void TextBox::refresh() {
|
void TextBox::refresh() {
|
||||||
Container::refresh();
|
Container::refresh();
|
||||||
label->setSize(
|
label->setSize(
|
||||||
size - glm::vec2(padding.z + padding.x, padding.w + padding.y)
|
size - glm::vec2(
|
||||||
|
padding.z + padding.x +
|
||||||
|
LINE_NUMBERS_PANE_WIDTH * showLineNumbers + textOffset,
|
||||||
|
padding.w + padding.y
|
||||||
|
)
|
||||||
);
|
);
|
||||||
label->setPos(glm::vec2(
|
label->setPos(glm::vec2(
|
||||||
padding.x + LINE_NUMBERS_PANE_WIDTH * showLineNumbers + textInitX -
|
padding.x + LINE_NUMBERS_PANE_WIDTH * showLineNumbers + textInitX -
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue