Merge branch 'main' into main

This commit is contained in:
Astazium 2026-10-15 16:19:06 +03:00 • committed by GitHub
commit bf59e520a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
109 changed files with 1908 additions and 474 deletions

View file

@ -25,14 +25,25 @@ void InlineFrame::setDocument(const std::shared_ptr<UiDocument>& document) {
if (document == nullptr) {
return;
}
auto newRoot = document->getRoot();
if (newRoot->hasParent()) {
return;
}
this->document = document;
this->root = document->getRoot();
this->root = std::move(newRoot);
add(root);
root->setSize(size);
gui.postRunnable([this]() {
scripting::on_ui_open(*this->document, {});
gui.postRunnable([weak = weak_from_this(), document]() {
auto node = weak.lock();
if (node == nullptr) {
return;
}
if (static_cast<InlineFrame&>(*node).document != document) {
return;
}
scripting::on_ui_open(*document, {});
});
}

View file

@ -120,7 +120,7 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
if (size.x <= 0 || size.y <= 0) {
return;
}
fbo = std::make_unique<Framebuffer>(size.x, size.y);
fbo = std::make_unique<Framebuffer>(size.x, size.y, true);
}
fbo->resize(size.x, size.y);
{
@ -130,7 +130,13 @@ void ModelViewer::draw(const DrawContext& pctx, const Assets& assets) {
ctx.setViewport({size.x, size.y});
ctx.setDepthTest(true);
ctx.setCullFace(true);
GLfloat clearColor[4];
glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
display::clear();
glClearColor(
clearColor[0], clearColor[1], clearColor[2], clearColor[3]
);
auto& ui3dShader = assets.require<Shader>("ui3d");
ui3dShader.use();

View file

@ -255,9 +255,9 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
// drawing caret here
if (isFocused() && editable && static_cast<int>((time - caretLastMove) * 2) % 2 == 0) {
uint line = label->getLineByTextIndex(caret);
auto linestart = label->getTextLineOffset(line);
uint lcaret = caret - label->getTextLineOffset(line);
int width = rawTextCache.metrics.calcWidth(input.substr(linestart), 0, lcaret);
size_t lineStart = label->getTextLineOffset(line);
size_t lineCaret = caret - lineStart;
int width = rawTextCache.metrics.calcWidth(input, lineStart, lineCaret);
batch->rect(
lcoord.x + width,
@ -275,11 +275,13 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
uint endLine = label->getLineByTextIndex(selectionEnd);
batch->setColor(glm::vec4(0.8f, 0.9f, 1.0f, 0.25f));
size_t startLineOffset = label->getTextLineOffset(startLine);
size_t endLineOffset = label->getTextLineOffset(endLine);
int start = rawTextCache.metrics.calcWidth(
labelText, 0, selectionStart - label->getTextLineOffset(startLine)
labelText, startLineOffset, selectionStart - startLineOffset
);
int end = rawTextCache.metrics.calcWidth(
labelText, 0, selectionEnd - label->getTextLineOffset(endLine)
labelText, endLineOffset, selectionEnd - endLineOffset
);
int lineY = label->getLineYOffset(startLine);
@ -352,6 +354,11 @@ void TextBox::draw(const DrawContext& pctx, const Assets& assets) {
}
void TextBox::drawBackground(const DrawContext& pctx, const Assets& assets) {
if (lineNumbersLabel->getFontName() != label->getFontName()) {
lineNumbersLabel->setFontName(label->getFontName());
}
lineNumbersLabel->setLineInterval(label->getLineInterval());
auto font = assets.getShared<Font>(label->getFontName());
if (font != nullptr) {
rawTextCache.prepare(font, font->getMetrics(), label->getSize().x);
@ -681,13 +688,19 @@ int TextBox::calcIndexAt(int x, int y) const {
uint line = label->getLineByYOffset(y - lcoord.y);
line = std::min(line, label->getLinesNumber() - 1);
size_t lineLength = getLineLength(line);
size_t lineStart = label->getTextLineOffset(line);
uint offset = 0;
while (lcoord.x + rawTextCache.metrics.calcWidth(labelText, 0, offset) < x &&
offset < lineLength - 1) {
while (offset < lineLength - 1) {
int width = rawTextCache.metrics.calcWidth(
labelText, lineStart, offset
);
if (lcoord.x + width >= x) {
break;
}
offset++;
}
return std::min(
offset + label->getTextLineOffset(line), labelText.length()
offset + lineStart, labelText.length()
);
}
@ -1224,9 +1237,12 @@ void TextBox::setCaret(size_t position) {
offset -= getSize().y;
scrolled(-glm::ceil(offset / static_cast<double>(scrollStep) + 0.5f));
}
int lcaret = caret - rawTextCache.getTextLineOffset(line);
int realoffset = rawTextCache.metrics.calcWidth(labelText, 0, lcaret) -
static_cast<int>(textOffset);
size_t lineStart = rawTextCache.getTextLineOffset(line);
size_t lineCaret = caret - lineStart;
int caretWidth = rawTextCache.metrics.calcWidth(
labelText, lineStart, lineCaret
);
int realoffset = caretWidth - static_cast<int>(textOffset);
if (realoffset - width > 0) {
setTextOffset(textOffset + realoffset - width);

View file

@ -60,6 +60,10 @@ bool UINode::isHover() const {
return hover;
}
bool UINode::hasParent() const {
return parent != nullptr;
}
void UINode::setParent(UINode* node) {
parent = node;
}
@ -376,14 +380,14 @@ void UINode::setGravity(Gravity gravity) {
}
}
bool UINode::isSubnodeOf(const UINode* node) {
bool UINode::isDescendantOf(const UINode* node) {
if (parent == nullptr) {
return false;
}
if (parent == node) {
return true;
}
return parent->isSubnodeOf(node);
return parent->isDescendantOf(node);
}
void UINode::getIndices(

View file

@ -176,6 +176,7 @@ namespace gui {
void setMouseOver(bool flag);
virtual void setParent(UINode* node);
bool hasParent() const;
UINode* getParent() const;
std::shared_ptr<UINode> getParentShared() const;
@ -290,7 +291,7 @@ namespace gui {
virtual void setGravity(Gravity gravity);
bool isSubnodeOf(const UINode* node);
bool isDescendantOf(const UINode* node);
/// @brief collect all nodes having id
static void getIndices(