} };
-Layout::~Layout()
-{
- for(Slot *s: slots)
- delete s;
-}
-
void Layout::set_container(Container &c)
{
if(container)
if(!container)
throw logic_error("!container");
- slots.push_back(new Slot(*this, wdg));
+ slots.emplace_back(make_unique<Slot>(*this, wdg));
update_slot_indices();
if(!arrangement_stack.empty())
arrangement_stack.back()->arrange(wdg);
void Layout::remove_widget(Widget &wdg)
{
- auto i = find_if(slots, [&wdg](Slot *s){ return &s->widget==&wdg; });
+ auto i = find_if(slots, [&wdg](const unique_ptr<Slot> &s){ return &s->widget==&wdg; });
if(i==slots.end())
return;
- for(Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
if(s!=*i)
{
for(auto k=s->constraints.begin(); k!=s->constraints.end(); )
{
- if(k->target==*i)
+ if(k->target==i->get())
k = s->constraints.erase(k);
else
++k;
}
}
- delete *i;
slots.erase(i);
update_slot_indices();
{
n_active_slots = 0;
size_t n_floating = 0;
- for(Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
{
if(s->widget.is_visible() || s->ghost)
{
n_slack_vars[0] = n_floating*2;
n_slack_vars[1] = n_floating*2;
- for(const Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
if(s->index>=0)
{
if(!s->floating)
{
for(unsigned j=0; j<2; ++j)
- if((s->*(pointers[j].packing)).gravity==0)
+ if((s.get()->*(pointers[j].packing)).gravity==0)
n_slack_vars[j] += 2;
}
Layout::Slot &Layout::get_slot_for_widget(Widget &wdg)
{
- auto i = find_if(slots, [&wdg](const Slot *s){ return &s->widget==&wdg; });
+ auto i = find_if(slots, [&wdg](const unique_ptr<Slot> &s){ return &s->widget==&wdg; });
if(i==slots.end())
throw hierarchy_error("widget not in layout");
solve_constraints(HORIZONTAL, UPDATE);
solve_constraints(VERTICAL, UPDATE);
- for(const Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
s->widget.set_geometry(s->geom);
}
LinearProgram linprog(n_active_slots*5+n_slack_vars[dir]+1);
float weight = slots.size()+1;
size_t k = n_active_slots*5;
- for(const Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
{
if(s->index<0)
continue;
else
{
if(!s->floating)
- objective[s->index*5] = (s->*(ptrs.packing)).gravity/weight;
- objective[s->index*5+1] = ((s->*(ptrs.packing)).expand ? weight : -1);
+ objective[s->index*5] = (s.get()->*(ptrs.packing)).gravity/weight;
+ objective[s->index*5+1] = ((s.get()->*(ptrs.packing)).expand ? weight : -1);
}
{
row.back() = geom.*(ptrs.dim)-margin.*(ptrs.high_margin);
}
- if(s->floating || (s->*(ptrs.packing)).gravity==0)
+ if(s->floating || (s.get()->*(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 = (s->*(ptrs.packing)).gravity*0.5+0.5;
+ float a = (s.get()->*(ptrs.packing)).gravity*0.5+0.5;
LinearProgram::Row row = linprog.add_row();
row[s->index*5] = 1;
row[s->index*5+1] = a;
if(mode==AUTOSIZE)
{
autosize_geom.*(ptrs.dim) = 0;
- for(const Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
if(s->index>=0)
{
int high_edge = linprog.get_variable(s->index*5)+linprog.get_variable(s->index*5+1);
}
else
{
- for(Slot *s: slots)
+ for(const unique_ptr<Slot> &s: slots)
if(s->index>=0)
{
s->geom.*(ptrs.pos) = linprog.get_variable(s->index*5);