Add padding support to the hBox class; also, ensure that we set the default alignment/padding in the constructor; finally, improve the Doxygen documentation.
git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6172 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
96509127b1
commit
3a4b246ff7
|
@ -84,6 +84,12 @@ void hBoxInit(hBox *self, const char *id)
|
|||
|
||||
// Set our type
|
||||
WIDGET(self)->classInfo = &hBoxClassInfo;
|
||||
|
||||
// Default vertical alignment is top
|
||||
self->vAlignment = TOP;
|
||||
|
||||
// Default padding is 0
|
||||
self->padding = 0;
|
||||
}
|
||||
|
||||
void hBoxDestroyImpl(widget *self)
|
||||
|
@ -125,8 +131,11 @@ bool hBoxDoLayoutImpl(widget *self)
|
|||
childSizeInfo[i].maxSize = widgetGetMaxSize(child);
|
||||
}
|
||||
|
||||
// Work out how much horizontal space is available for child widgets
|
||||
temp = self->size.x - (numChildren - 1) * HBOX(self)->padding;
|
||||
|
||||
// Next do y-axis positioning and initial x-axis sizing
|
||||
for (i = 0, temp = self->size.x; i < numChildren; i++)
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
sizeInfo *child = &childSizeInfo[i];
|
||||
|
||||
|
@ -184,7 +193,7 @@ bool hBoxDoLayoutImpl(widget *self)
|
|||
|
||||
widgetReposition(child, temp, childSize->offset.y);
|
||||
|
||||
temp += child->size.x;
|
||||
temp += child->size.x + HBOX(self)->padding;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -202,12 +211,40 @@ void hBoxSetVAlign(hBox *self, vAlign v)
|
|||
}
|
||||
}
|
||||
|
||||
bool hBoxSetPadding(hBox *self, int padding)
|
||||
{
|
||||
// Save the current padding
|
||||
int oldPadding = self->padding;
|
||||
|
||||
// Set the padding
|
||||
self->padding = padding;
|
||||
|
||||
// Redo the window's layout
|
||||
if (widgetDoLayout(widgetGetRoot(WIDGET(self))))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// New padding is untenable
|
||||
else
|
||||
{
|
||||
// Restore the old padding
|
||||
self->padding = oldPadding;
|
||||
|
||||
// Restore the layout
|
||||
widgetDoLayout(widgetGetRoot(WIDGET(self)));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
size hBoxGetMinSizeImpl(widget *self)
|
||||
{
|
||||
size minSize = { 0, 0 };
|
||||
int i;
|
||||
const int numChildren = vectorSize(self->children);
|
||||
|
||||
for (i = 0; i < vectorSize(self->children); i++)
|
||||
// Sum up the minimum size of our children
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
const size minChildSize = widgetGetMinSize(vectorAt(self->children, i));
|
||||
|
||||
|
@ -215,6 +252,9 @@ size hBoxGetMinSizeImpl(widget *self)
|
|||
minSize.y = MAX(minSize.y, minChildSize.y);
|
||||
}
|
||||
|
||||
// Factor in padding between children
|
||||
minSize.x += (numChildren - 1) * HBOX(self)->padding;
|
||||
|
||||
return minSize;
|
||||
}
|
||||
|
||||
|
@ -222,8 +262,10 @@ size hBoxGetMaxSizeImpl(widget *self)
|
|||
{
|
||||
size maxSize = { 0, 0 };
|
||||
int i;
|
||||
const int numChildren = vectorSize(self->children);
|
||||
|
||||
for (i = 0; i < vectorSize(self->children); i++)
|
||||
// Sum up the maximum size of our children
|
||||
for (i = 0; i < numChildren; i++)
|
||||
{
|
||||
const size maxChildSize = widgetGetMaxSize(vectorAt(self->children, i));
|
||||
|
||||
|
@ -231,6 +273,9 @@ size hBoxGetMaxSizeImpl(widget *self)
|
|||
maxSize.y = MAX(maxSize.y, maxChildSize.y);
|
||||
}
|
||||
|
||||
// Factor in padding between children
|
||||
maxSize.x += (numChildren - 1) * HBOX(self)->padding;
|
||||
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,20 +41,25 @@ struct _hBoxVtbl
|
|||
*/
|
||||
struct _hBox
|
||||
{
|
||||
/*
|
||||
/**
|
||||
* Parent
|
||||
*/
|
||||
struct _widget widget;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Our vtable
|
||||
*/
|
||||
hBoxVtbl *vtbl;
|
||||
|
||||
/*
|
||||
/**
|
||||
* Child alignment
|
||||
*/
|
||||
vAlign vAlignment;
|
||||
|
||||
/**
|
||||
* Padding between children
|
||||
*/
|
||||
int padding;
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -99,4 +104,18 @@ hBox *hBoxCreate(const char *id);
|
|||
*/
|
||||
void hBoxSetVAlign(hBox *self, vAlign v);
|
||||
|
||||
/**
|
||||
* Sets the padding (spacing) between child widgets. Since changing the padding
|
||||
* affects the minimum/maximum size of the hBox a call to this method causes the
|
||||
* window layout to be redone.
|
||||
*
|
||||
* Should the new padding result in an untenable layout then the padding is
|
||||
* restored to its previous value and the layout restored.
|
||||
*
|
||||
* @param self The hBox to set the padding property of.
|
||||
* @param padding The amount of padding to apply.
|
||||
* @return true if the padding was changed successfully; false otherwise.
|
||||
*/
|
||||
bool hBoxSetPadding(hBox *self, int padding);
|
||||
|
||||
#endif /*HBOX_H_*/
|
||||
|
|
Loading…
Reference in New Issue