add read-only UI contentOffset property
This commit is contained in:
parent
fbca439b2d
commit
08ebfa15db
@ -19,7 +19,7 @@ The element id cannot be changed from a script.
|
|||||||
The following tables will use abbreviated type descriptions, such as:
|
The following tables will use abbreviated type descriptions, such as:
|
||||||
- vec2 - an array of two numbers.
|
- vec2 - an array of two numbers.
|
||||||
- ivec2 - an array of two integers.
|
- ivec2 - an array of two integers.
|
||||||
- rgba - an array of four integers in the range *\[0..255\]* denoting RGBA constituent colors.
|
- rgba - an array of four integers in the range `[0..255]` denoting RGBA constituent colors.
|
||||||
|
|
||||||
Element methods, according to OOP features in Lua, are called using the `:` operator instead of `.`
|
Element methods, according to OOP features in Lua, are called using the `:` operator instead of `.`
|
||||||
|
|
||||||
@ -32,28 +32,29 @@ document["worlds-panel"]:clear()
|
|||||||
|
|
||||||
Properties that apply to all elements:
|
Properties that apply to all elements:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| ------------ | ------ | ------- | ------ | ------------------------------------------- |
|
| ------------- | ------ | ---- | ----- | ------------------------------------------- |
|
||||||
| id | string | yes | *no* | element id |
|
| id | string | yes | *no* | element id |
|
||||||
| pos | vec2 | yes | yes | element position inside a container |
|
| pos | vec2 | yes | yes | element position inside a container |
|
||||||
| wpos | vec2 | yes | yes | element position inside the window |
|
| wpos | vec2 | yes | yes | element position inside the window |
|
||||||
| size | vec2 | yes | yes | element size |
|
| size | vec2 | yes | yes | element size |
|
||||||
| interactive | bool | yes | yes | ability to interact with the element |
|
| interactive | bool | yes | yes | ability to interact with the element |
|
||||||
| enabled | bool | yes | yes | visually indicated version of *interactive* |
|
| enabled | bool | yes | yes | visually indicated version of *interactive* |
|
||||||
| visible | bool | yes | yes | element visibility |
|
| visible | bool | yes | yes | element visibility |
|
||||||
| focused | bool | yes | yes | focus on element |
|
| focused | bool | yes | yes | focus on element |
|
||||||
| color | rgba | yes | yes | element color |
|
| color | rgba | yes | yes | element color |
|
||||||
| hoverColor | rgba | yes | yes | hover color |
|
| hoverColor | rgba | yes | yes | hover color |
|
||||||
| pressedColor | rgba | yes | yes | color when pressed |
|
| pressedColor | rgba | yes | yes | color when pressed |
|
||||||
| tooltip | string | yes | yes | tooltip text |
|
| tooltip | string | yes | yes | tooltip text |
|
||||||
| tooltipDelay | float | yes | yes | tooltip delay |
|
| tooltipDelay | float | yes | yes | tooltip delay |
|
||||||
|
| contentOffset | vec2 | yes | *no* | element content offset |
|
||||||
|
|
||||||
Common element methods:
|
Common element methods:
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
| ------------------- | ----------------------------------------------------------------------- |
|
| ------------------- | ----------------------------------------------------------------------------------- |
|
||||||
| moveInto(container) | moves the element to the specified container (the element is specified, not the id) |
|
| moveInto(container) | moves the element to the specified container (the element is specified, not the id) |
|
||||||
| destruct() | removes element |
|
| destruct() | removes element |
|
||||||
|
|
||||||
## Containers
|
## Containers
|
||||||
|
|
||||||
@ -69,86 +70,86 @@ Common methods for containers (elements: container, panel, button, pagebox):
|
|||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| ----------- | ------ | ------- | ------ | ------------------------------------------------------------------------------------ |
|
| ----------- | ------ | ---- | ----- | ------------------------------------------------------------------------------------ |
|
||||||
| text | string | yes | yes | entered text or placeholder |
|
| text | string | yes | yes | entered text or placeholder |
|
||||||
| placeholder | string | yes | yes | placeholder (used if nothing has been entered) |
|
| placeholder | string | yes | yes | placeholder (used if nothing has been entered) |
|
||||||
| caret | int | yes | yes | carriage position. `textbox.caret = -1` will set the position to the end of the text |
|
| caret | int | yes | yes | carriage position. `textbox.caret = -1` will set the position to the end of the text |
|
||||||
| editable | bool | yes | yes | text mutability |
|
| editable | bool | yes | yes | text mutability |
|
||||||
| multiline | bool | yes | yes | multiline support |
|
| multiline | bool | yes | yes | multiline support |
|
||||||
| textWrap | bool | yes | yes | automatic text wrapping (only with multiline: "true") |
|
| textWrap | bool | yes | yes | automatic text wrapping (only with multiline: "true") |
|
||||||
| valid | bool | yes | no | is the entered text correct |
|
| valid | bool | yes | no | is the entered text correct |
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
| ----------- | -------------------------------------------- |
|
| ----------- | ------------------------------------------------ |
|
||||||
| paste(text) | inserts the specified text at the caret position |
|
| paste(text) | inserts the specified text at the caret position |
|
||||||
|
|
||||||
## Slider (trackbar)
|
## Slider (trackbar)
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| ---------- | ----- | ------- | ------ | --------------------- |
|
| ---------- | ----- | ---- | ----- | --------------------- |
|
||||||
| value | float | yes | yes | current value |
|
| value | float | yes | yes | current value |
|
||||||
| min | float | yes | yes | minimum value |
|
| min | float | yes | yes | minimum value |
|
||||||
| max | float | yes | yes | maximum value |
|
| max | float | yes | yes | maximum value |
|
||||||
| step | float | yes | yes | division step |
|
| step | float | yes | yes | division step |
|
||||||
| trackWidth | float | yes | yes | control element width |
|
| trackWidth | float | yes | yes | control element width |
|
||||||
| trackColor | rgba | yes | yes | control element color |
|
| trackColor | rgba | yes | yes | control element color |
|
||||||
|
|
||||||
## Menu (pagebox)
|
## Menu (pagebox)
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| -------- | ------ | ------ | ------ | ---------------- |
|
| ----- | ------ | ---- | ----- | ------------ |
|
||||||
| page | string | yes | yes | current page |
|
| page | string | yes | yes | current page |
|
||||||
|
|
||||||
Methods:
|
Methods:
|
||||||
|
|
||||||
| Method | Description |
|
| Method | Description |
|
||||||
| ------- | ------------------------------------------ |
|
| ------- | --------------------------------- |
|
||||||
| back() | switches to previous page |
|
| back() | switches to previous page |
|
||||||
| reset() | resets page and switching history |
|
| reset() | resets page and switching history |
|
||||||
|
|
||||||
## Checkbox
|
## Checkbox
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| -------- | ---- | ------ | ------ | ----------------- |
|
| ------- | ---- | ---- | ----- | ----------- |
|
||||||
| checked | bool | yes | yes | mark status |
|
| checked | bool | yes | yes | mark status |
|
||||||
|
|
||||||
## Button
|
## Button
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| -------- | ------ | ------ | ------ | ------------ |
|
| ----- | ------ | ---- | ----- | ------------ |
|
||||||
| text | string | yes | yes | button text |
|
| text | string | yes | yes | button text |
|
||||||
|
|
||||||
## Label
|
## Label
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| -------- | ------ | ------ | ------ | ----------- |
|
| ----- | ------ | ---- | ----- | ----------- |
|
||||||
| text | string | yes | yes | label text |
|
| text | string | yes | yes | label text |
|
||||||
|
|
||||||
## Image
|
## Image
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| ----- | ------ | ------- | ------ | ------------ |
|
| ----- | ------ | ---- | ----- | ------------ |
|
||||||
| src | string | yes | yes | texture name |
|
| src | string | yes | yes | texture name |
|
||||||
|
|
||||||
## Inventory
|
## Inventory
|
||||||
|
|
||||||
Properties:
|
Properties:
|
||||||
|
|
||||||
| Title | Type | Reading | Record | Description |
|
| Title | Type | Read | Write | Description |
|
||||||
| --------- | ---- | ------- | ------ | ------------------------------------------------- |
|
| --------- | ---- | ---- | ----- | ------------------------------------------------- |
|
||||||
| inventory | int | yes | yes | id of the inventory to which the element is bound |
|
| inventory | int | yes | yes | id of the inventory to which the element is bound |
|
||||||
|
|||||||
@ -19,7 +19,7 @@ Id элемента не может быть изменен из скрипта.
|
|||||||
В таблицах далее будут использоваться сокращенные описания типов, такие как:
|
В таблицах далее будут использоваться сокращенные описания типов, такие как:
|
||||||
- vec2 - массив из двух дробных чисел.
|
- vec2 - массив из двух дробных чисел.
|
||||||
- ivec2 - массив из двух целых чисел.
|
- ivec2 - массив из двух целых чисел.
|
||||||
- rgba - массив из четырех дробных чисел в диапазоне *\[0..255\]* обозначающий RGBA состовляющие цвета.
|
- rgba - массив из четырех дробных чисел в диапазоне `[0..255]` обозначающий RGBA состовляющие цвета.
|
||||||
|
|
||||||
Методы элементов, согласно особенностям ООП в Lua вызываются с использованием оператора `:` вместо `.`
|
Методы элементов, согласно особенностям ООП в Lua вызываются с использованием оператора `:` вместо `.`
|
||||||
|
|
||||||
@ -32,21 +32,22 @@ document["worlds-panel"]:clear()
|
|||||||
|
|
||||||
Свойства, относящиеся ко всем элементам:
|
Свойства, относящиеся ко всем элементам:
|
||||||
|
|
||||||
| Название | Тип | Чтение | Запись | Описание |
|
| Название | Тип | Чтение | Запись | Описание |
|
||||||
| ------------ | ------ | ------ | ------ | ----------------------------------------- |
|
| ------------- | ------ | ------ | ------ | ----------------------------------------- |
|
||||||
| id | string | да | *нет* | идентификатор элемента |
|
| id | string | да | *нет* | идентификатор элемента |
|
||||||
| pos | vec2 | да | да | позиция элемента внутри контейнера |
|
| pos | vec2 | да | да | позиция элемента внутри контейнера |
|
||||||
| wpos | vec2 | да | да | позиция элемента в окне |
|
| wpos | vec2 | да | да | позиция элемента в окне |
|
||||||
| size | vec2 | да | да | размер элемента |
|
| size | vec2 | да | да | размер элемента |
|
||||||
| interactive | bool | да | да | возможность взаимодействия с элементом |
|
| interactive | bool | да | да | возможность взаимодействия с элементом |
|
||||||
| enabled | bool | да | да | визуально обозначаемая версия interactive |
|
| enabled | bool | да | да | визуально обозначаемая версия interactive |
|
||||||
| visible | bool | да | да | видимость элемента |
|
| visible | bool | да | да | видимость элемента |
|
||||||
| focused | bool | да | да | фокус на элементе |
|
| focused | bool | да | да | фокус на элементе |
|
||||||
| color | rgba | да | да | цвет элемента |
|
| color | rgba | да | да | цвет элемента |
|
||||||
| hoverColor | rgba | да | да | цвет при наведении |
|
| hoverColor | rgba | да | да | цвет при наведении |
|
||||||
| pressedColor | rgba | да | да | цвет при нажатии |
|
| pressedColor | rgba | да | да | цвет при нажатии |
|
||||||
| tooltip | string | да | да | текст всплывающей подсказки |
|
| tooltip | string | да | да | текст всплывающей подсказки |
|
||||||
| tooltipDelay | float | да | да | задержка всплывающей подсказки |
|
| tooltipDelay | float | да | да | задержка всплывающей подсказки |
|
||||||
|
| contentOffset | vec2 | да | *нет* | смещение содержимого |
|
||||||
|
|
||||||
Общие методы элементов:
|
Общие методы элементов:
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ namespace gui {
|
|||||||
virtual void scrolled(int value) override;
|
virtual void scrolled(int value) override;
|
||||||
virtual void setScrollable(bool flag);
|
virtual void setScrollable(bool flag);
|
||||||
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
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 setSize(glm::vec2 size) override;
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
|
|
||||||
|
|||||||
@ -646,7 +646,7 @@ void TextBox::setCaret(size_t position) {
|
|||||||
caretLastMove = Window::time();
|
caretLastMove = Window::time();
|
||||||
int width = label->getSize().x;
|
int width = label->getSize().x;
|
||||||
uint line = label->getLineByTextIndex(caret);
|
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();
|
uint lineHeight = font->getLineHeight()*label->getLineInterval();
|
||||||
scrollStep = lineHeight;
|
scrollStep = lineHeight;
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
|
|||||||
@ -152,7 +152,7 @@ float UINode::getTooltipDelay() const {
|
|||||||
|
|
||||||
glm::vec2 UINode::calcPos() const {
|
glm::vec2 UINode::calcPos() const {
|
||||||
if (parent) {
|
if (parent) {
|
||||||
return pos + parent->calcPos() + parent->contentOffset();
|
return pos + parent->calcPos() + parent->getContentOffset();
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -209,7 +209,7 @@ namespace gui {
|
|||||||
virtual glm::vec4 calcColor() const;
|
virtual glm::vec4 calcColor() const;
|
||||||
|
|
||||||
/// @brief Get inner content offset. Used for scroll
|
/// @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
|
/// @brief Calculate screen position of the element
|
||||||
virtual glm::vec2 calcPos() const;
|
virtual glm::vec2 calcPos() const;
|
||||||
virtual void setPos(glm::vec2 pos);
|
virtual void setPos(glm::vec2 pos);
|
||||||
|
|||||||
@ -292,6 +292,10 @@ static int p_set_interval(UINode* node, lua::State* L) {
|
|||||||
return 0;
|
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) {
|
static int p_get_color(UINode* node, lua::State* L) {
|
||||||
return lua::pushcolor(L, node->getColor());
|
return lua::pushcolor(L, node->getColor());
|
||||||
}
|
}
|
||||||
@ -344,6 +348,7 @@ static int l_gui_getattr(lua::State* L) {
|
|||||||
{"color", p_get_color},
|
{"color", p_get_color},
|
||||||
{"hoverColor", p_get_hover_color},
|
{"hoverColor", p_get_hover_color},
|
||||||
{"pressedColor", p_get_pressed_color},
|
{"pressedColor", p_get_pressed_color},
|
||||||
|
{"contentOffset", p_get_content_offset},
|
||||||
{"tooltip", p_get_tooltip},
|
{"tooltip", p_get_tooltip},
|
||||||
{"tooltipDelay", p_get_tooltip_delay},
|
{"tooltipDelay", p_get_tooltip_delay},
|
||||||
{"pos", p_get_pos},
|
{"pos", p_get_pos},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user