Panels scrolling, scissors test fix
This commit is contained in:
@@ -14,6 +14,7 @@ using glm::vec2;
|
||||
using glm::vec4;
|
||||
|
||||
Container::Container(vec2 coord, vec2 size) : UINode(coord, size) {
|
||||
actualLength = size.y;
|
||||
}
|
||||
|
||||
shared_ptr<UINode> Container::getAt(vec2 pos, shared_ptr<UINode> self) {
|
||||
@@ -53,6 +54,24 @@ void Container::act(float delta) {
|
||||
}
|
||||
}
|
||||
|
||||
void Container::scrolled(int value) {
|
||||
int diff = (actualLength-size().y);
|
||||
if (diff > 0 && scrollable_) {
|
||||
scroll += value * 20;
|
||||
if (scroll > 0)
|
||||
scroll = 0;
|
||||
if (-scroll > diff) {
|
||||
scroll = -diff;
|
||||
}
|
||||
} else if (parent) {
|
||||
parent->scrolled(value);
|
||||
}
|
||||
}
|
||||
|
||||
void Container::scrollable(bool flag) {
|
||||
scrollable_ = flag;
|
||||
}
|
||||
|
||||
void Container::draw(Batch2D* batch, Assets* assets) {
|
||||
vec2 coord = calcCoord();
|
||||
vec2 size = this->size();
|
||||
@@ -110,6 +129,14 @@ void Panel::drawBackground(Batch2D* batch, Assets* assets) {
|
||||
batch->rect(coord.x, coord.y, size_.x, size_.y);
|
||||
}
|
||||
|
||||
void Panel::maxLength(int value) {
|
||||
maxLength_ = value;
|
||||
}
|
||||
|
||||
int Panel::maxLength() const {
|
||||
return maxLength_;
|
||||
}
|
||||
|
||||
void Panel::refresh() {
|
||||
float x = padding.x;
|
||||
float y = padding.y;
|
||||
@@ -141,8 +168,13 @@ void Panel::refresh() {
|
||||
node->refresh();
|
||||
maxw = fmax(maxw, ex+node->size().x+margin.z+padding.z);
|
||||
}
|
||||
if (resizing_)
|
||||
this->size(vec2(size.x, y+padding.w));
|
||||
if (resizing_) {
|
||||
if (maxLength_)
|
||||
this->size(vec2(size.x, min(maxLength_, (int)(y+padding.w))));
|
||||
else
|
||||
this->size(vec2(size.x, y+padding.w));
|
||||
}
|
||||
actualLength = y + padding.w;
|
||||
} else {
|
||||
float maxh = size.y;
|
||||
for (auto& node : nodes) {
|
||||
@@ -158,10 +190,15 @@ void Panel::refresh() {
|
||||
maxh = fmax(maxh, y+margin.y+node->size().y+margin.w+padding.w);
|
||||
}
|
||||
bool increased = maxh > size.y;
|
||||
if (resizing_)
|
||||
this->size(vec2(x+padding.z, size.y));
|
||||
if (resizing_) {
|
||||
if (maxLength_)
|
||||
this->size(vec2(min(maxLength_, (int)(x+padding.z)), size.y));
|
||||
else
|
||||
this->size(vec2(x+padding.z, size.y));
|
||||
}
|
||||
if (increased)
|
||||
refresh();
|
||||
actualLength = size.y;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user