From 722528f4e1ea8a57c07a6bf3ec0d5bac4d65facf Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 21 Mar 2026 08:27:52 +0100 Subject: [PATCH] gui2: more work on mlayout (first try) --- avr/modules/lcd2/gui2/base/mlayout.asm | 925 ++++++++++++++++++++++--- 1 file changed, 819 insertions(+), 106 deletions(-) diff --git a/avr/modules/lcd2/gui2/base/mlayout.asm b/avr/modules/lcd2/gui2/base/mlayout.asm index f2e25f9..5408f49 100644 --- a/avr/modules/lcd2/gui2/base/mlayout.asm +++ b/avr/modules/lcd2/gui2/base/mlayout.asm @@ -57,8 +57,8 @@ MLayout_new: push r20 push r21 - ldi r24, LOW(;LAYOUT_SIZE) - ldi r25, HIGH(;LAYOUT_SIZE) + ldi r24, LOW(MLAYOUT_SIZE) + ldi r25, HIGH(MLAYOUT_SIZE) bigcall Object_Alloc ; (!r16, !r17, !X) pop r21 pop r20 @@ -107,6 +107,14 @@ MLayout_Init: MLayout_OnLayout: + bigcall OBJ_GetFirstChild ; test for children + brcc MLayout_OnLayout_ret ; none, done here + ; TODO +MLayout_OnLayout_ret: + sec + ret + + MLayout_OnGetDefaultWidth: MLayout_OnGetDefaultHeight: ret @@ -119,21 +127,23 @@ MLayout_OnGetDefaultHeight: ; @param Y pointer to widget mLayoutColumnsHorizontally: - bigcall OBJ_GetFirstChild ; test for children - brcc mLayoutColumnsHorizontally_ret ; none, done here - ; preparations - rcall Layout_SetDefaultWidths ; calc default widths of children and store in Y+WIDGET_OFFS_TMP + rcall mLayoutSetDefaultWidths ; calc default widths of children and store in Y+WIDGET_OFFS_TMP rcall mLayoutCopyTmpToWidth ; copy to width fields for later rcall mLayoutGetBorders ; r22=spacing, r23=outer borders + ; calc size of each column and store it in the first widget of a column as TMP rcall mLayoutCalcAndSetSizesSkipped ; (r18-r31, !Y) ; calc total width of first row (which has the maximum sizes of each column) rcall mLayoutCalcFirstSizesContiguous ; r21:r20 width of first row (r16, r18, r19, r24, r25) - ; layout columns of first row - rcall mLayoutColumnsExpandFirstRow ; TODO: only if FILL set in PACK byte! + ; expand first row + ldd r18, Y+WIDGET_OFFS_WIDTH_LO + ldd r19, Y+WIDGET_OFFS_WIDTH_HI + ldi r22, (1< shift 2 times right + lsr r17 + andi r17, 3 + rcall mLayoutPackCell ; R21:R20=relative pos (r17, r18, r19) + add r20, r4 + adc r21, r5 + std Y+WIDGET_OFFS_Y_LO, r20 ; set new pos + std Y+WIDGET_OFFS_Y_HI, r21 + std Y+WIDGET_OFFS_HEIGHT_LO, r18 ; set new size + std Y+WIDGET_OFFS_HEIGHT_HI, r19 + add r4, r18 ; advance pos + adc r5, r19 + bigcall OBJ_GetNext + brcc mLayoutColumnsPositionY_done + mov yl, r18 + mov yh, r19 + dec r24 + brne mLayoutColumnsPositionY_loop2 + rjmp mLayoutColumnsPositionY_loop1 +mLayoutColumnsPositionY_done: + pop yh + pop yl + ret +; @end + + + ; --------------------------------------------------------------------------- ; @routine mLayoutPackCell ; @@ -234,50 +322,97 @@ mLayoutPackCell_ret: ; --------------------------------------------------------------------------- -; @routine mLayoutCopyTmpFromFirstLine +; @routine mLayoutCopyTmpFromFirstContiguous ; ; TMP in widgets of first row/column contains the available space per cell. ; ; @param Y pointer to widget ; @clobbers r17, r18, r19, r20, r21, r24 -mLayoutCopyTmpFromFirstLine: +mLayoutCopyTmpFromFirstContiguous: + ldd r24, Y+MLAYOUT_OFFS_COLSORROWS + cpi r24, 2 ; less than 2 in contiguous direction, nothing to copy + brcs mLayoutCopyTmpFromFirstContiguous_ret push yl push yh - ldd r24, Y+MLAYOUT_OFFS_COLSORROWS bigcall OBJ_GetFirstChild -mLayoutCopyTmpFromFirstLine_loop: +mLayoutCopyTmpFromFirstContiguous_loop: push yl push yh ldd r20, Y+WIDGET_OFFS_TMP_LO ldd r21, Y+WIDGET_OFFS_TMP_HI ; goto same cell in next block (e.g. same column in next row) ldd r17, Y+MLAYOUT_OFFS_COLSORROWS -mLayoutCopyTmpFromFirstLine_loop2: +mLayoutCopyTmpFromFirstContiguous_loop2: bigcall OBJ_GetNext - brcc mLayoutCopyTmpFromFirstLine_nextColumn + brcc mLayoutCopyTmpFromFirstContiguous_nextColumn mov yl, r18 mov yh, r19 dec r17 - brne mLayoutCopyTmpFromFirstLine_loop2 + brne mLayoutCopyTmpFromFirstContiguous_loop2 std Y+WIDGET_OFFS_TMP_LO, r20 std Y+WIDGET_OFFS_TMP_HI, r21 -mLayoutCopyTmpFromFirstLine_nextColumn: +mLayoutCopyTmpFromFirstContiguous_nextColumn: pop yh pop yl bigcall OBJ_GetNext - brcc mLayoutCopyTmpFromFirstLine_done + brcc mLayoutCopyTmpFromFirstContiguous_done mov yl, r18 mov yh, r19 - rjmp mLayoutCopyTmpFromFirstLine_loop -mLayoutCopyTmpFromFirstLine_done: + rjmp mLayoutCopyTmpFromFirstContiguous_loop +mLayoutCopyTmpFromFirstContiguous_done: pop yh pop yl +mLayoutCopyTmpFromFirstContiguous_ret: ret ; @end +; --------------------------------------------------------------------------- +; @routine mLayoutCopyTmpFromFirstSkipped +; +; TMP in widgets of first row/column contains the available space per cell. +; +; @param Y pointer to widget +; @clobbers r17, r18, r19, r20, r21, r24 + +mLayoutCopyTmpFromFirstSkipped: + ldd r24, Y+MLAYOUT_OFFS_COLSORROWS + cpi r24, 2 ; less than 2 in skipping direction, nothing to copy + brcs mLayoutCopyTmpFromFirstSkipped_ret + push yl + push yh + bigcall OBJ_GetFirstChild +mLayoutCopyTmpFromFirstSkipped_loop: + ldd r20, Y+WIDGET_OFFS_TMP_LO + ldd r21, Y+WIDGET_OFFS_TMP_HI + ldd r17, Y+MLAYOUT_OFFS_COLSORROWS +mLayoutCopyTmpFromFirstSkipped_loop2: + ; goto next cell in same block (e.g. next column in same row) + bigcall OBJ_GetNext + brcc mLayoutCopyTmpFromFirstSkipped_done + mov yl, r18 + mov yh, r19 + dec r17 + breq mLayoutCopyTmpFromFirstSkipped_loop2end + std Y+WIDGET_OFFS_TMP_LO, r20 + std Y+WIDGET_OFFS_TMP_HI, r21 + rjmp mLayoutCopyTmpFromFirstSkipped_loop2 +mLayoutCopyTmpFromFirstSkipped_loop2end: + rjmp mLayoutCopyTmpFromFirstSkipped_loop +mLayoutCopyTmpFromFirstSkipped_done: + pop yh + pop yl +mLayoutCopyTmpFromFirstSkipped_ret: + ret +; @end + + + + + + ; --------------------------------------------------------------------------- ; @routine mLayoutCopyTmpToWidth ; @@ -296,7 +431,7 @@ mLayoutCopyTmpToWidth_loop: std Y+WIDGET_OFFS_WIDTH_LO, r18 std Y+WIDGET_OFFS_WIDTH_HI, r19 mLayoutCopyTmpToWidth_next: - rcall OBJ_GetNext + bigcall OBJ_GetNext brcs mLayoutCopyTmpToWidth_loop mLayoutCopyTmpToWidth_ret: pop yh @@ -307,38 +442,99 @@ mLayoutCopyTmpToWidth_ret: ; --------------------------------------------------------------------------- -; @routine mLayoutCountChildrenWithMatchingPackMode +; @routine mLayoutCopyTmpToHeight ; ; @param Y pointer to widget -; @param r21:r20 width of first row +; +mLayoutCopyTmpToHeight: + push yl + push yh + bigcall OBJ_GetFirstChild + brcc mLayoutCopyTmpToHeight_ret +mLayoutCopyTmpToHeight_loop: + mov yl, r18 + mov yh, r19 + ldd r18, Y+WIDGET_OFFS_TMP_LO + ldd r19, Y+WIDGET_OFFS_TMP_HI + std Y+WIDGET_OFFS_HEIGHT_LO, r18 + std Y+WIDGET_OFFS_HEIGHT_HI, r19 +mLayoutCopyTmpToHeight_next: + bigcall OBJ_GetNext + brcs mLayoutCopyTmpToHeight_loop +mLayoutCopyTmpToHeight_ret: + pop yh + pop yl + ret +; @end -mLayoutColumnsExpandFirstRow: + + +; --------------------------------------------------------------------------- +; @routine mLayoutExpandFirstContiguous +; +; @param Y pointer to widget +; @param r19:r18 size of first line (width or height) +; @param r22 mask for WIDGET_OFFS_PACK +; @param r23 value for WIDGET_OFFS_PACK + +mLayoutExpandFirstContiguous: ldd r24, Y+MLAYOUT_OFFS_COLSORROWS ldi r25, 1 - ldi r22, (1<