Skip to content

Commit

Permalink
Merge branch 'fix/map-tooltip-width' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
black-sliver committed Jan 8, 2025
2 parents eec8a5b + 8897491 commit 92c6a74
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/uilib/scrollvbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,6 @@ class ScrollVBox : public Container {
setSize({w->getWidth()+2*_padding, w->getHeight()+2*_padding});
Container::addChild(w);
}
// keep track of max and min size
_maxSize = {-1,2*_padding};
_minSize = {0,2*_padding};
for (auto& child : _children) {
if (_maxSize.width<0 || _maxSize.width>(child->getLeft()+child->getMaxWidth()+_padding))
_maxSize.width=child->getLeft()+child->getMaxWidth()+_padding;
if (child->getLeft()+child->getMinWidth()+_padding>_minSize.width)
_minSize.width=child->getLeft()+child->getMinWidth()+_padding;
if (_maxSize.height != -1) {
if (child->getMaxHeight() == -1)
_maxSize.height = -1; // undefined = no max
else
_maxSize.height += child->getMaxHeight()+_spacing;
}
}
if (_maxSize.width >= 0 && _minSize.width>_maxSize.width)
_maxSize.width = _minSize.width;
if (_maxSize.height >= 0 && _minSize.height>_maxSize.height)
_maxSize.height = _minSize.height;
relayout(); // required to update scroll position
}

Expand Down Expand Up @@ -82,6 +63,28 @@ class ScrollVBox : public Container {

void relayout(bool isFixup=false) // TODO: virtual?
{
// calculate max and min size
_maxSize = {-1,2*_padding};
_minSize = {0,2*_padding};
for (auto& child : _children) {
if (!child->getVisible())
continue;
if (_maxSize.width<0 || _maxSize.width>(child->getLeft()+child->getMaxWidth()+_padding))
_maxSize.width=child->getLeft()+child->getMaxWidth()+_padding;
if (child->getLeft()+child->getMinWidth()+_padding>_minSize.width)
_minSize.width=child->getLeft()+child->getMinWidth()+_padding;
if (_maxSize.height != -1) {
if (child->getMaxHeight() == -1)
_maxSize.height = -1; // undefined = no max
else
_maxSize.height += child->getMaxHeight()+_spacing;
}
}
if (_maxSize.width >= 0 && _minSize.width>_maxSize.width)
_maxSize.width = _minSize.width;
if (_maxSize.height >= 0 && _minSize.height>_maxSize.height)
_maxSize.height = _minSize.height;

if (_scrollY > 0) _scrollY = 0;
else if (_children.empty()) _scrollY = 0;

Expand Down

0 comments on commit 92c6a74

Please sign in to comment.