Files
aqhomecontrol/avr/modules/lcd2/gui2/base/layout.asm
2026-03-09 02:08:33 +01:00

323 lines
7.8 KiB
NASM

; ***************************************************************************
; 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_LAYOUT_ASM
#define AQH_AVR_GUI2_LAYOUT_ASM
; ***************************************************************************
; defines
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine Layout_SetDefaultWidths
;
; Set default width in WIDGET_OFFS_TMP_LO/HI of child widgets
; Ignores invisible widgets.
;
; @param Y pointer to widget
; @clobbers any, !Y
Layout_SetDefaultWidths:
push yl
push yh
bigcall OBJ_GetFirstChild
brcc Layout_SetDefaultWidths_ret
Layout_SetDefaultWidths_loop:
mov yl, r18
mov yh, r19
ldd r18, Y+OBJECT_OFFS_FLAGS
sbrs r18, WIDGET_FLAGS_VISIBLE_BIT
rjmp Layout_SetDefaultWidths_next
bigcall Widget_GetDefaultWidth
std Y+WIDGET_OFFS_TMP_LO, r18
std Y+WIDGET_OFFS_TMP_HI, r19
Layout_SetDefaultWidths_next:
rcall OBJ_GetNext
brcs Layout_SetDefaultWidths_loop
Layout_SetDefaultWidths_ret:
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine Layout_SetDefaultHeights
;
; Set default height in WIDGET_OFFS_TMP_LO/HI of child widgets
; Ignores invisible widgets.
;
; @param Y pointer to widget
; @clobbers any, !Y
Layout_SetDefaultHeights:
push yl
push yh
bigcall OBJ_GetFirstChild
brcc Layout_SetDefaultHeights_ret
Layout_SetDefaultHeights_loop:
mov yl, r18
mov yh, r19
ldd r18, Y+OBJECT_OFFS_FLAGS
sbrs r18, WIDGET_FLAGS_VISIBLE_BIT
rjmp Layout_SetDefaultHeights_next
bigcall Widget_GetDefaultHeight
std Y+WIDGET_OFFS_TMP_LO, r18
std Y+WIDGET_OFFS_TMP_HI, r19
Layout_SetDefaultHeights_next:
rcall OBJ_GetNext
brcs Layout_SetDefaultHeights_loop
Layout_SetDefaultHeights_ret:
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine Layout_SumTmpValues
;
; Ignores invisible widgets.
;
; @param Y pointer to widget
; @return r19:r18 total width of all child widgets plus space between
; @clobbers r16, r17, r18, r19, r20, r21, r22, r23, Z
Layout_SumTmpValues:
ldd zl, Y+WIDGET_OFFS_STYLE_LO
ldd zh, Y+WIDGET_OFFS_STYLE_HI
; get spacing
adiw zh:zl, WIDGET_STYLE_OFFS_SPACING
lpm r22, Z
sbiw zh:zl, WIDGET_STYLE_OFFS_SPACING
; get outer border
adiw zh:zl, WIDGET_STYLE_OFFS_OUTERBORDERSIZE
lpm r23, Z
sbiw zh:zl, WIDGET_STYLE_OFFS_OUTERBORDERSIZE
; start adding
clr r20
clr r21
push yl
push yh
bigcall OBJ_GetFirstChild
brcc Layout_SumTmpValues_loopEnd
Layout_SumTmpValues_loop:
mov yl, r18
mov yh, r19
ldd r18, Y+OBJECT_OFFS_FLAGS
sbrs r18, WIDGET_FLAGS_VISIBLE_BIT
rjmp Layout_SumTmpValues_next
ldd r18, Y+WIDGET_OFFS_TMP_LO
ldd r19, Y+WIDGET_OFFS_TMP_HI
add r20, r18 ; add widget size
adc r21, r19
add r20, r22 ; add spacing
adc r21, r22
sub r21, r22
Layout_SumTmpValues_next:
rcall OBJ_GetNext
brcs Layout_SumTmpValues_loop
Layout_SumTmpValues_loopEnd:
mov r16, r20
or r16, r21
breq Layout_SumTmpValues_done
sub r20, r22 ; sub last spacing
sbc r21, r22
add r21, r22
add r20, r23 ; add outer border (begin)
adc r21, r23
sub r21, r23
add r20, r23 ; add outer border (end)
adc r21, r23
sub r21, r23
Layout_SumTmpValues_done:
mov r18, r20
mov r19, r21
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine Layout_GetMaxTmp
;
; Ignores invisible widgets.
;
; @param Y pointer to widget
; @return r19:r18 maximum value in WIDGET_OFFS_TMP_LO/HI of children
; @clobbers r20, r21
Layout_GetMaxTmp:
clr r20
clr r21
push yl
push yh
bigcall OBJ_GetFirstChild
Layout_GetMaxTmp_loop:
brcc Layout_GetMaxTmp_ret
mov yl, r18
mov yh, r19
ldd r18, Y+OBJECT_OFFS_FLAGS
sbrs r18, WIDGET_FLAGS_VISIBLE_BIT
rjmp Layout_GetMaxTmp_next
ldd r18, Y+WIDGET_OFFS_TMP_LO
ldd r19, Y+WIDGET_OFFS_TMP_HI
; max
cp r20, r18
cpc r21, r19
brcc Layout_GetMaxTmp_next
mov r20, r18
mov r21, r19
Layout_GetMaxTmp_next:
rcall OBJ_GetNext
rjmp Layout_GetMaxTmp_loop
Layout_GetMaxTmp_ret:
mov r18, r20
mov r19, r21
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine LayoutCountChildrenWithPackMode
;
; @param Y pointer to widget
; @param r22 mask for WIDGET_OFFS_PACK
; @param r23 value for WIDGET_OFFS_PACK
; @return r16 number of matching children
; @clobbers r17, r18, r19
LayoutCountChildrenWithPackMode:
clr r16
push yl
push yh
bigcall OBJ_GetFirstChild
LayoutCountChildrenWithPackMode_loop:
brcc LayoutCountChildrenWithPackMode_done
mov yl, r18
mov yh, r19
ldd r17, Y+OBJECT_OFFS_FLAGS
sbrs r17, WIDGET_FLAGS_VISIBLE_BIT ; skip invisible widgets
rjmp LayoutCountChildrenWithPackMode_next
ldd r17, Y+WIDGET_OFFS_PACK
eor r17, r23
and r17, r22
brne LayoutCountChildrenWithPackMode_next
inc r16
LayoutCountChildrenWithPackMode_next:
rcall OBJ_GetNext
rjmp LayoutCountChildrenWithPackMode_loop
LayoutCountChildrenWithPackMode_done:
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine LayoutCountVisibleChildren
;
; @param Y pointer to widget
; @return r16 number of matching children
; @clobbers r17, r18, r19
LayoutCountVisibleChildren:
clr r16
push yl
push yh
bigcall OBJ_GetFirstChild
LayoutCountVisibleChildren_loop:
brcc LayoutCountVisibleChildren_done
mov yl, r18
mov yh, r19
ldd r17, Y+OBJECT_OFFS_FLAGS
sbrc r17, WIDGET_FLAGS_VISIBLE_BIT ; skip invisible widgets
inc r16
LayoutCountVisibleChildren_next:
rcall OBJ_GetNext
rjmp LayoutCountVisibleChildren_loop
LayoutCountVisibleChildren_done:
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine LayoutIncTmpOnMatchingPack
;
; Ignores invisible widgets.
;
; @param Y pointer to widget
; @param R21:R20 value to add to tmp value of expandable widgets
; @param r22 mask for WIDGET_OFFS_PACK
; @param r23 value for WIDGET_OFFS_PACK
; @clobbers r16, r18, r19
LayoutIncTmpOnMatchingPack:
push yl
push yh
bigcall OBJ_GetFirstChild
brcc LayoutIncTmpOnMatchingPack_done
LayoutIncTmpOnMatchingPack_loop:
mov yl, r18
mov yh, r19
ldd r16, Y+OBJECT_OFFS_FLAGS
sbrs r16, WIDGET_FLAGS_VISIBLE_BIT ; skip invisible widgets
rjmp LayoutIncTmpOnMatchingPack_next
ldd r16, Y+WIDGET_OFFS_PACK
eor r16, r23
and r16, r22
brne LayoutIncTmpOnMatchingPack_next
ldd r18, Y+WIDGET_OFFS_TMP_LO
ldd r19, Y+WIDGET_OFFS_TMP_HI
add r18, r20
adc r19, r21
std Y+WIDGET_OFFS_TMP_LO, r18
std Y+WIDGET_OFFS_TMP_HI, r19
LayoutIncTmpOnMatchingPack_next:
rcall OBJ_GetNext
brcs LayoutIncTmpOnMatchingPack_loop
LayoutIncTmpOnMatchingPack_done:
pop yh
pop yl
ret
; @end
#endif