add 'scroll-step' property to container
This commit is contained in:
parent
5c005b4f9a
commit
2412699b89
@ -56,7 +56,8 @@ Buttons and panels are also containers.
|
|||||||
|
|
||||||
- `padding` - element padding. Type: 4D vector.
|
- `padding` - element padding. Type: 4D vector.
|
||||||
*left, top, right, bottom*
|
*left, top, right, bottom*
|
||||||
`scrollable` - element scrollability. Works on panels only. Type: boolean
|
- `scrollable` - element scrollability. Type: boolean.
|
||||||
|
- `scroll-step` - scrolling step. Type: integer.
|
||||||
|
|
||||||
# Common *panel* attributes
|
# Common *panel* attributes
|
||||||
|
|
||||||
|
|||||||
@ -59,7 +59,8 @@
|
|||||||
В число контейнеров также входят панели и кнопки.
|
В число контейнеров также входят панели и кнопки.
|
||||||
- `padding` - внутренний отступ элемента. Тип: 4D вектор.
|
- `padding` - внутренний отступ элемента. Тип: 4D вектор.
|
||||||
Порядок: `"left,top,right,bottom"`
|
Порядок: `"left,top,right,bottom"`
|
||||||
- `scrollable` - возможность скроллинга. Работает только у Panel. Тип: логический.
|
- `scrollable` - возможность скроллинга. Тип: логический.
|
||||||
|
- `scroll-step` - шаг скроллинга. Тип: целочисленный.
|
||||||
|
|
||||||
# Общие атрибуты панелей
|
# Общие атрибуты панелей
|
||||||
|
|
||||||
|
|||||||
@ -165,6 +165,14 @@ void Container::setSize(glm::vec2 size) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Container::getScrollStep() const {
|
||||||
|
return scrollStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Container::setScrollStep(int step) {
|
||||||
|
scrollStep = step;
|
||||||
|
}
|
||||||
|
|
||||||
void Container::refresh() {
|
void Container::refresh() {
|
||||||
std::stable_sort(nodes.begin(), nodes.end(), [](const auto& a, const auto& b) {
|
std::stable_sort(nodes.begin(), nodes.end(), [](const auto& a, const auto& b) {
|
||||||
return a->getZIndex() < b->getZIndex();
|
return a->getZIndex() < b->getZIndex();
|
||||||
|
|||||||
@ -32,6 +32,8 @@ namespace gui {
|
|||||||
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
||||||
virtual glm::vec2 getContentOffset() 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 int getScrollStep() const;
|
||||||
|
virtual void setScrollStep(int step);
|
||||||
virtual void refresh() override;
|
virtual void refresh() override;
|
||||||
|
|
||||||
const std::vector<std::shared_ptr<UINode>>& getNodes() const;
|
const std::vector<std::shared_ptr<UINode>>& getNodes() const;
|
||||||
|
|||||||
@ -43,6 +43,7 @@ TextBox::TextBox(std::wstring placeholder, glm::vec4 padding)
|
|||||||
|
|
||||||
textInitX = label->getPos().x;
|
textInitX = label->getPos().x;
|
||||||
scrollable = true;
|
scrollable = true;
|
||||||
|
scrollStep = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
||||||
@ -746,7 +747,9 @@ void TextBox::setCaret(size_t position) {
|
|||||||
uint line = label->getLineByTextIndex(caret);
|
uint line = label->getLineByTextIndex(caret);
|
||||||
int offset = label->getLineYOffset(line) + getContentOffset().y;
|
int offset = label->getLineYOffset(line) + getContentOffset().y;
|
||||||
uint lineHeight = font->getLineHeight()*label->getLineInterval();
|
uint lineHeight = font->getLineHeight()*label->getLineInterval();
|
||||||
scrollStep = lineHeight;
|
if (scrollStep == 0) {
|
||||||
|
scrollStep = lineHeight;
|
||||||
|
}
|
||||||
if (offset < 0) {
|
if (offset < 0) {
|
||||||
scrolled(-glm::floor(offset/static_cast<double>(scrollStep)+0.5f));
|
scrolled(-glm::floor(offset/static_cast<double>(scrollStep)+0.5f));
|
||||||
} else if (offset >= getSize().y) {
|
} else if (offset >= getSize().y) {
|
||||||
|
|||||||
@ -172,6 +172,9 @@ static void _readContainer(UiXmlReader& reader, const xml::xmlelement& element,
|
|||||||
if (element->has("scrollable")) {
|
if (element->has("scrollable")) {
|
||||||
container.setScrollable(element->attr("scrollable").asBool());
|
container.setScrollable(element->attr("scrollable").asBool());
|
||||||
}
|
}
|
||||||
|
if (element->has("scroll-step")) {
|
||||||
|
container.setScrollStep(element->attr("scroll-step").asInt());
|
||||||
|
}
|
||||||
for (auto& sub : element->getElements()) {
|
for (auto& sub : element->getElements()) {
|
||||||
if (sub->isText())
|
if (sub->isText())
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user