add read-only UI contentOffset property
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user