Use generic layout algorithms.
This commit is contained in:
@@ -76,6 +76,16 @@ void AQDG_Placement_LayoutSecondaryAxis(AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElemen
|
|||||||
AQDG_PLACEMENT_LAYOUT_ELEMENT *ptr;
|
AQDG_PLACEMENT_LAYOUT_ELEMENT *ptr;
|
||||||
|
|
||||||
rawLength=destLength-borderBegin-borderEnd;
|
rawLength=destLength-borderBegin-borderEnd;
|
||||||
|
|
||||||
|
/* stretch on request */
|
||||||
|
ptr=ptrElements;
|
||||||
|
for (i=0; i<numElements; i++) {
|
||||||
|
if (ptr->opts & AQDG_PLACEMENT_LAYOUT_ELEMENT_OPTS_STRETCH)
|
||||||
|
ptr->length=rawLength;
|
||||||
|
ptr++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* place children */
|
||||||
ptr=ptrElements;
|
ptr=ptrElements;
|
||||||
for (i=0; i<numElements; i++) {
|
for (i=0; i<numElements; i++) {
|
||||||
int pos;
|
int pos;
|
||||||
@@ -89,7 +99,7 @@ void AQDG_Placement_LayoutSecondaryAxis(AQDG_PLACEMENT_LAYOUT_ELEMENT *ptrElemen
|
|||||||
else
|
else
|
||||||
pos=borderBegin;
|
pos=borderBegin;
|
||||||
|
|
||||||
ptr->pos=(pos>borderBegin)?pos:borderBegin;
|
ptr->pos=(pos<borderBegin)?borderBegin:pos;
|
||||||
ptr++;
|
ptr++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,8 +123,8 @@ int test1(GWEN_UNUSED GWEN_TEST_MODULE *mod)
|
|||||||
DBG_ERROR(AQDG_LOGDOMAIN, "WIDTH of box 2 is not 70 (%d)", w);
|
DBG_ERROR(AQDG_LOGDOMAIN, "WIDTH of box 2 is not 70 (%d)", w);
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
if (y!=16) {
|
if (y!=19) {
|
||||||
DBG_ERROR(AQDG_LOGDOMAIN, "Y of box 2 is not 16 (%d)", y);
|
DBG_ERROR(AQDG_LOGDOMAIN, "Y of box 2 is not 19 (%d)", y);
|
||||||
errors++;
|
errors++;
|
||||||
}
|
}
|
||||||
if (h!=10) {
|
if (h!=10) {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "o_hlayout.h"
|
#include "o_hlayout.h"
|
||||||
|
#include "o_layout.h"
|
||||||
|
|
||||||
|
|
||||||
/* ------------------------------------------------------------------------------------------------
|
/* ------------------------------------------------------------------------------------------------
|
||||||
@@ -19,8 +20,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static int _layout(AQDG_OBJECT *object);
|
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);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -47,114 +46,39 @@ AQDG_OBJECT *AQDG_HLayoutObject_new(AQDG_OBJECT *parent, uint32_t options)
|
|||||||
|
|
||||||
int _layout(AQDG_OBJECT *object)
|
int _layout(AQDG_OBJECT *object)
|
||||||
{
|
{
|
||||||
AQDG_OBJECT *child;
|
int num;
|
||||||
int stretchables=0;
|
|
||||||
int minWidth;
|
|
||||||
int selfWidth;
|
|
||||||
int selfHeight;
|
|
||||||
int hSpacing;
|
|
||||||
int borderTop;
|
|
||||||
int borderBottom;
|
|
||||||
|
|
||||||
selfWidth=AQDG_Object_GetWidth(object);
|
num=AQDG_LayoutObject_CountDirectChildren(object);
|
||||||
selfHeight=AQDG_Object_GetHeight(object);
|
if (num) {
|
||||||
borderTop=AQDG_Object_GetBorderTop(object);
|
AQDG_PLACEMENT_LAYOUT_ELEMENT *elements;
|
||||||
borderBottom=AQDG_Object_GetBorderBottom(object);
|
|
||||||
hSpacing=AQDG_Object_GetHSpacing(object);
|
|
||||||
|
|
||||||
minWidth=AQDG_Object_GetBorderLeft(object);
|
AQDG_LayoutObject_SetChildrenWidths(object);
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(object);
|
elements=AQDG_LayoutObject_Children2ElementsX(object, num);
|
||||||
while(child) {
|
if (elements) {
|
||||||
int childWidth;
|
AQDG_Placement_LayoutAndStretch(elements, num,
|
||||||
uint32_t childOpts;
|
AQDG_Object_GetWidth(object),
|
||||||
|
AQDG_Object_GetBorderLeft(object),
|
||||||
childOpts=AQDG_Object_GetOptions(child);
|
AQDG_Object_GetBorderRight(object),
|
||||||
AQDG_Object_SetRelativeX(child, minWidth);
|
AQDG_Object_GetHSpacing(object));
|
||||||
|
AQDG_LayoutObject_ChildrenFromElementsX(object, elements, num);
|
||||||
if (childOpts & AQDG_OBJECT_OPTIONS_FIXEDWIDTH)
|
free(elements);
|
||||||
childWidth=AQDG_Object_GetWidth(child);
|
|
||||||
else {
|
|
||||||
childWidth=AQDG_Object_GetDefaultWidth(child);
|
|
||||||
AQDG_Object_SetWidth(child, childWidth);
|
|
||||||
}
|
}
|
||||||
minWidth+=childWidth;
|
|
||||||
|
|
||||||
_vAlignChild(child, childOpts, selfHeight, borderTop, borderBottom);
|
AQDG_LayoutObject_SetChildrenHeights(object);
|
||||||
|
elements=AQDG_LayoutObject_Children2ElementsY(object, num);
|
||||||
|
if (elements) {
|
||||||
|
AQDG_Placement_LayoutSecondaryAxis(elements, num,
|
||||||
|
AQDG_Object_GetHeight(object),
|
||||||
|
AQDG_Object_GetBorderTop(object),
|
||||||
|
AQDG_Object_GetBorderBottom(object));
|
||||||
|
AQDG_LayoutObject_ChildrenFromElementsY(object, elements, num);
|
||||||
|
free(elements);
|
||||||
|
}
|
||||||
|
|
||||||
if (childOpts & AQDG_OBJECT_OPTIONS_STRETCHX)
|
|
||||||
stretchables++;
|
|
||||||
|
|
||||||
child=AQDG_Object_Tree2_GetNext(child);
|
|
||||||
if (child)
|
|
||||||
minWidth+=hSpacing;
|
|
||||||
}
|
}
|
||||||
minWidth+=AQDG_Object_GetBorderRight(object);
|
|
||||||
|
|
||||||
if (stretchables && (selfWidth>minWidth))
|
|
||||||
_hStretchBelow(object, selfWidth, minWidth, hSpacing, stretchables);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _vAlignChild(AQDG_OBJECT *child, uint32_t childOpts, int parentHeight, int borderTop, int borderBottom)
|
|
||||||
{
|
|
||||||
int childHeight;
|
|
||||||
int y;
|
|
||||||
int rawParentHeight;
|
|
||||||
|
|
||||||
rawParentHeight=parentHeight-borderTop-borderBottom;
|
|
||||||
if (childOpts & AQDG_OBJECT_OPTIONS_FIXEDHEIGHT)
|
|
||||||
childHeight=AQDG_Object_GetHeight(child);
|
|
||||||
else {
|
|
||||||
if (childOpts & AQDG_OBJECT_OPTIONS_STRETCHY)
|
|
||||||
childHeight=rawParentHeight;
|
|
||||||
else
|
|
||||||
childHeight=AQDG_Object_GetDefaultHeight(child);
|
|
||||||
AQDG_Object_SetHeight(child, childHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (childOpts & AQDG_OBJECT_OPTIONS_VALIGNBOTTOM)
|
|
||||||
y=parentHeight-borderBottom-childHeight;
|
|
||||||
else if (childOpts & AQDG_OBJECT_OPTIONS_VALIGNCENTER)
|
|
||||||
y=(rawParentHeight-childHeight)/2;
|
|
||||||
else
|
|
||||||
y=borderTop;
|
|
||||||
AQDG_Object_SetRelativeY(child, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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 */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ AQDG_PLACEMENT_LAYOUT_ELEMENT *AQDG_LayoutObject_Children2ElementsX(const AQDG_O
|
|||||||
eptr=elements;
|
eptr=elements;
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(object);
|
child=AQDG_Object_Tree2_GetFirstChild(object);
|
||||||
while(child && num) {
|
while(child && num) {
|
||||||
_setElementFromObjectX(eptr, object);
|
_setElementFromObjectX(eptr, child);
|
||||||
child=AQDG_Object_Tree2_GetNext(child);
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
eptr++;
|
eptr++;
|
||||||
num--;
|
num--;
|
||||||
@@ -88,7 +88,7 @@ AQDG_PLACEMENT_LAYOUT_ELEMENT *AQDG_LayoutObject_Children2ElementsY(const AQDG_O
|
|||||||
eptr=elements;
|
eptr=elements;
|
||||||
child=AQDG_Object_Tree2_GetFirstChild(object);
|
child=AQDG_Object_Tree2_GetFirstChild(object);
|
||||||
while(child && num) {
|
while(child && num) {
|
||||||
_setElementFromObjectY(eptr, object);
|
_setElementFromObjectY(eptr, child);
|
||||||
child=AQDG_Object_Tree2_GetNext(child);
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
eptr++;
|
eptr++;
|
||||||
num--;
|
num--;
|
||||||
@@ -140,6 +140,34 @@ void AQDG_LayoutObject_ChildrenFromElementsY(AQDG_OBJECT *object, const AQDG_PLA
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_LayoutObject_SetChildrenWidths(AQDG_OBJECT *object)
|
||||||
|
{
|
||||||
|
AQDG_OBJECT *child;
|
||||||
|
|
||||||
|
child=AQDG_Object_Tree2_GetFirstChild(object);
|
||||||
|
while(child) {
|
||||||
|
if (!(AQDG_Object_GetOptions(child) & AQDG_OBJECT_OPTIONS_FIXEDWIDTH))
|
||||||
|
AQDG_Object_SetWidth(child, AQDG_Object_GetDefaultWidth(child));
|
||||||
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void AQDG_LayoutObject_SetChildrenHeights(AQDG_OBJECT *object)
|
||||||
|
{
|
||||||
|
AQDG_OBJECT *child;
|
||||||
|
|
||||||
|
child=AQDG_Object_Tree2_GetFirstChild(object);
|
||||||
|
while(child) {
|
||||||
|
if (!(AQDG_Object_GetOptions(child) & AQDG_OBJECT_OPTIONS_FIXEDHEIGHT))
|
||||||
|
AQDG_Object_SetHeight(child, AQDG_Object_GetDefaultHeight(child));
|
||||||
|
child=AQDG_Object_Tree2_GetNext(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _setElementFromObjectX(AQDG_PLACEMENT_LAYOUT_ELEMENT *eptr, const AQDG_OBJECT *object)
|
void _setElementFromObjectX(AQDG_PLACEMENT_LAYOUT_ELEMENT *eptr, const AQDG_OBJECT *object)
|
||||||
{
|
{
|
||||||
uint32_t opts;
|
uint32_t opts;
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ AQDG_API AQDG_PLACEMENT_LAYOUT_ELEMENT *AQDG_LayoutObject_Children2ElementsY(con
|
|||||||
AQDG_API void AQDG_LayoutObject_ChildrenFromElementsX(AQDG_OBJECT *object, const AQDG_PLACEMENT_LAYOUT_ELEMENT *elements, int num);
|
AQDG_API void AQDG_LayoutObject_ChildrenFromElementsX(AQDG_OBJECT *object, const AQDG_PLACEMENT_LAYOUT_ELEMENT *elements, int num);
|
||||||
AQDG_API void AQDG_LayoutObject_ChildrenFromElementsY(AQDG_OBJECT *object, const AQDG_PLACEMENT_LAYOUT_ELEMENT *elements, int num);
|
AQDG_API void AQDG_LayoutObject_ChildrenFromElementsY(AQDG_OBJECT *object, const AQDG_PLACEMENT_LAYOUT_ELEMENT *elements, int num);
|
||||||
|
|
||||||
|
AQDG_API void AQDG_LayoutObject_SetChildrenWidths(AQDG_OBJECT *object);
|
||||||
|
AQDG_API void AQDG_LayoutObject_SetChildrenHeights(AQDG_OBJECT *object);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user