require "mspdatafile";
require "sigc++-2.0";
+ build_info
+ {
+ standard CXX "c++11";
+ };
+
library "mspgltk"
{
source "source";
{
Side side = static_cast<Side>(i);
const Edge &edge = arr.get_edge(side);
- for(list<Widget *>::const_iterator j=edge.widgets.begin(); j!=edge.widgets.end(); ++j)
- process_widget(**j, side, edge.aligned);
+ for(Widget *w: edge.widgets)
+ process_widget(*w, side, edge.aligned);
}
finish_slot();
}
void Arrangement::add_constraint(Widget &wdg, Layout::ConstraintType type, const Edge &edge, int spacing)
{
- for(list<Widget *>::const_iterator i=edge.widgets.begin(); i!=edge.widgets.end(); ++i)
- if(*i!=&wdg)
+ for(Widget *w: edge.widgets)
+ if(w!=&wdg)
{
if(spacing<0)
- layout.add_constraint(wdg, type, **i);
+ layout.add_constraint(wdg, type, *w);
else
- layout.add_constraint(wdg, type, **i, spacing);
+ layout.add_constraint(wdg, type, *w, spacing);
}
}
if(aligned || widgets.empty())
return;
- list<Widget *>::iterator second = widgets.begin();
+ auto second = widgets.begin();
++second;
widgets.erase(second, widgets.end());
+#include <msp/core/algorithm.h>
#include "container.h"
#include "part.h"
void Container::remove(Widget &wdg)
{
- for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
- if((*i)->widget==&wdg)
- {
- wdg.set_parent(0);
- delete *i;
- children.erase(i);
- if(wdg.get_animation_interval())
- check_animation_interval();
- on_child_removed(wdg);
- return;
- }
+ auto i = find_if(children, [&wdg](const Child *c){ return c->widget==&wdg; });
+ if(i==children.end())
+ throw hierarchy_error("widget not in container");
- throw hierarchy_error("widget not in container");
+ wdg.set_parent(0);
+ delete *i;
+ children.erase(i);
+ if(wdg.get_animation_interval())
+ check_animation_interval();
+ on_child_removed(wdg);
}
Container::Child *Container::create_child(Widget *wdg)
list<Widget *> Container::get_children() const
{
list<Widget *> result;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
- result.push_back((*i)->widget);
+ for(const Child *c: children)
+ result.push_back(c->widget);
return result;
}
Widget *Container::get_child_at(int x, int y) const
{
- for(list<Child *>::const_iterator i=children.end(); i!=children.begin();)
+ for(auto i=children.end(); i!=children.begin();)
if((*--i)->widget->is_visible() && (*i)->widget->get_geometry().is_inside(x, y))
return (*i)->widget;
void Container::raise(Widget &wdg)
{
- for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
- if((*i)->widget==&wdg)
- {
- children.splice(children.end(), children, i);
- return;
- }
+ auto i = find_if(children, [&wdg](const Child *c){ return c->widget==&wdg; });
+ if(i==children.end())
+ throw hierarchy_error("widget not in container");
- throw hierarchy_error("widget not in container");
+ children.splice(children.end(), children, i);
}
void Container::set_pointer_focus(Widget *wdg, bool grab)
void Container::check_animation_interval()
{
Time::TimeDelta shortest;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
+ for(const Child *c: children)
{
- const Time::TimeDelta &child_iv = (*i)->widget->get_animation_interval();
+ const Time::TimeDelta &child_iv = c->widget->get_animation_interval();
if(child_iv && (!shortest || child_iv<shortest))
shortest = child_iv;
}
if(children_rebuild_needed)
{
children_rebuild_needed = false;
- for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
- (*i)->widget->rebuild_hierarchy();
+ for(Child *c: children)
+ c->widget->rebuild_hierarchy();
}
}
void Container::animate(const Time::TimeDelta &dt)
{
- for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
+ for(Child *c: children)
{
- const Time::TimeDelta &child_iv = (*i)->widget->get_animation_interval();
+ const Time::TimeDelta &child_iv = c->widget->get_animation_interval();
if(!child_iv)
continue;
- (*i)->time_since_animate += dt;
- if((*i)->time_since_animate>=child_iv)
+ c->time_since_animate += dt;
+ if(c->time_since_animate>=child_iv)
{
- Time::TimeDelta child_dt = (*i)->time_since_animate;
- (*i)->time_since_animate = min((*i)->time_since_animate-child_iv, child_iv);
- (*i)->widget->animate(child_dt);
+ Time::TimeDelta child_dt = c->time_since_animate;
+ c->time_since_animate = min(c->time_since_animate-child_iv, child_iv);
+ c->widget->animate(child_dt);
}
}
}
void Container::on_reparent()
{
- for(list<Child *>::iterator i=children.begin(); i!=children.end(); ++i)
+ for(const Child *c: children)
{
- if(Container *c = dynamic_cast<Container *>((*i)->widget))
- c->on_reparent();
- (*i)->widget->update_style();
+ if(Container *o = dynamic_cast<Container *>(c->widget))
+ o->on_reparent();
+ c->widget->update_style();
}
}
-#include <algorithm>
#include <limits>
+#include <msp/core/algorithm.h>
#include <msp/core/maputils.h>
#include <msp/strings/format.h>
#include "arrangement.h"
Layout::~Layout()
{
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- delete *i;
+ for(Slot *s: slots)
+ delete s;
}
void Layout::set_container(Container &c)
void Layout::pop_arrangement(Arrangement &arr)
{
- list<Arrangement *>::iterator begin = find(arrangement_stack.begin(), arrangement_stack.end(), &arr);
+ auto begin = find(arrangement_stack, &arr);
if(begin==arrangement_stack.end())
return;
void Layout::remove_widget(Widget &wdg)
{
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- if(&(*i)->widget==&wdg)
+ auto i = find_if(slots, [&wdg](Slot *s){ return &s->widget==&wdg; });
+ if(i==slots.end())
+ return;
+
+ for(Slot *s: slots)
+ if(s!=*i)
{
- for(list<Slot *>::iterator j=slots.begin(); j!=slots.end(); ++j)
- if(j!=i)
- {
- for(list<Constraint>::iterator k=(*j)->constraints.begin(); k!=(*j)->constraints.end(); )
- {
- if(&k->target==*i)
- (*j)->constraints.erase(k++);
- else
- ++k;
- }
- }
+ for(auto k=s->constraints.begin(); k!=s->constraints.end(); )
+ {
+ if(&k->target==*i)
+ s->constraints.erase(k++);
+ else
+ ++k;
+ }
+ }
- delete *i;
- slots.erase(i);
+ delete *i;
+ slots.erase(i);
- update_slot_indices();
- update();
- return;
- }
+ update_slot_indices();
+ update();
}
void Layout::update_slot_indices()
{
n_active_slots = 0;
unsigned n_floating = 0;
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
+ for(Slot *s: slots)
{
- if((*i)->widget.is_visible() || (*i)->ghost)
+ if(s->widget.is_visible() || s->ghost)
{
- (*i)->index = n_active_slots++;
- if((*i)->floating)
+ s->index = n_active_slots++;
+ if(s->floating)
++n_floating;
}
else
- (*i)->index = -1;
+ s->index = -1;
}
n_slack_vars[0] = n_floating*2;
n_slack_vars[1] = n_floating*2;
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- if((*i)->index>=0)
+ for(const Slot *s: slots)
+ if(s->index>=0)
{
- if(!(*i)->floating)
+ if(!s->floating)
{
for(unsigned j=0; j<2; ++j)
- if(((*i)->*(pointers[j].packing)).gravity==0)
+ if((s->*(pointers[j].packing)).gravity==0)
n_slack_vars[j] += 2;
}
- for(list<Constraint>::iterator j=(*i)->constraints.begin(); j!=(*i)->constraints.end(); ++j)
- if(j->target.index>(*i)->index && (j->type&SLACK))
- ++n_slack_vars[j->type&1];
+ for(const Constraint &c: s->constraints)
+ if(c.target.index>s->index && (c.type&SLACK))
+ ++n_slack_vars[c.type&1];
}
}
Layout::Slot &Layout::get_slot_for_widget(Widget &wdg)
{
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- if(&(*i)->widget==&wdg)
- return **i;
+ auto i = find_if(slots, [&wdg](const Slot *s){ return &s->widget==&wdg; });
+ if(i==slots.end())
+ throw hierarchy_error("widget not in layout");
- throw hierarchy_error("widget not in layout");
+ return **i;
}
Layout::ConstraintType Layout::complement(ConstraintType type)
Slot &src_slot = get_slot_for_widget(src);
Slot &tgt_slot = get_slot_for_widget(tgt);
- for(list<Constraint>::iterator i=src_slot.constraints.begin(); i!=src_slot.constraints.end(); ++i)
- if(i->type==type && &i->target==&tgt_slot)
+ for(const Constraint &c: src_slot.constraints)
+ if(c.type==type && &c.target==&tgt_slot)
return;
src_slot.constraints.push_back(Constraint(type, tgt_slot));
solve_constraints(HORIZONTAL, UPDATE);
solve_constraints(VERTICAL, UPDATE);
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- (*i)->widget.set_geometry((*i)->geom);
+ for(const Slot *s: slots)
+ s->widget.set_geometry(s->geom);
}
void Layout::autosize(Geometry &geom)
LinearProgram linprog(n_active_slots*5+n_slack_vars[dir]+1);
float weight = slots.size()+1;
unsigned k = n_active_slots*5;
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
+ for(const Slot *s: slots)
{
- if((*i)->index<0)
+ if(s->index<0)
continue;
LinearProgram::Row objective = linprog.get_objective_row();
if(mode==AUTOSIZE)
{
- objective[(*i)->index*5] = -1;
- objective[(*i)->index*5+1] = -1;
+ objective[s->index*5] = -1;
+ objective[s->index*5+1] = -1;
}
else
{
- if(!(*i)->floating)
- objective[(*i)->index*5] = ((*i)->*(ptrs.packing)).gravity/weight;
- objective[(*i)->index*5+1] = (((*i)->*(ptrs.packing)).expand ? weight : -1);
+ if(!s->floating)
+ objective[s->index*5] = (s->*(ptrs.packing)).gravity/weight;
+ objective[s->index*5+1] = ((s->*(ptrs.packing)).expand ? weight : -1);
}
{
// Prevent the widget from going past the container's low edge.
LinearProgram::Row row = linprog.add_row();
- row[(*i)->index*5] = 1;
- row[(*i)->index*5+2] = -1;
+ row[s->index*5] = 1;
+ row[s->index*5+2] = -1;
row.back() = margin.*(ptrs.low_margin);
}
{
// Prevent the widget from going past the container's high edge.
LinearProgram::Row row = linprog.add_row();
- row[(*i)->index*5] = 1;
- row[(*i)->index*5+1] = 1;
- row[(*i)->index*5+3] = 1;
+ row[s->index*5] = 1;
+ row[s->index*5+1] = 1;
+ row[s->index*5+3] = 1;
row.back() = geom.*(ptrs.dim)-margin.*(ptrs.high_margin);
}
- if((*i)->floating || ((*i)->*(ptrs.packing)).gravity==0)
+ if(s->floating || (s->*(ptrs.packing)).gravity==0)
{
/* Try to keep the widget as close to a target position as possible.
Since linear programs can't express absolute values directly, use two
opposing slack variables that are optimized for a low value. */
- float a = ((*i)->*(ptrs.packing)).gravity*0.5+0.5;
+ float a = (s->*(ptrs.packing)).gravity*0.5+0.5;
LinearProgram::Row row = linprog.add_row();
- row[(*i)->index*5] = 1;
- row[(*i)->index*5+1] = a;
+ row[s->index*5] = 1;
+ row[s->index*5+1] = a;
row[k] = 1;
row[k+1] = -1;
- if((*i)->floating)
+ if(s->floating)
{
- const Geometry &cgeom = (*i)->widget.get_geometry();
+ const Geometry &cgeom = s->widget.get_geometry();
row.back() = cgeom.*(ptrs.pos)+cgeom.*(ptrs.dim)*a;
}
else
/* Don't allow the widget's dimension to get below that determined
by autosizing. */
LinearProgram::Row row = linprog.add_row();
- row[(*i)->index*5+1] = 1;
- row[(*i)->index*5+4] = -1;
- row.back() = (*i)->autosize_geom.*(ptrs.dim);
+ row[s->index*5+1] = 1;
+ row[s->index*5+4] = -1;
+ row.back() = s->autosize_geom.*(ptrs.dim);
}
/* Add rows for user-defined constraints. Constraints are always added
in pairs, so it's only necessary to create a row for one half. */
- for(list<Constraint>::iterator j=(*i)->constraints.begin(); j!=(*i)->constraints.end(); ++j)
- if(j->target.index>(*i)->index && (j->type&1)==dir)
+ for(const Constraint &c: s->constraints)
+ if(c.target.index>s->index && (c.type&1)==dir)
{
LinearProgram::Row row = linprog.add_row();
- float polarity = ((j->type&SELF_DIM) ? -1 : 1);
- float dim_weight = ((j->type&HALF_DIM) ? 0.5f : 1);
- if(j->type&SELF_POS)
- row[(*i)->index*5] = polarity;
- if(j->type&SELF_DIM)
- row[(*i)->index*5+1] = polarity*dim_weight;
- if(j->type&TARGET_POS)
- row[j->target.index*5] = -polarity;
- if(j->type&TARGET_DIM)
- row[j->target.index*5+1] = -polarity*dim_weight;
- if(j->type&SPACING)
- row.back() = (j->spacing>=0 ? j->spacing : this->*(ptrs.spacing));
- if(j->type&SLACK)
+ float polarity = ((c.type&SELF_DIM) ? -1 : 1);
+ float dim_weight = ((c.type&HALF_DIM) ? 0.5f : 1);
+ if(c.type&SELF_POS)
+ row[s->index*5] = polarity;
+ if(c.type&SELF_DIM)
+ row[s->index*5+1] = polarity*dim_weight;
+ if(c.type&TARGET_POS)
+ row[c.target.index*5] = -polarity;
+ if(c.type&TARGET_DIM)
+ row[c.target.index*5+1] = -polarity*dim_weight;
+ if(c.type&SPACING)
+ row.back() = (c.spacing>=0 ? c.spacing : this->*(ptrs.spacing));
+ if(c.type&SLACK)
row[k++] = -1;
}
}
if(mode==AUTOSIZE)
{
autosize_geom.*(ptrs.dim) = 0;
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- if((*i)->index>=0)
+ for(const Slot *s: slots)
+ if(s->index>=0)
{
- int high_edge = linprog.get_variable((*i)->index*5)+linprog.get_variable((*i)->index*5+1);
+ int high_edge = linprog.get_variable(s->index*5)+linprog.get_variable(s->index*5+1);
autosize_geom.*(ptrs.dim) = max(autosize_geom.*(ptrs.dim), high_edge+margin.*(ptrs.high_margin));
}
}
else
{
- for(list<Slot *>::iterator i=slots.begin(); i!=slots.end(); ++i)
- if((*i)->index>=0)
+ for(Slot *s: slots)
+ if(s->index>=0)
{
- (*i)->geom.*(ptrs.pos) = linprog.get_variable((*i)->index*5);
- (*i)->geom.*(ptrs.dim) = linprog.get_variable((*i)->index*5+1);
+ s->geom.*(ptrs.pos) = linprog.get_variable(s->index*5);
+ s->geom.*(ptrs.dim) = linprog.get_variable(s->index*5+1);
}
}
}
vector<float> obj_coeff(n_rows, 0.0f);
vector<float> row_coeff(n_rows, 1.0f);
const vector<float> &constants = columns.back().values;
- for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
- {
- if(i->values.size()>=2 && i->values.back()!=0.0f && (constants.size()<i->values.size() || i->values.back()*constants[i->values.size()-1]>=0.0f) && obj_coeff[i->values.size()-1]==0.0f)
+ for(Column &c: columns)
+ if(c.values.size()>=2 && c.values.back()!=0.0f && (constants.size()<c.values.size() || c.values.back()*constants[c.values.size()-1]>=0.0f) && obj_coeff[c.values.size()-1]==0.0f)
{
bool basic = true;
- for(unsigned j=1; (basic && j+1<i->values.size()); ++j)
- basic = (i->values[j]==0.0f);
+ for(unsigned j=1; (basic && j+1<c.values.size()); ++j)
+ basic = (c.values[j]==0.0f);
if(basic)
{
- i->basic = i->values.size()-1;
- row_coeff[i->basic] = 1.0f/i->values.back();
- obj_coeff[i->basic] = -i->values.front();
- i->values.clear();
+ c.basic = c.values.size()-1;
+ row_coeff[c.basic] = 1.0f/c.values.back();
+ obj_coeff[c.basic] = -c.values.front();
+ c.values.clear();
}
}
- }
// Price out the newly-created basic variables.
- for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
- if(!i->values.empty())
+ for(Column &c: columns)
+ if(!c.values.empty())
{
- for(unsigned j=0; j<i->values.size(); ++j)
+ for(unsigned j=0; j<c.values.size(); ++j)
{
- i->values[j] *= row_coeff[j];
- i->values.front() += obj_coeff[j]*i->values[j];
+ c.values[j] *= row_coeff[j];
+ c.values.front() += obj_coeff[j]*c.values[j];
}
}
}
for(unsigned i=0; i<artificial_rows.size(); ++i)
artificial_rows[i] = i+1;
- for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
- if(i->basic)
- artificial_rows[i->basic-1] = 0;
+ for(const Column &c: columns)
+ if(c.basic)
+ artificial_rows[c.basic-1] = 0;
artificial_rows.erase(std::remove(artificial_rows.begin(), artificial_rows.end(), 0), artificial_rows.end());
/* Force all non-basic columns fully into existence and relocate objective
row to bottom in preparation of phase 1. A new objective row is calculated
by pricing out the constraint rows. */
- for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
- if(!i->basic)
+ for(Column &c: columns)
+ if(!c.basic)
{
float objective = 0.0f;
- if(!i->values.empty())
+ if(!c.values.empty())
{
- objective = i->values.front();
- i->values.front() = 0.0f;
- for(vector<unsigned>::iterator j=artificial_rows.begin(); j!=artificial_rows.end(); ++j)
- if(*j<i->values.size())
- i->values.front() += i->values[*j];
+ objective = c.values.front();
+ c.values.front() = 0.0f;
+ for(unsigned r: artificial_rows)
+ if(r<c.values.size())
+ c.values.front() += c.values[r];
}
- i->values.resize(n_rows+1, 0.0f);
- i->values.back() = objective;
+ c.values.resize(n_rows+1, 0.0f);
+ c.values.back() = objective;
}
if(artificial_rows.empty())
/* Get rid of the artificial variables and restore the original objective
row to form the phase 2 problem. */
columns.erase(columns.begin()+(n_columns-1), columns.end()-1);
- for(vector<Column>::iterator i=columns.begin(); i!=columns.end(); ++i)
- if(!i->basic)
+ for(Column &c: columns)
+ if(!c.basic)
{
- i->values.front() = i->values.back();
- i->values.pop_back();
+ c.values.front() = c.values.back();
+ c.values.pop_back();
}
}
own_data = false;
observer = new DataObserver(*this);
- for(vector<Item *>::iterator i=items.begin(); i!=items.end(); ++i)
- delete *i;
+ for(Item *i: items)
+ delete i;
items.clear();
unsigned n_items = data->size();
for(unsigned i=0; i<n_items; ++i)
{
list.sel_index = -1;
list.focus_index = -1;
- for(vector<Item *>::iterator i=list.items.begin(); i!=list.items.end(); ++i)
- delete *i;
+ for(Item *i: list.items)
+ delete i;
list.items.clear();
list.items_changed();
if(part.get_name()=="children")
{
const Sides &margin = part.get_margin();
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
+ for(const Child *c: children)
{
Geometry cgeom;
- (*i)->widget->autosize(cgeom);
+ c->widget->autosize(cgeom);
ageom.w = max(ageom.w, cgeom.x+cgeom.w+margin.right);
ageom.h = max(ageom.h, cgeom.y+cgeom.h+margin.top);
}
{
if(part.get_name()=="children")
{
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
- (*i)->widget->render(renderer);
+ for(const Child *c: children)
+ c->widget->render(renderer);
}
}
widths.resize(children.size(), 0);
unsigned n = 0;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i, ++n)
+ for(const Child *c: children)
{
Geometry cgeom;
- (*i)->widget->autosize(cgeom);
+ c->widget->autosize(cgeom);
// TODO invent a better way to specify spacings
widths[n] = max(widths[n], cgeom.w+8);
+ ++n;
}
}
const Sides &margin = part->get_margin();
int x = margin.left;
unsigned n = 0;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i, ++n)
+ for(const Child *c: children)
{
- (*i)->widget->set_position(x, margin.bottom);
- x += widths[n];
+ c->widget->set_position(x, margin.bottom);
+ x += widths[n++];
}
}
if(!style)
return;
- for(std::list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
- (*i)->widget->autosize();
+ for(const Child *c: children)
+ c->widget->autosize();
vector<unsigned> widths;
List *list = static_cast<List *>(parent);
- for(vector<Item *>::const_iterator i=list->items.begin(); i!=list->items.end(); ++i)
- if(*i!=this)
- if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(*i))
+ for(Item *i: list->items)
+ if(i!=this)
+ if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(i))
mci->check_widths(widths);
vector<unsigned> self_widths(widths);
if(update_all)
{
- for(vector<Item *>::const_iterator i=list->items.begin(); i!=list->items.end(); ++i)
- if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(*i))
+ for(Item *i: list->items)
+ if(MultiColumnItem *mci = dynamic_cast<MultiColumnItem *>(i))
mci->set_widths(self_widths);
}
{
if(part.get_name()=="children")
{
- for(list<Container::Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
- if((*i)->widget->is_visible())
- (*i)->widget->render(renderer);
+ for(const Container::Child *c: children)
+ if(c->widget->is_visible())
+ c->widget->render(renderer);
}
}
}
else if(nav==NAV_NEXT || nav==NAV_PREVIOUS)
{
- vector<Widget *>::iterator i = find(nav_order, input_focus);
+ auto i = find(nav_order, input_focus);
if(nav==NAV_NEXT)
{
{
Widget *sibling = 0;
int best_score = 0;
- for(list<Child *>::const_iterator i=children.begin(); i!=children.end(); ++i)
+ for(const Child *c: children)
{
- if((*i)->widget==input_focus || !(*i)->widget->is_focusable())
+ if(c->widget==input_focus || !c->widget->is_focusable())
continue;
- const Geometry &cgeom = (*i)->widget->get_geometry();
+ const Geometry &cgeom = c->widget->get_geometry();
int dx = compute_delta(cgeom.x, cgeom.w, origin_x, origin_dim, nav_x);
int dy = compute_delta(cgeom.y, cgeom.h, origin_y, origin_dim, nav_y);
if(score>=0 && (!sibling || score<best_score))
{
- sibling = (*i)->widget;
+ sibling = c->widget;
best_score = score;
}
}
void Panel::on_child_removed(Widget &wdg)
{
- vector<Widget *>::iterator i = std::remove(nav_order.begin(), nav_order.end(), &wdg);
+ auto i = std::remove(nav_order.begin(), nav_order.end(), &wdg);
if(i!=nav_order.end())
nav_order.erase(i, nav_order.end());
+#include <msp/core/algorithm.h>
#include "resources.h"
#include "style.h"
const Part *Style::get_part(const string &name) const
{
- for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
- if(i->get_name()==name)
- return &*i;
-
- return 0;
+ auto i = find_if(parts, [&name](const Part &p){ return p.get_name()==name; });
+ return (i!=parts.end() ? &*i : 0);
}
bool Style::compare_states(State s1, State s2) const
if(c1.r!=c2.r || c1.g!=c2.g || c1.b!=c2.b)
return true;
- for(PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
- if(i->get_graphic(s1)!=i->get_graphic(s2))
+ for(const Part &p: parts)
+ if(p.get_graphic(s1)!=p.get_graphic(s2))
return true;
return false;
+#include <msp/core/algorithm.h>
#include <msp/gl/matrix.h>
#include <msp/gl/meshbuilder.h>
#include <msp/gl/texture2d.h>
{
const GL::Font &font = style->get_font();
float font_size = style->get_font_size();
- for(vector<Line>::iterator i=lines.begin(); i!=lines.end(); ++i)
- i->width = static_cast<unsigned>(font.get_string_width(text.substr(i->start, i->bytes))*font_size);
+ for(Line &l: lines)
+ l.width = static_cast<unsigned>(font.get_string_width(text.substr(l.start, l.bytes))*font_size);
}
}
unsigned Text::get_width() const
{
unsigned width = 0;
- for(vector<Line>::const_iterator i=lines.begin(); i!=lines.end(); ++i)
- width = max(width, i->width);
+ for(const Line &l: lines)
+ width = max(width, l.width);
return width;
}
check_alignment(pos+len);
text.erase(pos, len);
- vector<Line>::iterator i;
- for(i=lines.begin(); (i!=lines.end() && i->start+i->bytes<pos); ++i) ;
+ auto i = find_if(lines, [pos](const Line &l){ return l.start+l.bytes>=pos; });
if(pos+len>i->start+i->bytes)
find_lines();
find_lines();
else
{
- vector<Line>::iterator i;
- for(i=lines.begin(); (i!=lines.end() && i->start+i->bytes<pos); ++i) ;
+ auto i = find_if(lines, [pos](const Line &l){ return l.start+l.bytes>=pos; });
i->bytes += s.size();
i->length = count_characters(i->start, i->bytes);
return offs;
StringCodec::Utf8::Decoder dec(StringCodec::IGNORE_ERRORS);
- string::const_iterator i = text.begin()+offs;
+ auto i = text.begin()+offs;
if(change>0)
{
for(; change>0; --change)
while(change<0 && i!=text.begin())
{
--i;
- string::const_iterator j = i;
+ auto j = i;
if(dec.decode_char(text, j)!=-1)
++change;
}
else
{
StringCodec::Utf8::Decoder dec;
- string::const_iterator i = text.begin()+line.start;
+ auto i = text.begin()+line.start;
for(col=min(col, line.length); col; --col)
dec.decode_char(text, i);
return i-text.begin();
unsigned Text::count_characters(unsigned start, unsigned bytes) const
{
StringCodec::Utf8::Decoder dec;
- string::const_iterator i = text.begin()+start;
- string::const_iterator end = i+bytes;
+ auto i = text.begin()+start;
+ auto end = i+bytes;
unsigned count = 0;
for(; i<end; dec.decode_char(text, i))
++count;
void Text::check_alignment(unsigned offs) const
{
StringCodec::Utf8::Decoder dec;
- string::const_iterator i = text.begin()+offs;
+ auto i = text.begin()+offs;
dec.decode_char(text, i);
}
{
if(i==data.row)
{
- string::const_iterator begin = text.begin()+lines[i].start;
- string::const_iterator j = begin;
+ auto begin = text.begin()+lines[i].start;
+ auto j = begin;
if(lines[i].length==lines[i].bytes)
j += data.col;
else
void Toggle::exclude_siblings()
{
- const list<Widget *> &siblings = parent->get_children();
- for(list<Widget *>::const_iterator i=siblings.begin(); i!=siblings.end(); ++i)
- if(Toggle *tgl = dynamic_cast<Toggle *>(*i))
+ for(Widget *w: parent->get_children())
+ if(Toggle *tgl = dynamic_cast<Toggle *>(w))
if(tgl!=this && tgl->get_exclusive() && tgl->get_value())
tgl->set_value(false);
}
return;
ageom = Geometry(geom.x, geom.y, 0, 0);
- const Style::PartSeq &parts = style->get_parts();
- for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ for(const Part &p: style->get_parts())
{
- if(i->get_name().empty())
+ if(p.get_name().empty())
{
- const Geometry &pgeom = i->get_geometry();
- const Sides &pmargin = i->get_margin();
+ const Geometry &pgeom = p.get_geometry();
+ const Sides &pmargin = p.get_margin();
ageom.w = max(ageom.w, pgeom.w+pmargin.left+pmargin.right);
ageom.h = max(ageom.h, pgeom.h+pmargin.top+pmargin.bottom);
}
else
- autosize_special(*i, ageom);
+ autosize_special(p, ageom);
}
}
return;
PartCache::Rebuild rebuild_cache(part_cache);
- const Style::PartSeq &parts = style->get_parts();
- for(Style::PartSeq::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ for(const Part &p: style->get_parts())
{
- if(i->get_name().empty())
- i->build(geom, state, part_cache);
+ if(p.get_name().empty())
+ p.build(geom, state, part_cache);
else
- rebuild_special(*i);
+ rebuild_special(p);
}
}
int y = 0;
map_coords_to_root(x, y);
renderer.set_matrix(GL::Matrix::translation(x, y, 0));
- const PartCache::PartList &parts = part_cache.get_parts();
- for(PartCache::PartList::const_iterator i=parts.begin(); i!=parts.end(); ++i)
+ for(const CachedPart &p: part_cache.get_parts())
{
- if(i->mesh && i->texture)
+ if(p.mesh && p.texture)
{
- renderer.set_texture(texture_tag, i->texture, &style->get_sampler());
- i->mesh->draw(renderer);
+ renderer.set_texture(texture_tag, p.texture, &style->get_sampler());
+ p.mesh->draw(renderer);
}
- else if(i->part)
- render_special(*i->part, renderer);
+ else if(p.part)
+ render_special(*p.part, renderer);
}
}