add 'keep-line-selection' textbox attribute
This commit is contained in:
parent
fbc9ceece4
commit
aba18ef836
@ -231,7 +231,7 @@ TextBox::~TextBox() = default;
|
|||||||
void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
||||||
Container::draw(pctx, assets);
|
Container::draw(pctx, assets);
|
||||||
|
|
||||||
if (!isFocused()) {
|
if (!isFocused() && !keepLineSelection) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto& labelText = getText();
|
const auto& labelText = getText();
|
||||||
@ -252,7 +252,7 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
|
|
||||||
float time = gui.getWindow().time();
|
float time = gui.getWindow().time();
|
||||||
|
|
||||||
if (editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) {
|
if (isFocused() && editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) {
|
||||||
uint line = label->getLineByTextIndex(caret);
|
uint line = label->getLineByTextIndex(caret);
|
||||||
uint lcaret = caret - label->getTextLineOffset(line);
|
uint lcaret = caret - label->getTextLineOffset(line);
|
||||||
int width = rawTextCache.metrics.calcWidth(input, 0, lcaret);
|
int width = rawTextCache.metrics.calcWidth(input, 0, lcaret);
|
||||||
@ -308,42 +308,44 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isFocused() && multiline) {
|
if (!multiline) {
|
||||||
auto selectionCtx = subctx.sub(batch);
|
return;
|
||||||
selectionCtx.setBlendMode(BlendMode::addition);
|
|
||||||
|
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
|
||||||
|
|
||||||
uint line = label->getLineByTextIndex(caret);
|
|
||||||
while (label->isFakeLine(line)) {
|
|
||||||
line--;
|
|
||||||
}
|
|
||||||
do {
|
|
||||||
int lineY = label->getLineYOffset(line);
|
|
||||||
|
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.05f));
|
|
||||||
if (showLineNumbers) {
|
|
||||||
batch->rect(
|
|
||||||
lcoord.x - 8,
|
|
||||||
lcoord.y + lineY,
|
|
||||||
label->getSize().x,
|
|
||||||
lineHeight
|
|
||||||
);
|
|
||||||
batch->setColor(glm::vec4(1, 1, 1, 0.10f));
|
|
||||||
batch->rect(
|
|
||||||
lcoord.x - LINE_NUMBERS_PANE_WIDTH,
|
|
||||||
lcoord.y + lineY,
|
|
||||||
LINE_NUMBERS_PANE_WIDTH - 8,
|
|
||||||
lineHeight
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
batch->rect(
|
|
||||||
lcoord.x, lcoord.y + lineY, label->getSize().x, lineHeight
|
|
||||||
);
|
|
||||||
}
|
|
||||||
line++;
|
|
||||||
} while (line < label->getLinesNumber() && label->isFakeLine(line));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto selectionCtx = subctx.sub(batch);
|
||||||
|
selectionCtx.setBlendMode(BlendMode::addition);
|
||||||
|
|
||||||
|
batch->setColor(glm::vec4(1, 1, 1, 0.1f));
|
||||||
|
|
||||||
|
uint line = label->getLineByTextIndex(caret);
|
||||||
|
while (label->isFakeLine(line)) {
|
||||||
|
line--;
|
||||||
|
}
|
||||||
|
do {
|
||||||
|
int lineY = label->getLineYOffset(line);
|
||||||
|
|
||||||
|
batch->setColor(glm::vec4(1, 1, 1, 0.05f));
|
||||||
|
if (showLineNumbers) {
|
||||||
|
batch->rect(
|
||||||
|
lcoord.x - 8,
|
||||||
|
lcoord.y + lineY,
|
||||||
|
label->getSize().x,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
|
batch->setColor(glm::vec4(1, 1, 1, 0.10f));
|
||||||
|
batch->rect(
|
||||||
|
lcoord.x - LINE_NUMBERS_PANE_WIDTH,
|
||||||
|
lcoord.y + lineY,
|
||||||
|
LINE_NUMBERS_PANE_WIDTH - 8,
|
||||||
|
lineHeight
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
batch->rect(
|
||||||
|
lcoord.x, lcoord.y + lineY, label->getSize().x, lineHeight
|
||||||
|
);
|
||||||
|
}
|
||||||
|
line++;
|
||||||
|
} while (line < label->getLinesNumber() && label->isFakeLine(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::drawBackground(const DrawContext& pctx, const Assets& assets) {
|
void TextBox::drawBackground(const DrawContext& pctx, const Assets& assets) {
|
||||||
@ -605,6 +607,14 @@ size_t TextBox::getSelectionEnd() const {
|
|||||||
return selectionEnd;
|
return selectionEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TextBox::setKeepLineSelection(bool flag) {
|
||||||
|
keepLineSelection = flag;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextBox::isKeepLineSelection() const {
|
||||||
|
return keepLineSelection;
|
||||||
|
}
|
||||||
|
|
||||||
void TextBox::setOnEditStart(runnable oneditstart) {
|
void TextBox::setOnEditStart(runnable oneditstart) {
|
||||||
onEditStart = oneditstart;
|
onEditStart = oneditstart;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -62,6 +62,7 @@ namespace gui {
|
|||||||
bool editable = true;
|
bool editable = true;
|
||||||
bool autoresize = false;
|
bool autoresize = false;
|
||||||
bool showLineNumbers = false;
|
bool showLineNumbers = false;
|
||||||
|
bool keepLineSelection = false;
|
||||||
std::string markup;
|
std::string markup;
|
||||||
std::string syntax;
|
std::string syntax;
|
||||||
|
|
||||||
@ -222,6 +223,9 @@ namespace gui {
|
|||||||
size_t getSelectionStart() const;
|
size_t getSelectionStart() const;
|
||||||
size_t getSelectionEnd() const;
|
size_t getSelectionEnd() const;
|
||||||
|
|
||||||
|
void setKeepLineSelection(bool flag);
|
||||||
|
bool isKeepLineSelection() const;
|
||||||
|
|
||||||
/// @brief Set runnable called on textbox focus
|
/// @brief Set runnable called on textbox focus
|
||||||
virtual void setOnEditStart(runnable oneditstart);
|
virtual void setOnEditStart(runnable oneditstart);
|
||||||
|
|
||||||
|
|||||||
@ -573,6 +573,11 @@ static std::shared_ptr<UINode> read_text_box(
|
|||||||
if (element.has("line-numbers")) {
|
if (element.has("line-numbers")) {
|
||||||
textbox->setShowLineNumbers(element.attr("line-numbers").asBool());
|
textbox->setShowLineNumbers(element.attr("line-numbers").asBool());
|
||||||
}
|
}
|
||||||
|
if (element.has("keep-line-selection")) {
|
||||||
|
textbox->setKeepLineSelection(
|
||||||
|
element.attr("keep-line-selection").asBool()
|
||||||
|
);
|
||||||
|
}
|
||||||
if (element.has("markup")) {
|
if (element.has("markup")) {
|
||||||
textbox->setMarkup(element.attr("markup").getText());
|
textbox->setMarkup(element.attr("markup").getText());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user