Merge pull request #491 from MihailRis/scroll-container-property

'scroll' container property
This commit is contained in:
MihailRis 2025-03-21 05:48:24 +03:00 committed by GitHub
commit 31c66e65d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 36 additions and 2 deletions

View File

@ -60,7 +60,13 @@ Common element methods:
## Containers
Common methods for containers (elements: container, panel, button, pagebox):
Common properties for containers (elements: container, panel, button, pagebox):
| Name | Type | Read | Write | Description |
| ------ | ------ | ---- | ----- | --------------- |
| scroll | string | yes | yes | scroll contents |
Common methods:
| Method | Description |
| ------------------------------- | -------------------------------------------------------------------------------------------- |

View File

@ -60,7 +60,13 @@ document["worlds-panel"]:clear()
## Контейнеры
Общие для контейнеров методы (элементы: container, panel, button, pagebox):
Свойства, относящиеся к контейнерам (элементы: container, panel, button, pagebox):
| Название | Тип | Чтение | Запись | Описание |
| ------------- | ------ | ------ | ------ | ----------------------------------------- |
| scroll | string | да | да | прокрутка содержимого |
Методы:
| Метод | Описание |
| ------------------------------- | ------------------------------------------------------------------------------------------- |

View File

@ -87,6 +87,7 @@ end
function build_files_list(filenames, selected)
local files_list = document.filesList
files_list.scroll = 0
files_list:clear()
for _, actual_filename in ipairs(filenames) do

View File

@ -226,6 +226,10 @@ void Container::refresh() {
});
}
void Container::setScroll(int scroll) {
this->scroll = scroll;
}
const std::vector<std::shared_ptr<UINode>>& Container::getNodes() const {
return nodes;
}

View File

@ -42,6 +42,7 @@ namespace gui {
virtual int getScrollStep() const;
virtual void setScrollStep(int step);
virtual void refresh() override;
void setScroll(int scroll);
virtual void mouseMove(GUI*, int x, int y) override;
virtual void mouseRelease(GUI*, int x, int y) override;

View File

@ -423,6 +423,13 @@ static int p_get_cursor(UINode* node, lua::State* L) {
return lua::pushstring(L, to_string(node->getCursor()));
}
static int p_get_scroll(UINode* node, lua::State* L) {
if (auto container = dynamic_cast<Container*>(node)) {
return lua::pushnumber(L, container->getContentOffset().y);
}
return 0;
}
static int l_gui_getattr(lua::State* L) {
auto docname = lua::require_string(L, 1);
auto element = lua::require_string(L, 2);
@ -469,6 +476,7 @@ static int l_gui_getattr(lua::State* L) {
{"min", p_get_min},
{"max", p_get_max},
{"step", p_get_step},
{"scroll", p_get_scroll},
{"trackWidth", p_get_track_width},
{"trackColor", p_get_track_color},
{"textColor", p_get_text_color},
@ -655,6 +663,13 @@ static void p_set_cursor(UINode* node, lua::State* L, int idx) {
}
}
static int p_set_scroll(UINode* node, lua::State* L, int idx) {
if (auto container = dynamic_cast<Container*>(node)) {
container->setScroll(lua::tointeger(L, idx));
}
return 0;
}
static int l_gui_setattr(lua::State* L) {
auto docname = lua::require_string(L, 1);
auto element = lua::require_string(L, 2);
@ -692,6 +707,7 @@ static int l_gui_setattr(lua::State* L) {
{"min", p_set_min},
{"max", p_set_max},
{"step", p_set_step},
{"scroll", p_set_scroll},
{"trackWidth", p_set_track_width},
{"trackColor", p_set_track_color},
{"textColor", p_set_text_color},