gui2: more work on preparing code sharing for all layout modules.

This commit is contained in:
Martin Preuss
2026-04-10 00:07:53 +02:00
parent 12cdc6c637
commit 7d556c0f26
2 changed files with 314 additions and 139 deletions

View File

@@ -97,27 +97,15 @@ HLayout2_Init:
; @clobbers any, !Y
HLayout2_OnLayout:
; create layout context
bigcall OBJ_CountDirectChildren ; r16=num of children (r18, r19)
tst r16
breq HLayout2_OnLayout_ret
push r16
bigcall LayoutCtx_new ; X=new ctx (r16, r17, r18, r19, r24, r25)
pop r16
; create and preset context
rcall LayoutCtx_CreateContextFor1D
brcc HLayout2_OnLayout_ret
; set borders and spacing in layout context
bigcall Widget_GetBorderAndSpacing ; (none)
adiw xh:xl, LAYOUT_CTX_OFFS_BORDERS
st X+, r23 ; store border
st X, r22 ; store spacing
sbiw xh:xl, (LAYOUT_CTX_OFFS_BORDERS+1)
; do layout
mov r25, r16
rcall hLayout2Horizontally
rcall hLayout2Vertically
; release layout context
bigcall LayoutCtx_free
; force re-drawing of this widget, clear layout bit
ldd r16, Y+OBJECT_OFFS_FLAGS
sbr r16, (1<<WIDGET_FLAGS_DIRTY_BIT)
@@ -173,19 +161,61 @@ HLayout2_OnGetDefaultWidth:
; @clobbers any, !X, !Y
hLayout2Vertically:
rcall hLayout2PrepareVertical ; (any, !R25, !X, !Y)
rcall hLayout2ReadLayoutWriteVertical ; (r16-r24)
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2PrepareVertical
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers any, !R25, !X, !Y,
hLayout2PrepareVertical:
push xl
push xh
push yl
push yh
push r25
rcall Layout2_SetDefaultHeights
pop r25
pop yh
pop yl
pop xh
pop xl
ldd r20, Y+WIDGET_OFFS_HEIGHT_LO
ldd r21, Y+WIDGET_OFFS_HEIGHT_HI
adiw xh:xl, LAYOUT_CTX_OFFS_TOTALSIZE_LO
st X+, r20
st X, r21
sbiw xh:xl, (LAYOUT_CTX_OFFS_TOTALSIZE_LO+1)
; layout
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2ReadLayoutWriteHorizontal
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers r16-r24
hLayout2ReadLayoutWriteVertical:
push yl
push yh
push r24
bigcall OBJ_GetFirstChild
mov yl, r18
mov yh, r19
; read positions and flags into new layout context
push r25
push yl
@@ -194,21 +224,24 @@ hLayout2Vertically:
pop yh
pop yl
pop r25
; get default heights
push r25
push yl
push yh
bigcall LayoutCtx_SetDefaultHeightContiguous
pop yh
pop yl
pop r25
pop r24
; layout
bigcall LayoutCtx_GetMaxDefaultSize ; r19:r18=max default size (r18, r19, r20, r21, r24)
bigcall LayoutCtx_GetMaxSize ; r19:r18=max default size (r18, r19, r20, r21, r24)
bigcall LayoutCtx_SetFixedSize ; (r24)
push r25
bigcall LayoutCtxSetPos ; (r16-r25)
pop r25
; pack
push r25
push yl
push yh
bigcall LayoutCtx_PackYContiguous
pop yh
pop yl
pop r25
; write back dims
push r25
push yl
@@ -224,6 +257,9 @@ hLayout2Vertically:
; ---------------------------------------------------------------------------
; @routine hLayout2Horizontally
;
@@ -233,6 +269,36 @@ hLayout2Vertically:
; @clobbers any, !Y
hLayout2Horizontally:
rcall hLayout2PrepareHorizontal ; (any, !R25, !X, !Y)
rcall hLayout2ReadLayoutWriteHorizontal ; (r16-r24)
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2PrepareHorizontal
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers any, !R25, !X, !Y,
hLayout2PrepareHorizontal:
push xl
push xh
push yl
push yh
push r25
rcall Layout2_SetDefaultWidths ; (any, !Y)
pop r25
pop yh
pop yl
pop xh
pop xl
; setup layout context for horizontal operations
ldd r20, Y+WIDGET_OFFS_WIDTH_LO
ldd r21, Y+WIDGET_OFFS_WIDTH_HI
@@ -240,27 +306,33 @@ hLayout2Horizontally:
st X+, r20
st X, r21
sbiw xh:xl, (LAYOUT_CTX_OFFS_TOTALSIZE_LO+1)
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2ReadLayoutWriteHorizontal
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers r16-r24
hLayout2ReadLayoutWriteHorizontal:
; layout
ldd r24, Y+HLAYOUT2_OFFS_MODE
push yl
push yh
push r24
bigcall OBJ_GetFirstChild
bigcall OBJ_GetFirstChild ; (none)
mov yl, r18
mov yh, r19
; read X positions and flags into new layout context
push r25
push yl
push yh
bigcall LayoutCtx_ReadXDimsContiguous
pop yh
pop yl
pop r25
; get default widths
push r25
push yl
push yh
bigcall LayoutCtx_SetDefaultWidthContiguous
bigcall LayoutCtx_ReadXDimsContiguous ; (r16, r18, r19, r24, Y)
pop yh
pop yl
pop r25
@@ -268,21 +340,31 @@ hLayout2Horizontally:
; layout
push r25
cpi r24, HLAYOUT_MODE_SPREAD
breq hLayout2Horizontally_spread
bigcall LayoutCtx_LayoutExpand ; (r16-r25)
rjmp hLayout2Horizontally_writeBack
hLayout2Horizontally_spread:
bigcall LayoutCtx_LayoutSpread ; (r16-r25)
hLayout2Horizontally_writeBack:
breq hLayout2ReadLayoutWriteHorizontal_spread
bigcall LayoutCtx_LayoutExpand ; (r16-r25)
rjmp hLayout2ReadLayoutWriteHorizontal_pack
hLayout2ReadLayoutWriteHorizontal_spread:
bigcall LayoutCtx_LayoutSpread ; (r16-r25)
hLayout2ReadLayoutWriteHorizontal_pack:
pop r25
; pack
push r25
push yl
push yh
bigcall LayoutCtx_PackXContiguous ; (r16-r21, r24, r25, Y)
pop yh
pop yl
pop r25
; write back dims
push r25
push yl
push yh
bigcall LayoutCtx_WriteXDimsContiguous
bigcall LayoutCtx_WriteXDimsContiguous ; (r16, r18, r19, r24, Y)
pop yh
pop yl
pop r25
pop yh
pop yl
ret
@@ -294,6 +376,7 @@ hLayout2Horizontally_writeBack:
; ***************************************************************************
; data in FLASH