a few optimizations to layouts/rendering
This commit is contained in:
parent
503638dbc6
commit
b3a87e3a6f
2 changed files with 26 additions and 37 deletions
|
@ -86,11 +86,9 @@ void Widget::show(bool children)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!_visible) {
|
if (!_visible) {
|
||||||
_visible = true;
|
|
||||||
if (_parent) _parent->calcDefaultSizes();
|
if (_parent) _parent->calcDefaultSizes();
|
||||||
else {
|
else resize(_area.size()); // constrain sizes
|
||||||
resize(_area.size());
|
_visible = true;
|
||||||
}
|
|
||||||
XMapWindow(**display, _window);
|
XMapWindow(**display, _window);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -133,14 +131,15 @@ void Widget::moveresize(const Rect &r)
|
||||||
w = std::max(std::min(r.width(), maxSize().width()), minSize().width());
|
w = std::max(std::min(r.width(), maxSize().width()), minSize().width());
|
||||||
h = std::max(std::min(r.height(), maxSize().height()), minSize().height());
|
h = std::max(std::min(r.height(), maxSize().height()), minSize().height());
|
||||||
|
|
||||||
if (r.x() == area().x() && r.y() == area().y() &&
|
bool sizechange = !(w == area().width() && h == area().height());
|
||||||
w == area().width() && h == area().height()) {
|
|
||||||
|
if (r.x() == area().x() && r.y() == area().y() && !sizechange)
|
||||||
return; // no change, don't cause a big layout chain to occur!
|
return; // no change, don't cause a big layout chain to occur!
|
||||||
}
|
|
||||||
|
|
||||||
internal_moveresize(r.x(), r.y(), w, h);
|
internal_moveresize(r.x(), r.y(), w, h);
|
||||||
|
|
||||||
update();
|
if (sizechange)
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::internal_moveresize(int x, int y, int w, int h)
|
void Widget::internal_moveresize(int x, int y, int w, int h)
|
||||||
|
@ -297,13 +296,10 @@ void Widget::layoutHorz()
|
||||||
std::list<Widget*>::iterator it, end;
|
std::list<Widget*>::iterator it, end;
|
||||||
|
|
||||||
// work with just the visible children
|
// work with just the visible children
|
||||||
std::list<Widget*> visible = _children;
|
std::list<Widget*> visible;
|
||||||
for (it = visible.begin(), end = visible.end(); it != end;) {
|
for (it = _children.begin(), end = _children.end(); it != end; ++it)
|
||||||
std::list<Widget*>::iterator next = it; ++next;
|
if ((*it)->visible())
|
||||||
if (!(*it)->visible())
|
visible.push_back(*it);
|
||||||
visible.erase(it);
|
|
||||||
it = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (visible.empty()) return;
|
if (visible.empty()) return;
|
||||||
|
|
||||||
|
@ -317,16 +313,14 @@ void Widget::layoutHorz()
|
||||||
if (free < 0) free = 0;
|
if (free < 0) free = 0;
|
||||||
int each;
|
int each;
|
||||||
|
|
||||||
std::list<Widget*> adjustable = visible;
|
std::list<Widget*> adjustable;
|
||||||
|
|
||||||
// find the 'free' space, and how many children will be using it
|
// find the 'free' space, and how many children will be using it
|
||||||
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
|
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
|
||||||
std::list<Widget*>::iterator next = it; ++next;
|
|
||||||
free -= (*it)->minSize().width();
|
free -= (*it)->minSize().width();
|
||||||
if (free < 0) free = 0;
|
if (free < 0) free = 0;
|
||||||
if ((*it)->maxSize().width() - (*it)->minSize().width() <= 0)
|
if ((*it)->maxSize().width() - (*it)->minSize().width() > 0)
|
||||||
adjustable.erase(it);
|
adjustable.push_back(*it);
|
||||||
it = next;
|
|
||||||
}
|
}
|
||||||
// some widgets may have max widths that restrict them, find the 'true'
|
// some widgets may have max widths that restrict them, find the 'true'
|
||||||
// amount of free space after these widgets are not included
|
// amount of free space after these widgets are not included
|
||||||
|
@ -393,13 +387,10 @@ void Widget::layoutVert()
|
||||||
std::list<Widget*>::iterator it, end;
|
std::list<Widget*>::iterator it, end;
|
||||||
|
|
||||||
// work with just the visible children
|
// work with just the visible children
|
||||||
std::list<Widget*> visible = _children;
|
std::list<Widget*> visible;
|
||||||
for (it = visible.begin(), end = visible.end(); it != end;) {
|
for (it = _children.begin(), end = _children.end(); it != end; ++it)
|
||||||
std::list<Widget*>::iterator next = it; ++next;
|
if ((*it)->visible())
|
||||||
if (!(*it)->visible())
|
visible.push_back(*it);
|
||||||
visible.erase(it);
|
|
||||||
it = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (visible.empty()) return;
|
if (visible.empty()) return;
|
||||||
|
|
||||||
|
@ -413,16 +404,14 @@ void Widget::layoutVert()
|
||||||
if (free < 0) free = 0;
|
if (free < 0) free = 0;
|
||||||
int each;
|
int each;
|
||||||
|
|
||||||
std::list<Widget*> adjustable = visible;
|
std::list<Widget*> adjustable;
|
||||||
|
|
||||||
// find the 'free' space, and how many children will be using it
|
// find the 'free' space, and how many children will be using it
|
||||||
for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
|
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
|
||||||
std::list<Widget*>::iterator next = it; ++next;
|
|
||||||
free -= (*it)->minSize().height();
|
free -= (*it)->minSize().height();
|
||||||
if (free < 0) free = 0;
|
if (free < 0) free = 0;
|
||||||
if ((*it)->maxSize().height() - (*it)->minSize().height() <= 0)
|
if ((*it)->maxSize().height() - (*it)->minSize().height() > 0)
|
||||||
adjustable.erase(it);
|
adjustable.push_back(*it);
|
||||||
it = next;
|
|
||||||
}
|
}
|
||||||
// some widgets may have max heights that restrict them, find the 'true'
|
// some widgets may have max heights that restrict them, find the 'true'
|
||||||
// amount of free space after these widgets are not included
|
// amount of free space after these widgets are not included
|
||||||
|
@ -446,7 +435,7 @@ void Widget::layoutVert()
|
||||||
|
|
||||||
// place/size the widgets
|
// place/size the widgets
|
||||||
if (!adjustable.empty())
|
if (!adjustable.empty())
|
||||||
each = free / adjustable.size();
|
each = free / adjustable.size();
|
||||||
else
|
else
|
||||||
each = 0;
|
each = 0;
|
||||||
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
|
for (it = visible.begin(), end = visible.end(); it != end; ++it) {
|
||||||
|
@ -541,7 +530,7 @@ void Widget::configureHandler(const XConfigureEvent &e)
|
||||||
} else {
|
} else {
|
||||||
// only interested in these for top level windows
|
// only interested in these for top level windows
|
||||||
if (_parent) return;
|
if (_parent) return;
|
||||||
|
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
ev.xconfigure.width = e.width;
|
ev.xconfigure.width = e.width;
|
||||||
ev.xconfigure.height = e.height;
|
ev.xconfigure.height = e.height;
|
||||||
|
|
|
@ -52,7 +52,7 @@ public:
|
||||||
inline bool visible() const { return _visible; }
|
inline bool visible() const { return _visible; }
|
||||||
|
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void refresh() { _dirty = true; render(); }
|
virtual void refresh() { if (_visible) { _dirty = true; render(); } }
|
||||||
|
|
||||||
virtual void setBevel(int b);
|
virtual void setBevel(int b);
|
||||||
inline int bevel() const { return _bevel; }
|
inline int bevel() const { return _bevel; }
|
||||||
|
|
Loading…
Reference in a new issue