| 1 |
/* |
| 2 |
* Copyright (C) 2004 Ivo Danihelka ([email protected]) |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; either version 2 of the License, or |
| 7 |
* (at your option) any later version. |
| 8 |
*/ |
| 9 |
#include "VBox.h" |
| 10 |
|
| 11 |
#include "minmax.h" |
| 12 |
|
| 13 |
//----------------------------------------------------------------- |
| 14 |
/** |
| 15 |
* Starts as empty box. |
| 16 |
*/ |
| 17 |
VBox::VBox() |
| 18 |
{ |
| 19 |
m_w = 0; |
| 20 |
m_h = 0; |
| 21 |
m_centered = false; |
| 22 |
} |
| 23 |
//----------------------------------------------------------------- |
| 24 |
/** |
| 25 |
* Place widget to the lowest vertical place. |
| 26 |
*/ |
| 27 |
void |
| 28 |
VBox::addWidget(IWidget *new_widget) |
| 29 |
{ |
| 30 |
m_widgets.push_back(new_widget); |
| 31 |
m_w = max(m_w, new_widget->getW()); |
| 32 |
int shiftX = 0; |
| 33 |
if (m_centered) { |
| 34 |
shiftX = (m_w - new_widget->getW()) / 2; |
| 35 |
} |
| 36 |
new_widget->setShift(m_shift.plus(V2(shiftX, m_h))); |
| 37 |
m_h += new_widget->getH(); |
| 38 |
} |
| 39 |
//----------------------------------------------------------------- |
| 40 |
/** |
| 41 |
* Update shift for all subwidgets. |
| 42 |
*/ |
| 43 |
void |
| 44 |
VBox::setShift(const V2 &shift) |
| 45 |
{ |
| 46 |
m_shift = shift; |
| 47 |
int height = 0; |
| 48 |
t_widgets::iterator end = m_widgets.end(); |
| 49 |
for (t_widgets::iterator i = m_widgets.begin(); i != end; ++i) { |
| 50 |
int shiftX = 0; |
| 51 |
if (m_centered) { |
| 52 |
shiftX = (m_w - (*i)->getW()) / 2; |
| 53 |
} |
| 54 |
(*i)->setShift(m_shift.plus(V2(shiftX, height))); |
| 55 |
height += (*i)->getH(); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
|