add read-only UI contentOffset property

This commit is contained in:
MihailRis
2024-10-15 05:56:15 +03:00
parent fbca439b2d
commit 08ebfa15db
7 changed files with 86 additions and 79 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ namespace gui {
virtual void scrolled(int value) override;
virtual void setScrollable(bool flag);
void listenInterval(float interval, ontimeout callback, int repeat=-1);
virtual glm::vec2 contentOffset() override {return glm::vec2(0.0f, scroll);};
virtual glm::vec2 getContentOffset() override {return glm::vec2(0.0f, scroll);};
virtual void setSize(glm::vec2 size) override;
virtual void refresh() override;
+1 -1
View File
@@ -646,7 +646,7 @@ void TextBox::setCaret(size_t position) {
caretLastMove = Window::time();
int width = label->getSize().x;
uint line = label->getLineByTextIndex(caret);
int offset = label->getLineYOffset(line) + contentOffset().y;
int offset = label->getLineYOffset(line) + getContentOffset().y;
uint lineHeight = font->getLineHeight()*label->getLineInterval();
scrollStep = lineHeight;
if (offset < 0) {
+1 -1
View File
@@ -152,7 +152,7 @@ float UINode::getTooltipDelay() const {
glm::vec2 UINode::calcPos() const {
if (parent) {
return pos + parent->calcPos() + parent->contentOffset();
return pos + parent->calcPos() + parent->getContentOffset();
}
return pos;
}
+1 -1
View File
@@ -209,7 +209,7 @@ namespace gui {
virtual glm::vec4 calcColor() const;
/// @brief Get inner content offset. Used for scroll
virtual glm::vec2 contentOffset() {return glm::vec2(0.0f);};
virtual glm::vec2 getContentOffset() {return glm::vec2(0.0f);};
/// @brief Calculate screen position of the element
virtual glm::vec2 calcPos() const;
virtual void setPos(glm::vec2 pos);
+5
View File
@@ -292,6 +292,10 @@ static int p_set_interval(UINode* node, lua::State* L) {
return 0;
}
static int p_get_content_offset(UINode* node, lua::State* L) {
return lua::pushvec(L, node->getContentOffset());
}
static int p_get_color(UINode* node, lua::State* L) {
return lua::pushcolor(L, node->getColor());
}
@@ -344,6 +348,7 @@ static int l_gui_getattr(lua::State* L) {
{"color", p_get_color},
{"hoverColor", p_get_hover_color},
{"pressedColor", p_get_pressed_color},
{"contentOffset", p_get_content_offset},
{"tooltip", p_get_tooltip},
{"tooltipDelay", p_get_tooltip_delay},
{"pos", p_get_pos},