gui2: new layout modules basically work now.
This commit is contained in:
357
avr/modules/lcd2/gui2/base/vlayout2.asm
Normal file
357
avr/modules/lcd2/gui2/base/vlayout2.asm
Normal file
@@ -0,0 +1,357 @@
|
||||
; ***************************************************************************
|
||||
; 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_VLAYOUT2_ASM
|
||||
#define AQH_AVR_GUI2_VLAYOUT2_ASM
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ VLAYOUT2_OFFS_BEGIN = WIDGET_SIZE
|
||||
.equ VLAYOUT2_OFFS_MODE = VLAYOUT2_OFFS_BEGIN+0
|
||||
.equ VLAYOUT2_SIZE = VLAYOUT2_OFFS_BEGIN+1
|
||||
|
||||
|
||||
; values for VLAYOUT_OFFS_MODE
|
||||
.equ VLAYOUT2_MODE_EXPAND = 0
|
||||
.equ VLAYOUT2_MODE_SPREAD = 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine VLayout_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 (VLAYOUT_MODE_EXPAND, VLAYOUT_MODE_SPREAD)
|
||||
; @clobbers any
|
||||
|
||||
VLayout2_new:
|
||||
push r20
|
||||
ldi r24, LOW(VLAYOUT2_SIZE)
|
||||
ldi r25, HIGH(VLAYOUT2_SIZE)
|
||||
bigcall Object_Alloc ; (!r16, !r17, !X)
|
||||
pop r20
|
||||
brcc VLayout2_new_ret
|
||||
rcall VLayout2_Init ; (r16, r17, X)
|
||||
sec
|
||||
VLayout2_new_ret:
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine VLayout2_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 (VLAYOUT_MODE_EXPAND, VLAYOUT_MODE_SPREAD)
|
||||
; @clobbers r16, r17, X
|
||||
|
||||
VLayout2_Init:
|
||||
push r20
|
||||
; call base class
|
||||
bigcall Widget_Init ; (r16, r17, X)
|
||||
pop r20
|
||||
|
||||
; set widget-specific data
|
||||
std Y+VLAYOUT2_OFFS_MODE, r20
|
||||
|
||||
; set default signal map
|
||||
ldi r16, LOW(VLayout2_DefaultSignalmap*2)
|
||||
std Y+OBJECT_OFFS_SIGNALMAP_LO, r16
|
||||
ldi r16, HIGH(VLayout2_DefaultSignalmap*2)
|
||||
std Y+OBJECT_OFFS_SIGNALMAP_HI, r16
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine VLayout2_OnLayout
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @clobbers any, !Y
|
||||
|
||||
VLayout2_OnLayout:
|
||||
; create and preset context
|
||||
rcall LayoutCtx_CreateContextFor1D ; X=ctx, r16=num of children
|
||||
brcc VLayout2_OnLayout_ret
|
||||
; do layout
|
||||
mov r25, r16
|
||||
rcall vLayout2Horizontally
|
||||
rcall vLayout2Vertically
|
||||
|
||||
; 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
|
||||
VLayout2_OnLayout_ret:
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine VLayout2_OnGetDefaultHeight
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @return r19:r18 value
|
||||
; @clobbers any, !Y
|
||||
|
||||
VLayout2_OnGetDefaultHeight:
|
||||
rcall Layout2_SetDefaultHeights
|
||||
rcall Layout2_SumTmpValues ; r19:r18=default width
|
||||
sec
|
||||
ret
|
||||
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine VLayout2_OnGetDefaultWidth
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @return r19:r18 value
|
||||
; @clobbers any, !Y
|
||||
|
||||
VLayout2_OnGetDefaultWidth:
|
||||
rcall Layout2_SetDefaultWidths
|
||||
rcall Layout2_GetMaxTmp
|
||||
bigcall Widget_AddOuterStyleBorders ; (r20, r21)
|
||||
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine vLayout2Horizontally
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers any, !Y
|
||||
|
||||
vLayout2Horizontally:
|
||||
rcall vLayout2PrepareHorizontal ; (any, !R25, !X, !Y)
|
||||
rcall vLayout2ReadLayoutWriteHorizontal ; (r16-r24)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine vLayout2PrepareHorizontal
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers any, !R25, !X, !Y,
|
||||
|
||||
vLayout2PrepareHorizontal:
|
||||
push xl
|
||||
push xh
|
||||
push yl
|
||||
push yh
|
||||
push r25
|
||||
rcall Layout2_SetDefaultWidths
|
||||
pop r25
|
||||
pop yh
|
||||
pop yl
|
||||
pop xh
|
||||
pop xl
|
||||
|
||||
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 vLayout2ReadLayoutWriteHorizontal
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers r16-r24
|
||||
|
||||
vLayout2ReadLayoutWriteHorizontal:
|
||||
; read positions and flags into new layout context
|
||||
bigcall LayoutCtx_ReadXDimsContiguous ; (R16, r18, r19, Z)
|
||||
|
||||
; layout
|
||||
adiw xh:xl, LAYOUT_CTX_OFFS_BORDERS
|
||||
ld r18, X
|
||||
clr r19
|
||||
sbiw xh:xl, LAYOUT_CTX_OFFS_BORDERS
|
||||
bigcall LayoutCtx_SetFixedPos ; (r24)
|
||||
mov r22, r18 ; save border
|
||||
|
||||
bigcall LayoutCtx_GetMaxSize ; r19:r18=max default size (r18, r19, r20, r21, r24)
|
||||
ldd r16, Y+WIDGET_OFFS_PACK
|
||||
andi r16, (1<<WIDGET_PACK_HSELF1_BIT) | (1<<WIDGET_PACK_HSELF0_BIT)
|
||||
cpi r16, WIDGET_PACK_FILLED
|
||||
brne vLayout2ReadLayoutWriteHorizontal_setSize
|
||||
; use full possible width
|
||||
adiw xh:xl, LAYOUT_CTX_OFFS_TOTALSIZE_LO
|
||||
ld r18, X+
|
||||
ld r19, X
|
||||
sbiw xh:xl, (LAYOUT_CTX_OFFS_TOTALSIZE_LO+1)
|
||||
clr r23
|
||||
lsl r22
|
||||
rol r23
|
||||
sub r18, r22
|
||||
sbc r19, r23
|
||||
vLayout2ReadLayoutWriteHorizontal_setSize:
|
||||
bigcall LayoutCtx_SetFixedSize ; (r24)
|
||||
|
||||
; pack
|
||||
bigcall LayoutCtx_PackXContiguous ; (R16, r18, r19, Z)
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine vLayout2Vertically
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers any, !X, !Y
|
||||
|
||||
vLayout2Vertically:
|
||||
rcall vLayout2PrepareVertical ; (any, !R25, !X, !Y)
|
||||
rcall vLayout2ReadLayoutWriteVertical ; (r16-r24)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine vLayout2PrepareVertical
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers any, !R25, !X, !Y,
|
||||
|
||||
vLayout2PrepareVertical:
|
||||
push xl
|
||||
push xh
|
||||
push yl
|
||||
push yh
|
||||
push r25
|
||||
rcall Layout2_SetDefaultHeights ; (any, !Y)
|
||||
pop r25
|
||||
pop yh
|
||||
pop yl
|
||||
pop xh
|
||||
pop xl
|
||||
|
||||
; setup layout context for horizontal operations
|
||||
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 vLayout2ReadLayoutWriteVertical
|
||||
;
|
||||
; @param Y pointer to widget
|
||||
; @param X layout context
|
||||
; @param r25 number of children
|
||||
; @clobbers r16-r24
|
||||
|
||||
vLayout2ReadLayoutWriteVertical:
|
||||
; read X positions and flags into new layout context
|
||||
bigcall LayoutCtx_ReadYDimsContiguous ; (R16, r18, r19, Z)
|
||||
|
||||
; layout
|
||||
push r25
|
||||
ldd r24, Y+VLAYOUT2_OFFS_MODE
|
||||
cpi r24, VLAYOUT2_MODE_SPREAD
|
||||
breq vLayout2ReadLayoutWriteVertical_spread
|
||||
bigcall LayoutCtx_LayoutExpand ; (r16-r25)
|
||||
rjmp vLayout2ReadLayoutWriteVertical_pack
|
||||
vLayout2ReadLayoutWriteVertical_spread:
|
||||
bigcall LayoutCtx_LayoutSpread ; (r16-r25)
|
||||
vLayout2ReadLayoutWriteVertical_pack:
|
||||
pop r25
|
||||
|
||||
; pack
|
||||
push r25
|
||||
bigcall LayoutCtx_PackYContiguous ; (r16-r21, r24, r25)
|
||||
pop r25
|
||||
|
||||
; write back dims
|
||||
; bigcall LayoutCtx_WriteYDimsContiguous ; (r16, r18, r19, r24)
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data in FLASH
|
||||
|
||||
VLayout2_DefaultSignalmap:
|
||||
; header
|
||||
.dw Widget_DefaultSignalmap*2 ; next table to use
|
||||
; entries
|
||||
.db 0, WIDGET_SIGNAL_LAYOUT, LOW(VLayout2_OnLayout), HIGH(VLayout2_OnLayout)
|
||||
.db WIDGET_VALUE_DEFAULT_WIDTH, WIDGET_SIGNAL_GETVALUE, LOW(VLayout2_OnGetDefaultWidth), HIGH(VLayout2_OnGetDefaultWidth)
|
||||
.db WIDGET_VALUE_DEFAULT_HEIGHT, WIDGET_SIGNAL_GETVALUE, LOW(VLayout2_OnGetDefaultHeight), HIGH(VLayout2_OnGetDefaultHeight)
|
||||
|
||||
.db 0, 0, 0, 0 ; end of table
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user