Fix some bugs with the grid flags.

The flags did an uncorrect test on the flags, now properly uses a mask.
Also added better detection for invalid flags. Avoided grow and
alignment both to be set (leading to invalid flags) and removed all
occurances in the configs.
This commit is contained in:
Mark de Wever 2008-09-21 09:25:36 +00:00
parent 64c366064e
commit bcb10dfc79
7 changed files with 42 additions and 24 deletions

View file

@ -63,7 +63,6 @@
border = "all"
border_size = 5
horizontal_alignment = "right"
[listbox]
id = "language_list"

View file

@ -184,7 +184,6 @@
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "message"
@ -267,7 +266,6 @@
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "message"

View file

@ -97,7 +97,6 @@
border = "all"
border_size = 5
horizontal_alignment = "right"
[listbox]
id = "method_list"

View file

@ -123,7 +123,6 @@
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "name"
@ -139,8 +138,6 @@
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id = "address"

View file

@ -84,6 +84,8 @@ void tgrid::set_child(twidget* widget, const unsigned row,
const unsigned col, const unsigned flags, const unsigned border_size)
{
assert(row < rows_ && col < cols_);
assert(flags & VERTICAL_MASK);
assert(flags & HORIZONTAL_MASK);
tchild& cell = child(row, col);
@ -738,7 +740,7 @@ void tgrid::tchild::set_size(tpoint orig, tpoint size)
}
const tpoint maximum_size = widget()->get_maximum_size();
if((flags_ & (HORIZONTAL_GROW_SEND_TO_CLIENT | VERTICAL_GROW_SEND_TO_CLIENT))
if((flags_ & (HORIZONTAL_MASK | VERTICAL_MASK))
== (HORIZONTAL_GROW_SEND_TO_CLIENT | VERTICAL_GROW_SEND_TO_CLIENT)) {
if(maximum_size == tpoint(0,0) || size <= maximum_size) {
@ -757,7 +759,9 @@ void tgrid::tchild::set_size(tpoint orig, tpoint size)
std::min(size.y, best_size.y));
tpoint widget_orig = orig;
if(flags_ & VERTICAL_GROW_SEND_TO_CLIENT) {
const unsigned v_flag = flags_ & VERTICAL_MASK;
if(v_flag == VERTICAL_GROW_SEND_TO_CLIENT) {
if(maximum_size.y) {
widget_size.y = std::min(size.y, maximum_size.y);
} else {
@ -766,27 +770,30 @@ void tgrid::tchild::set_size(tpoint orig, tpoint size)
DBG_G << "Grid cell: vertical growing from "
<< best_size.y << " to " << widget_size.y << ".\n";
} else if((flags_ & VERTICAL_ALIGN_TOP) == VERTICAL_ALIGN_TOP) {
} else if(v_flag == VERTICAL_ALIGN_TOP) {
// Do nothing.
DBG_G << "Grid cell: vertically aligned at the top.\n";
} else if((flags_ & VERTICAL_ALIGN_CENTER) == VERTICAL_ALIGN_CENTER) {
} else if(v_flag == VERTICAL_ALIGN_CENTER) {
widget_orig.y += (size.y - widget_size.y) / 2;
DBG_G << "Grid cell: vertically centred.\n";
} else if((flags_ & VERTICAL_ALIGN_BOTTOM) == VERTICAL_ALIGN_BOTTOM) {
} else if(v_flag == VERTICAL_ALIGN_BOTTOM) {
widget_orig.y += (size.y - widget_size.y);
DBG_G << "Grid cell: vertically aligned at the bottom.\n";
} else {
ERR_G << "Grid cell: No vertical alignment specified.\n";
ERR_G << "Grid cell: Invalid vertical alignment '"
<< v_flag << "' specified.\n";
assert(false);
}
if(flags_ & HORIZONTAL_GROW_SEND_TO_CLIENT) {
const unsigned h_flag = flags_ & HORIZONTAL_MASK;
if(h_flag == HORIZONTAL_GROW_SEND_TO_CLIENT) {
if(maximum_size.x) {
widget_size.x = std::min(size.x, maximum_size.x);
} else {
@ -795,22 +802,23 @@ void tgrid::tchild::set_size(tpoint orig, tpoint size)
DBG_G << "Grid cell: horizontal growing from "
<< best_size.x << " to " << widget_size.x << ".\n";
} else if((flags_ & HORIZONTAL_ALIGN_LEFT) == HORIZONTAL_ALIGN_LEFT) {
} else if(h_flag == HORIZONTAL_ALIGN_LEFT) {
// Do nothing.
DBG_G << "Grid cell: horizontally aligned at the left.\n";
} else if((flags_ & HORIZONTAL_ALIGN_CENTER) == HORIZONTAL_ALIGN_CENTER) {
} else if(h_flag == HORIZONTAL_ALIGN_CENTER) {
widget_orig.x += (size.x - widget_size.x) / 2;
DBG_G << "Grid cell: horizontally centred.\n";
} else if((flags_ & HORIZONTAL_ALIGN_RIGHT) == HORIZONTAL_ALIGN_RIGHT) {
} else if(h_flag == HORIZONTAL_ALIGN_RIGHT) {
widget_orig.x += (size.x - widget_size.x);
DBG_G << "Grid cell: horizontally aligned at the right.\n";
} else {
ERR_G << "Grid cell: No horizontal alignment specified.\n";
ERR_G << "Grid cell: No horizontal alignment '"
<< h_flag << "' specified.\n";
assert(false);
}

View file

@ -41,11 +41,13 @@ public:
static const unsigned VERTICAL_ALIGN_TOP = 2 << 0;
static const unsigned VERTICAL_ALIGN_CENTER = 3 << 0;
static const unsigned VERTICAL_ALIGN_BOTTOM = 4 << 0;
static const unsigned VERTICAL_MASK = 7 << 0;
static const unsigned HORIZONTAL_GROW_SEND_TO_CLIENT = 1 << 3;
static const unsigned HORIZONTAL_ALIGN_LEFT = 2 << 3;
static const unsigned HORIZONTAL_ALIGN_CENTER = 3 << 3;
static const unsigned HORIZONTAL_ALIGN_RIGHT = 4 << 3;
static const unsigned HORIZONTAL_MASK = 7 << 3;
static const unsigned BORDER_TOP = 1 << 6;
static const unsigned BORDER_BOTTOM = 1 << 7;

View file

@ -116,17 +116,30 @@ unsigned read_flags(const config& cfg)
{
unsigned flags = 0;
// Read the flags. FIXME document.
flags |= get_v_align(cfg["vertical_alignment"]);
flags |= get_h_align(cfg["horizontal_alignment"]);
const unsigned v_flags = get_v_align(cfg["vertical_alignment"]);
const unsigned h_flags = get_h_align(cfg["horizontal_alignment"]);
flags |= get_border( utils::split(cfg["border"]));
if(utils::string_bool(cfg["vertical_grow"])) {
flags |= tgrid::VERTICAL_GROW_SEND_TO_CLIENT;
if(! (cfg["vertical_alignment"]).empty()) {
ERR_G_P << "vertical_grow and vertical_alignment "
"can't be combined, alignment is ignored.\n";
}
} else {
flags |= v_flags;
}
if(utils::string_bool(cfg["horizontal_grow"])) {
flags |= tgrid::HORIZONTAL_GROW_SEND_TO_CLIENT;
if(! (cfg["horizontal_alignment"]).empty()) {
ERR_G_P << "horizontal_grow and horizontal_alignment "
"can't be combined, alignment is ignored.\n";
}
} else {
flags |= h_flags;
}
return flags;
@ -407,10 +420,12 @@ tbuilder_grid::tbuilder_grid(const config& cfg) :
*
* vertical_alignment (v_align = "")
* The vertical alignment of the widget in
* the grid cell.
* the grid cell. (This value is ignored if
* vertical_grow is true.)
* horizontal_alignment (h_align = "")
* The horizontal alignment of the widget in
* the grid cell.
* the grid cell.(This value is ignored if
* horizontal_grow is true.)
*
* vertical_grow (bool = false) Does the widget grow in vertical
* direction when the grid cell grows in the