From a0921163b00112c41d9024f3ec4286de341bd65a Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Wed, 15 Nov 2023 00:36:31 +0100 Subject: [PATCH] Improved maintainability of hlayout code. --- src/lib/aqdiagram/placement/o_hlayout.c | 56 ++++++++++++++----------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/lib/aqdiagram/placement/o_hlayout.c b/src/lib/aqdiagram/placement/o_hlayout.c index 7441b97..88f6a61 100644 --- a/src/lib/aqdiagram/placement/o_hlayout.c +++ b/src/lib/aqdiagram/placement/o_hlayout.c @@ -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 */ +} +