mlayout: works for first row now (still WIP!)
This commit is contained in:
516
avr/modules/lcd2/gui2/base/mlayout_column.asm
Normal file
516
avr/modules/lcd2/gui2/base/mlayout_column.asm
Normal file
@@ -0,0 +1,516 @@
|
||||
; ***************************************************************************
|
||||
; copyright : (C) 2026 by Martin Preuss
|
||||
; email : martin@libchipcard.de
|
||||
;
|
||||
; ***************************************************************************
|
||||
; * This file is part of the project "AqHome". *
|
||||
; * Please see toplevel file COPYING of that project for license details. *
|
||||
; ***************************************************************************
|
||||
|
||||
#ifndef AQH_AVR_GUI2_MLAYOUT_COLUMN_ASM
|
||||
#define AQH_AVR_GUI2_MLAYOUT_COLUMN_ASM
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine MLayout_LayoutColumnMode @global
|
||||
;
|
||||
; @param Y widget
|
||||
; @clobbers any, !Y
|
||||
|
||||
MLayout_Layout_ColumnMode:
|
||||
rcall mLayoutColumnLayoutHorizontally
|
||||
; rcall mLayoutColumnLayoutVertically
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine MLayout_OnGetDefaultWidth_ColumnMode @global
|
||||
;
|
||||
; @param Y widget
|
||||
; @return r19:r18 value
|
||||
; @clobbers any, !Y
|
||||
|
||||
MLayout_OnGetDefaultWidth_ColumnMode:
|
||||
; DEBUG
|
||||
ldi r18, 10
|
||||
clr r19
|
||||
sec
|
||||
ret
|
||||
|
||||
rcall mLayoutSetDefaultWidthToTmp ; (any, !Y)
|
||||
rcall mLayoutGetBorders ; r22=spacing, r23=border
|
||||
push yl
|
||||
push yh
|
||||
rcall MLayout_GetFirstChildToY
|
||||
rcall mLayoutSumContiguous ; r21:r20 needed minimum row width (r18, r19, r25)
|
||||
pop yh
|
||||
pop yl
|
||||
mov r18, r20
|
||||
mov r19, r21
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine MLayout_OnGetDefaultHeight_ColumnMode @global
|
||||
;
|
||||
; @param Y widget
|
||||
; @return r19:r18 value
|
||||
; @clobbers any, !Y
|
||||
|
||||
MLayout_OnGetDefaultHeight_ColumnMode:
|
||||
; DEBUG
|
||||
ldi r18, 10
|
||||
clr r19
|
||||
sec
|
||||
ret
|
||||
|
||||
bigcall OBJ_GetFirstChild
|
||||
push yl
|
||||
push yh
|
||||
mov yl, r18
|
||||
mov yh, r19
|
||||
rcall mLayoutSetDefaultHeightToTmp ; (any, !Y)
|
||||
rcall mLayoutGetBorders ; r22=spacing, r23=border
|
||||
rcall mLayoutSumSkipped ; r21:r20 needed minimum row width (r18, r19, r25)
|
||||
mov r18, r20
|
||||
mov r19, r21
|
||||
pop yh
|
||||
pop yl
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnLayoutHorizontally
|
||||
;
|
||||
; @param Y widget
|
||||
; @clobbers any, !Y
|
||||
|
||||
mLayoutColumnLayoutHorizontally:
|
||||
rcall mLayoutGetBorders ; r22=spacing, r23=border
|
||||
ldd r25, Y+MLAYOUT_OFFS_COLSORROWS
|
||||
|
||||
push yl
|
||||
push yh
|
||||
rcall MLayout_GetFirstChildToY ; (none)
|
||||
push r22
|
||||
push r23
|
||||
push r25
|
||||
clr r25
|
||||
rcall mLayoutSetDefaultWidthToTmp ; (any, !Y)
|
||||
clr r25
|
||||
rcall mLayoutCopyTmpToWidth ; (r18, r19, Z)
|
||||
pop r25
|
||||
pop r23
|
||||
pop r22
|
||||
|
||||
; prepare first row
|
||||
rcall mLayoutSetupFirstContiguous ; set max column widths to first row (r18, r19, Z)
|
||||
|
||||
; possibly distribute free space to expandable columns
|
||||
push r22 ; spacing
|
||||
push r23 ; border
|
||||
; rcall mLayoutColumnExpandColumns ; (r16-r23, r25)
|
||||
pop r23
|
||||
pop r22
|
||||
|
||||
; rcall mLayoutColumnCopyTmpFromFirstRow ; copy TMP of every column from first row to following (r18-r21, Z)
|
||||
push r25
|
||||
clr r25
|
||||
rcall mLayoutColumnPositionX ; (r12, r13, r16-r21, X)
|
||||
pop r25
|
||||
pop yl
|
||||
pop yh
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
mLayoutColumnLayoutVertically:
|
||||
rcall mLayoutGetBorders ; r22=spacing, r23=border
|
||||
ldd r25, Y+MLAYOUT_OFFS_COLSORROWS
|
||||
|
||||
push yl
|
||||
push yh
|
||||
rcall MLayout_GetFirstChildToY ; (none)
|
||||
push r22
|
||||
push r23
|
||||
push r25
|
||||
rcall mLayoutSetDefaultHeightToTmp ; (any, !Y)
|
||||
pop r25
|
||||
rcall mLayoutCopyTmpToHeight ; (r18, r19, Z)
|
||||
pop r23
|
||||
pop r22
|
||||
|
||||
; prepare first column
|
||||
rcall mLayoutSetupFirstSkipped ; set max column widths to first column (r18, r19, Z)
|
||||
|
||||
; possibly distribute free space to expandable columns
|
||||
push r22 ; spacing
|
||||
push r23 ; border
|
||||
; rcall mLayoutColumnExpandRows ; (r16-r23)
|
||||
pop r23
|
||||
pop r22
|
||||
|
||||
rcall mLayoutColumnCopyTmpFromFirstColumn ; copy TMP of every column from first row to following (r18-r21, Z)
|
||||
|
||||
rcall mLayoutColumnPositionY ; (r12, r13, r16-r21, X)
|
||||
|
||||
pop yl
|
||||
pop yh
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCopyTmpFromFirstRow
|
||||
;
|
||||
; @param Y widget
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r18-r21, Z
|
||||
|
||||
mLayoutColumnCopyTmpFromFirstRow:
|
||||
push yl
|
||||
push yh
|
||||
ldi zl, LOW(mLayoutCallbackColumnCopyRow)
|
||||
ldi zh, HIGH(mLayoutCallbackColumnCopyRow)
|
||||
rcall mLayoutForEveryObjectContiguous ; (r18-r21, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutCallbackColumnCopyRow
|
||||
;
|
||||
; @param Y widget
|
||||
; @clobbers r18, r19, r20, r21, r25
|
||||
|
||||
mLayoutCallbackColumnCopyRow:
|
||||
push zl
|
||||
push zh
|
||||
rcall mLayoutColumnCopyTmpAcrossColumn ; (r18, r19, r20, r21, Z)
|
||||
pop zh
|
||||
pop zl
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCopyTmpAcrossColumn
|
||||
;
|
||||
; @param Y widget
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r18, r19, r20, r21, Z
|
||||
|
||||
mLayoutColumnCopyTmpAcrossColumn:
|
||||
push yl
|
||||
push yh
|
||||
ldd r20, Y+WIDGET_OFFS_TMP_LO
|
||||
ldd r21, Y+WIDGET_OFFS_TMP_HI
|
||||
ldi zl, LOW(mLayoutCallbackSetTmp)
|
||||
ldi zh, HIGH(mLayoutCallbackSetTmp)
|
||||
rcall mLayoutForEveryObjectSkipped ; (r18, r19, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCopyTmpFromFirstColumn
|
||||
;
|
||||
; @param Y widget
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r18-r21, Z
|
||||
|
||||
mLayoutColumnCopyTmpFromFirstColumn:
|
||||
push yl
|
||||
push yh
|
||||
ldi zl, LOW(mLayoutCallbackColumnCopyColumn)
|
||||
ldi zh, HIGH(mLayoutCallbackColumnCopyColumn)
|
||||
rcall mLayoutForEveryObjectSkipped ; (r18-r21, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutCallbackColumnCopyColumn
|
||||
;
|
||||
; @param Y widget
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r18, r19, r20, r21
|
||||
|
||||
mLayoutCallbackColumnCopyColumn:
|
||||
push zl
|
||||
push zh
|
||||
rcall mLayoutColumnCopyTmpAcrossRow ; (r18, r19, r20, r21, Z)
|
||||
pop zh
|
||||
pop zl
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCopyTmpAcrossRow
|
||||
;
|
||||
; @param Y widget
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r18, r19, r20, r21, Z
|
||||
|
||||
mLayoutColumnCopyTmpAcrossRow:
|
||||
push yl
|
||||
push yh
|
||||
ldd r20, Y+WIDGET_OFFS_TMP_LO
|
||||
ldd r21, Y+WIDGET_OFFS_TMP_HI
|
||||
ldi zl, LOW(mLayoutCallbackSetTmp)
|
||||
ldi zh, HIGH(mLayoutCallbackSetTmp)
|
||||
rcall mLayoutForEveryObjectContiguous ; (r18, r19, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnPositionX
|
||||
;
|
||||
; Set X and width to all columns of the row
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @param r22 spacing between widgets
|
||||
; @param r23 border at beginning and and
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r12, r13, r16-r21, X
|
||||
|
||||
mLayoutColumnPositionX:
|
||||
mov xl, r23 ; start at border
|
||||
clr xh
|
||||
push yl
|
||||
push yh
|
||||
ldi zl, LOW(mLayoutCallbackPositionX)
|
||||
ldi zh, HIGH(mLayoutCallbackPositionX)
|
||||
rcall mLayoutForEveryObjectContiguous ; (r12, r13, r16-r21, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnPositionY
|
||||
;
|
||||
; Set X and width to all columns of the row
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @param r22 spacing between widgets
|
||||
; @param r23 border at beginning and end
|
||||
; @param R25 widgets per row/column
|
||||
; @clobbers r12, r13, r16-r21, X
|
||||
|
||||
mLayoutColumnPositionY:
|
||||
mov xl, r23 ; start at border
|
||||
clr xh
|
||||
push yl
|
||||
push yh
|
||||
ldi zl, LOW(mLayoutCallbackPositionY)
|
||||
ldi zh, HIGH(mLayoutCallbackPositionY)
|
||||
rcall mLayoutForEveryObjectSkipped ; (r12, r13, r16-r21, Y)
|
||||
pop yh
|
||||
pop yl
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnExpandColumns
|
||||
;
|
||||
; Calculate additional space per expandable widget in a row.
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @param R25 widgets per row/column
|
||||
; @return CFLAG set if there is additional space to distribute
|
||||
; @return r21:r20 space to add to every expandable widget
|
||||
; @clobbers r16-r23
|
||||
|
||||
mLayoutColumnExpandColumns:
|
||||
rcall mLayoutColumnCalcAddSpacePerColumn ; r21:r20=additional space (r16-r23)
|
||||
brcc mLayoutColumnExpandColumns_ret
|
||||
|
||||
ldi r22, (1<<WIDGET_PACK_HSELF1_BIT) | (1<<WIDGET_PACK_HSELF0_BIT) ; mask
|
||||
ldi r23, (WIDGET_PACK_FILLED<<WIDGET_PACK_HSELF0_BIT) ; value
|
||||
rcall mLayoutExpandChildrenMatchingPackContiguous ; (r18, r19)
|
||||
|
||||
mLayoutColumnExpandColumns_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCalcAddSpacePerColumn
|
||||
;
|
||||
; Calculate additional space per expandable widget in a row.
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @return CFLAG set if there is additional space to distribute
|
||||
; @return r21:r20 space to add to every expandable widget
|
||||
; @param r22 spacing between widgets
|
||||
; @param r23 border at beginning and and
|
||||
; @param r25 widgets per row/column
|
||||
; @clobbers r16-r23
|
||||
|
||||
mLayoutColumnCalcAddSpacePerColumn:
|
||||
rcall mLayoutSumContiguous ; r21:r20 needed minimum row width (r18, r19)
|
||||
ldd r18, Y+WIDGET_OFFS_WIDTH_LO
|
||||
ldd r19, Y+WIDGET_OFFS_WIDTH_HI
|
||||
sub r18, r20
|
||||
sbc r19, r21
|
||||
brcc mLayoutColumnCalcAddSpacePerElement_none
|
||||
breq mLayoutColumnCalcAddSpacePerElement_none
|
||||
; r19:r18=space to distribute
|
||||
push r18
|
||||
push r19
|
||||
ldi r22, (1<<WIDGET_PACK_HSELF1_BIT) | (1<<WIDGET_PACK_HSELF0_BIT) ; mask
|
||||
ldi r23, (WIDGET_PACK_FILLED<<WIDGET_PACK_HSELF0_BIT) ; value
|
||||
rcall mLayoutCountChildrenMatchingPackContiguous ; r20=num of matching children (r18, r19, r25)
|
||||
pop r19
|
||||
pop r18
|
||||
tst r20
|
||||
breq mLayoutColumnCalcAddSpacePerElement_none ; don't divide by zero!
|
||||
mov r22, r20
|
||||
clr r23
|
||||
mov r20, r18
|
||||
mov r21, r19
|
||||
push r25
|
||||
bigcall Utils_Divu16_16_16 ; r17:r16=space per expandable widget (r25)
|
||||
pop r25
|
||||
mov r20, r16
|
||||
mov r21, r17
|
||||
sec
|
||||
rjmp mLayoutColumnCalcAddSpacePerElement_ret
|
||||
mLayoutColumnCalcAddSpacePerElement_none:
|
||||
clr r20
|
||||
clr r21
|
||||
clc
|
||||
mLayoutColumnCalcAddSpacePerElement_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnExpandRows
|
||||
;
|
||||
; Calculate additional space per expandable widget in a column.
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @param r25 widgets per row/column
|
||||
; @return CFLAG set if there is additional space to distribute
|
||||
; @return r21:r20 space to add to every expandable widget
|
||||
; @clobbers r16-r23
|
||||
|
||||
mLayoutColumnExpandRows:
|
||||
rcall mLayoutColumnCalcAddSpacePerRow ; r21:r20=additional space (r16-r23)
|
||||
brcc mLayoutColumnExpandRows_ret
|
||||
|
||||
ldi r22, (1<<WIDGET_PACK_VSELF1_BIT) | (1<<WIDGET_PACK_VSELF0_BIT) ; mask
|
||||
ldi r23, (WIDGET_PACK_FILLED<<WIDGET_PACK_VSELF0_BIT) ; value
|
||||
rcall mLayoutExpandChildrenMatchingPackSkipped ; (r18, r19)
|
||||
|
||||
mLayoutColumnExpandRows_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine mLayoutColumnCalcAddSpacePerRow
|
||||
;
|
||||
; Calculate additional space per expandable widget in a row.
|
||||
;
|
||||
; @param Y first widget of current row
|
||||
; @return CFLAG set if there is additional space to distribute
|
||||
; @return r21:r20 space to add to every expandable widget
|
||||
; @param r22 spacing between widgets
|
||||
; @param r23 border at beginning and and
|
||||
; @param r25 widgets per row/column
|
||||
; @clobbers r16-r23
|
||||
|
||||
mLayoutColumnCalcAddSpacePerRow:
|
||||
rcall mLayoutSumSkipped ; r21:r20 needed minimum row width (r18, r19)
|
||||
ldd r18, Y+WIDGET_OFFS_HEIGHT_LO
|
||||
ldd r19, Y+WIDGET_OFFS_HEIGHT_HI
|
||||
sub r18, r20
|
||||
sbc r19, r21
|
||||
brcc mLayoutColumnCalcAddSpacePerRow_none
|
||||
breq mLayoutColumnCalcAddSpacePerRow_none
|
||||
; r19:r18=space to distribute
|
||||
push r18
|
||||
push r19
|
||||
ldi r22, (1<<WIDGET_PACK_VSELF1_BIT) | (1<<WIDGET_PACK_VSELF0_BIT) ; mask
|
||||
ldi r23, (WIDGET_PACK_FILLED<<WIDGET_PACK_VSELF0_BIT) ; value
|
||||
rcall mLayoutCountChildrenMatchingPackSkipped ; r20=num of matching children (r18, r19)
|
||||
pop r19
|
||||
pop r18
|
||||
tst r20
|
||||
breq mLayoutColumnCalcAddSpacePerRow_none ; don't divide by zero!
|
||||
mov r22, r20
|
||||
clr r23
|
||||
mov r20, r18
|
||||
mov r21, r19
|
||||
push r25
|
||||
bigcall Utils_Divu16_16_16 ; r17:r16=space per expandable widget
|
||||
pop r25
|
||||
mov r20, r16
|
||||
mov r21, r17
|
||||
sec
|
||||
rjmp mLayoutColumnCalcAddSpacePerRow_ret
|
||||
mLayoutColumnCalcAddSpacePerRow_none:
|
||||
clr r20
|
||||
clr r21
|
||||
clc
|
||||
mLayoutColumnCalcAddSpacePerRow_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user