Files
aqhomecontrol/avr/modules/lcd2/gui2/base/hlayout2.asm
2026-04-12 01:31:23 +02:00

346 lines
8.2 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 and preset context
rcall LayoutCtx_CreateContextFor1D ; X=ctx, r16=num of children
brcc HLayout2_OnLayout_ret
; 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)
ldi r18, 10
clr r19
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
ldi r18, 10
clr r19
sec
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2Vertically
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @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)
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2ReadLayoutWriteVertical
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @clobbers r16-r24
hLayout2ReadLayoutWriteVertical:
; read positions and flags into new layout context
bigcall LayoutCtx_ReadYDimsContiguous ; (R16, r18, r19, Z)
; layout
bigcall LayoutCtx_GetMaxSize ; r19:r18=max default size (r18, r19, r20, r21, r24)
bigcall LayoutCtx_SetFixedSize ; (r24)
adiw xh:xl, LAYOUT_CTX_OFFS_BORDERS
ld r18, X
clr r19
sbiw xh:xl, LAYOUT_CTX_OFFS_BORDERS
bigcall LayoutCtx_SetFixedPos ; (r24)
; pack
bigcall LayoutCtx_PackYContiguous ; (R16, r18, r19, Z)
; write back dims
bigcall LayoutCtx_WriteYDimsContiguous ; (R16, r18, r19, Z)
ret
; @end
; ---------------------------------------------------------------------------
; @routine hLayout2Horizontally
;
; @param Y pointer to widget
; @param X layout context
; @param r25 number of children
; @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
adiw xh:xl, LAYOUT_CTX_OFFS_TOTALSIZE_LO
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
; read X positions and flags into new layout context
bigcall LayoutCtx_ReadXDimsContiguous ; (R16, r18, r19, Z)
; layout
push r25
cpi r24, HLAYOUT_MODE_SPREAD
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
bigcall LayoutCtx_PackXContiguous ; (r16-r21, r24, r25)
pop r25
; write back dims
bigcall LayoutCtx_WriteXDimsContiguous ; (r16, r18, r19, r24)
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