Files
aqhomecontrol/avr/modules/lcd2/gui2/base/hlayout2.asm

314 lines
7.6 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_HLAYOUT2_ASM
#define AQH_AVR_GUI2_HLAYOUT2_ASM
; ***************************************************************************
; defines
.equ HLAYOUT2_OFFS_BEGIN = WIDGET_SIZE
.equ HLAYOUT2_OFFS_MODE = HLAYOUT2_OFFS_BEGIN+0
.equ HLAYOUT2_SIZE = HLAYOUT2_OFFS_BEGIN+1
; values for HLAYOUT_OFFS_MODE
.equ HLAYOUT2_MODE_EXPAND = 0
.equ HLAYOUT2_MODE_SPREAD = 1
; ***************************************************************************
; code
.cseg
; ---------------------------------------------------------------------------
; @routine HLayout_new @global
;
; @return CFLAG set of okay, cleared otherwise
; @return Y address of newly created object
; @param X parent widget
; @param r16 value for OBJECT_OFFS_OPTS
; @param r17 value for WIDGET_OFFS_PACK
; @param r20 layout mode (HLAYOUT_MODE_EXPAND, HLAYOUT_MODE_SPREAD)
; @clobbers any
HLayout2_new:
push r20
ldi r24, LOW(HLAYOUT2_SIZE)
ldi r25, HIGH(HLAYOUT2_SIZE)
bigcall Object_Alloc ; (!r16, !r17, !X)
pop r20
brcc HLayout2_new_ret
rcall HLayout2_Init ; (r16, r17, X)
sec
HLayout2_new_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine HLayout2_Init @global
;
; @param Y address of widget
; @param X parent widget (if any)
; @param r16 value for OBJECT_OFFS_OPTS
; @param r17 value for WIDGET_OFFS_PACK
; @param r20 layout mode (HLAYOUT_MODE_EXPAND, HLAYOUT_MODE_SPREAD)
; @clobbers r16, r17, X
HLayout2_Init:
push r20
; call base class
bigcall Widget_Init ; (r16, r17, X)
pop r20
; set widget-specific data
std Y+HLAYOUT2_OFFS_MODE, r20
; set default signal map
ldi r16, LOW(HLayout2_DefaultSignalmap*2)
std Y+OBJECT_OFFS_SIGNALMAP_LO, r16
ldi r16, HIGH(HLayout2_DefaultSignalmap*2)
std Y+OBJECT_OFFS_SIGNALMAP_HI, r16
ret
; @end
; ---------------------------------------------------------------------------
; @routine HLayout2_OnLayout
;
; @param Y pointer to widget
; @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
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)
cbr r16, (1<<WIDGET_FLAGS_LAYOUT_BIT)
std Y+OBJECT_OFFS_FLAGS, r16
HLayout2_OnLayout_ret:
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine HLayout2_OnGetDefaultHeight
;
; @param Y pointer to widget
; @return r19:r18 value
; @clobbers any, !Y
HLayout2_OnGetDefaultHeight:
; rcall Layout_SetDefaultHeights
; rcall Layout_GetMaxTmp
; bigcall Widget_AddOuterStyleBorders ; (r20, r21)
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine HLayout2_OnGetDefaultWidth
;
; @param Y pointer to widget
; @return r19:r18 value
; @clobbers any, !Y
HLayout2_OnGetDefaultWidth:
; rcall Layout_SetDefaultWidths
; rcall Layout_SumTmpValues ; r19:r18=default width
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2Vertically
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers any, !X, !Y
hLayout2Vertically:
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
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
push yh
bigcall LayoutCtx_ReadYDimsContiguous
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_SetFixedSize ; (r24)
push r25
bigcall LayoutCtxSetPos ; (r16-r25)
pop r25
; write back dims
push r25
push yl
push yh
bigcall LayoutCtx_WriteYDimsContiguous
pop yh
pop yl
pop r25
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2Horizontally
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers any, !Y
hLayout2Horizontally:
; setup layout context for horizontal operations
ldd r20, Y+WIDGET_OFFS_WIDTH_LO
ldd r21, Y+WIDGET_OFFS_WIDTH_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
ldd r24, Y+HLAYOUT2_OFFS_MODE
push yl
push yh
push r24
bigcall OBJ_GetFirstChild
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
pop yh
pop yl
pop r25
pop r24
; 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:
pop r25
; write back dims
push r25
push yl
push yh
bigcall LayoutCtx_WriteXDimsContiguous
pop yh
pop yl
pop r25
pop yh
pop yl
ret
; @end
; ***************************************************************************
; data in FLASH
HLayout2_DefaultSignalmap:
; header
.dw Widget_DefaultSignalmap*2 ; next table to use
; entries
.db 0, WIDGET_SIGNAL_LAYOUT, LOW(HLayout2_OnLayout), HIGH(HLayout2_OnLayout)
.db WIDGET_VALUE_DEFAULT_WIDTH, WIDGET_SIGNAL_GETVALUE, LOW(HLayout2_OnGetDefaultWidth), HIGH(HLayout2_OnGetDefaultWidth)
.db WIDGET_VALUE_DEFAULT_HEIGHT, WIDGET_SIGNAL_GETVALUE, LOW(HLayout2_OnGetDefaultHeight), HIGH(HLayout2_OnGetDefaultHeight)
.db 0, 0, 0, 0 ; end of table
#endif