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.
|
||||
*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
|
||||
|
||||
|
||||
@ -59,7 +59,8 @@
|
||||
В число контейнеров также входят панели и кнопки.
|
||||
- `padding` - внутренний отступ элемента. Тип: 4D вектор.
|
||||
Порядок: `"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() {
|
||||
std::stable_sort(nodes.begin(), nodes.end(), [](const auto& a, const auto& b) {
|
||||
return a->getZIndex() < b->getZIndex();
|
||||
|
||||
@ -32,6 +32,8 @@ namespace gui {
|
||||
void listenInterval(float interval, ontimeout callback, int repeat=-1);
|
||||
virtual glm::vec2 getContentOffset() override {return glm::vec2(0.0f, scroll);};
|
||||
virtual void setSize(glm::vec2 size) override;
|
||||
virtual int getScrollStep() const;
|
||||
virtual void setScrollStep(int step);
|
||||
virtual void refresh() override;
|
||||
|
||||
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;
|
||||
scrollable = true;
|
||||
scrollStep = 0;
|
||||
}
|
||||
|
||||
void TextBox::draw(const DrawContext* pctx, Assets* assets) {
|
||||
@ -746,7 +747,9 @@ void TextBox::setCaret(size_t position) {
|
||||
uint line = label->getLineByTextIndex(caret);
|
||||
int offset = label->getLineYOffset(line) + getContentOffset().y;
|
||||
uint lineHeight = font->getLineHeight()*label->getLineInterval();
|
||||
scrollStep = lineHeight;
|
||||
if (scrollStep == 0) {
|
||||
scrollStep = lineHeight;
|
||||
}
|
||||
if (offset < 0) {
|
||||
scrolled(-glm::floor(offset/static_cast<double>(scrollStep)+0.5f));
|
||||
} else if (offset >= getSize().y) {
|
||||
|
||||
@ -172,6 +172,9 @@ static void _readContainer(UiXmlReader& reader, const xml::xmlelement& element,
|
||||
if (element->has("scrollable")) {
|
||||
container.setScrollable(element->attr("scrollable").asBool());
|
||||
}
|
||||
if (element->has("scroll-step")) {
|
||||
container.setScrollStep(element->attr("scroll-step").asInt());
|
||||
}
|
||||
for (auto& sub : element->getElements()) {
|
||||
if (sub->isText())
|
||||
continue;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user