+ if (empty() || width() <= w)
+ return;
+
+ Elements::iterator const beg = elements_.begin();
+ Elements::iterator const end = elements_.end();
+ Elements::iterator last_sep = elements_.end();
+ int last_width = 0;
+ int wid = left_margin;
+
+ Elements::iterator cit = beg;
+ for ( ; cit != end ; ++cit) {
+ if (cit->type == SEPARATOR && cit->pos >= keep) {
+ last_sep = cit;
+ last_width = wid;
+ }
+ if (wid + cit->dim.wid > w)
+ break;
+ wid += cit->dim.wid;
+ }
+
+ if (last_sep != end) {
+ // We have found a suitable separator. This is the
+ // common case.
+ end_ = last_sep->endpos;
+ dim_.wid = last_width;
+ elements_.erase(last_sep, end);