gui2: more code sharing.

This commit is contained in:
Martin Preuss
2026-04-13 10:56:07 +02:00
parent 0da8170df7
commit 7a58c4a8ad
2 changed files with 17 additions and 44 deletions

View File

@@ -437,7 +437,6 @@ layoutCtxSetPosWithExtra_loop: ; r19:r18=current pos, r22=spac
; @routine layoutCtxPack ; @routine layoutCtxPack
; ;
; @param X pointer to current item ; @param X pointer to current item
; @param Y current widget
; @param r21:r20 default size of the widget ; @param r21:r20 default size of the widget
; @return r19:r18 calculated pos ; @return r19:r18 calculated pos
; @return r21:r20 calculated size ; @return r21:r20 calculated size
@@ -451,77 +450,50 @@ layoutCtxPack:
ld r17, X+ ; size hi ld r17, X+ ; size hi
ld r25, X ; flags ld r25, X ; flags
sbiw xh:xl, LAYOUT_CTX_ITEM_OFFS_FLAGS sbiw xh:xl, LAYOUT_CTX_ITEM_OFFS_FLAGS
sub r16, r20 ; r17:r16=(size-defaultSize) rjmp layoutPack
sbc r17, r21
brcs layoutCtxPack_done
andi r25, 3
cpi r25, WIDGET_PACK_END
breq layoutCtxPack_end
cpi r25, WIDGET_PACK_CENTER
breq layoutCtxPack_center
cpi r25, WIDGET_PACK_FILLED
breq layoutCtxPack_filled
rjmp layoutCtxPack_done
layoutCtxPack_end:
add r18, r16 ; just add difference to pos
adc r19, r17
rjmp layoutCtxPack_done
layoutCtxPack_center:
lsr r17
ror r16
add r18, r16 ; just add half difference to pos
adc r19, r17
rjmp layoutCtxPack_done
layoutCtxPack_filled:
add r16, r20 ; get total size back
adc r17, r21
mov r20, r16
mov r21, r17
layoutCtxPack_done:
ret
; @end ; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine layout2Pack ; @routine layoutPack
; ;
; @param X pointer to current item
; @param Y current widget
; @param r17:r16 space available to the child widget ; @param r17:r16 space available to the child widget
; @param r21:r20 default size of the child widget ; @param r21:r20 default size of the child widget
; @param r19:r18 pos ; @param r19:r18 pos
; @param r25 pack flags ; @param r25 pack flags
; @return r19:r18 calculated pos
; @return r21:r20 calculated size
; @clobbers r16-r19, r25 ; @clobbers r16-r19, r25
layout2Pack: layoutPack:
sub r16, r20 ; r17:r16=(size-defaultSize) sub r16, r20 ; r17:r16=(size-defaultSize)
sbc r17, r21 sbc r17, r21
brcs layout2Pack_done brcs layoutPack_done
andi r25, 3 andi r25, 3
cpi r25, WIDGET_PACK_END cpi r25, WIDGET_PACK_END
breq layout2Pack_end breq layoutPack_end
cpi r25, WIDGET_PACK_CENTER cpi r25, WIDGET_PACK_CENTER
breq layout2Pack_center breq layoutPack_center
cpi r25, WIDGET_PACK_FILLED cpi r25, WIDGET_PACK_FILLED
breq layout2Pack_filled breq layoutPack_filled
rjmp layout2Pack_done rjmp layoutPack_done
layout2Pack_end: layoutPack_end:
add r18, r16 ; just add difference to pos add r18, r16 ; just add difference to pos
adc r19, r17 adc r19, r17
rjmp layout2Pack_done rjmp layoutPack_done
layout2Pack_center: layoutPack_center:
lsr r17 lsr r17
ror r16 ror r16
add r18, r16 ; just add half difference to pos add r18, r16 ; just add half difference to pos
adc r19, r17 adc r19, r17
rjmp layout2Pack_done rjmp layoutPack_done
layout2Pack_filled: layoutPack_filled:
add r16, r20 ; get total size back add r16, r20 ; get total size back
adc r17, r21 adc r17, r21
mov r20, r16 mov r20, r16
mov r21, r17 mov r21, r17
layout2Pack_done: layoutPack_done:
ret ret
; @end ; @end

View File

@@ -1476,6 +1476,7 @@ widgetCalcAbsPosAndBorders:
; @param R13:R12 size of object to pack (i.e. width or height) ; @param R13:R12 size of object to pack (i.e. width or height)
; @return R21:R20 pos ; @return R21:R20 pos
; @clobbers r17, r18, r19 ; @clobbers r17, r18, r19
; @todo move layoutPack here and use that (shares more code)
widgetPack: widgetPack:
; subtract borders ; subtract borders