Improved maintainability of hlayout code.

This commit is contained in:
Martin Preuss
2023-11-15 00:36:31 +01:00
parent 9f5e43063a
commit a0921163b0

View File

@@ -20,6 +20,7 @@
static int _layout(AQDG_OBJECT *object);
static void _vAlignChild(AQDG_OBJECT *child, uint32_t childOpts, int parentHeight, int borderTop, int borderBottom);
static void _hStretchBelow(AQDG_OBJECT *object, int selfWidth, int minWidth, int hSpacing, int stretchables);
@@ -44,7 +45,6 @@ AQDG_OBJECT *AQDG_HLayoutObject_new(AQDG_OBJECT *parent, uint32_t options)
int _layout(AQDG_OBJECT *object)
{
AQDG_OBJECT *child;
@@ -90,31 +90,9 @@ int _layout(AQDG_OBJECT *object)
}
minWidth+=AQDG_Object_GetBorderRight(object);
if (stretchables && (selfWidth>minWidth)) {
int diffWidth;
int toAdd;
int pos;
if (stretchables && (selfWidth>minWidth))
_hStretchBelow(object, selfWidth, minWidth, hSpacing, stretchables);
diffWidth=selfWidth-minWidth;
toAdd=diffWidth/stretchables;
pos=AQDG_Object_GetBorderLeft(object);
child=AQDG_Object_Tree2_GetFirstChild(object);
while(child) {
int w;
AQDG_Object_SetRelativeX(child, pos);
w=AQDG_Object_GetWidth(child);
if (AQDG_Object_GetOptions(child) & AQDG_OBJECT_OPTIONS_STRETCHX) {
w+=toAdd;
AQDG_Object_SetWidth(child, w);
}
pos+=w;
child=AQDG_Object_Tree2_GetNext(child);
if (child)
pos+=hSpacing;
} /* while */
}
return 0;
}
@@ -148,6 +126,34 @@ void _vAlignChild(AQDG_OBJECT *child, uint32_t childOpts, int parentHeight, int
void _hStretchBelow(AQDG_OBJECT *object, int selfWidth, int minWidth, int hSpacing, int stretchables)
{
AQDG_OBJECT *child;
int diffWidth;
int toAdd;
int pos;
diffWidth=selfWidth-minWidth;
toAdd=diffWidth/stretchables;
pos=AQDG_Object_GetBorderLeft(object);
child=AQDG_Object_Tree2_GetFirstChild(object);
while(child) {
int w;
AQDG_Object_SetRelativeX(child, pos);
w=AQDG_Object_GetWidth(child);
if (AQDG_Object_GetOptions(child) & AQDG_OBJECT_OPTIONS_STRETCHX) {
w+=toAdd;
AQDG_Object_SetWidth(child, w);
}
pos+=w;
child=AQDG_Object_Tree2_GetNext(child);
if (child)
pos+=hSpacing;
} /* while */
}