textsel: use index instead of ressource id as value for the widget.

This commit is contained in:
Martin Preuss
2026-05-23 11:06:39 +02:00
parent 776ec7a363
commit a65e6fbec2

View File

@@ -21,13 +21,11 @@
; defines
.equ TEXTSEL_OFFS_BEGIN = HLAYOUT_SIZE
.equ TEXTSEL_OFFS_CURVALUE_LO = TEXTSEL_OFFS_BEGIN+0
.equ TEXTSEL_OFFS_CURVALUE_HI = TEXTSEL_OFFS_BEGIN+1
.equ TEXTSEL_OFFS_TEXTLIST_LO = TEXTSEL_OFFS_BEGIN+2
.equ TEXTSEL_OFFS_TEXTLIST_HI = TEXTSEL_OFFS_BEGIN+3
.equ TEXTSEL_OFFS_CURRIDX = TEXTSEL_OFFS_BEGIN+4
.equ TEXTSEL_OFFS_COUNT = TEXTSEL_OFFS_BEGIN+5
.equ TEXTSEL_SIZE = TEXTSEL_OFFS_BEGIN+6
.equ TEXTSEL_OFFS_TEXTLIST_LO = TEXTSEL_OFFS_BEGIN+0
.equ TEXTSEL_OFFS_TEXTLIST_HI = TEXTSEL_OFFS_BEGIN+1
.equ TEXTSEL_OFFS_CURRIDX = TEXTSEL_OFFS_BEGIN+2
.equ TEXTSEL_OFFS_COUNT = TEXTSEL_OFFS_BEGIN+3
.equ TEXTSEL_SIZE = TEXTSEL_OFFS_BEGIN+4
; selectors
@@ -122,25 +120,12 @@ TextSel_Init_ret:
textSelCreateChildren:
push yl
push yh
mov xl, yl ; parent
mov xh, yh
; create left button
call textSelCreateLeftButton
brcc textSelCreateChildren_popRet
; create label
ldi r16, 0 ; OPTS
ldi r17, (WIDGET_PACK_END<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) | \
(WIDGET_PACK_END<<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT) ; PACK
clr r20
clr r21
push xl
push xh
bigcall Label_new
pop xh
pop xl
rcall textSelCreateLabel
brcc textSelCreateChildren_popRet
; create right button
call textSelCreateRightButton
textSelCreateChildren_popRet:
@@ -151,15 +136,23 @@ textSelCreateChildren_popRet:
; ---------------------------------------------------------------------------
; @routine textSelCreateLeftButton
;
; @param Y object
; @clobbers any, !Y
textSelCreateLeftButton:
push xl
push xh
push yl
push yh
; create button
mov xl, yl
mov xh, yh
ldi r16, (1<<WIDGET_OPTS_BORDER_BIT) ; OPTS
ldi r17, (WIDGET_PACK_BEGIN<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) ; PACK
ldi r20, LOW(RESSOURCE_TXT_LESSERTHAN_C) ; text ressource
ldi r21, HIGH(RESSOURCE_TXT_LESSERTHAN_C)
ldi r22, TEXTSEL_SEL_LEFT ; selector
ldi r22, TEXTSEL_SEL_LEFT ; selector
ldi r23, BUTTON_MODE_REPEATED
bigcall TextButton_new
brcc textSelCreateLeftButton_done
@@ -174,17 +167,25 @@ textSelCreateLeftButton:
ldi r16, HIGH(TextSel_ButtonStyle*2)
std Y+WIDGET_OFFS_STYLE_HI, r16
textSelCreateLeftButton_done:
pop xh
pop xl
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine textSelCreateRightButton
;
; @param Y object
; @clobbers any, !Y
textSelCreateRightButton:
push xl
push xh
push yl
push yh
; create button
mov xl, yl
mov xh, yh
ldi r16, (1<<WIDGET_OPTS_BORDER_BIT) ; OPTS
ldi r17, (WIDGET_PACK_BEGIN<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) ; PACK
ldi r20, LOW(RESSOURCE_TXT_GREATERTHAN_C) ; text ressource
@@ -204,8 +205,35 @@ textSelCreateRightButton:
ldi r16, HIGH(TextSel_ButtonStyle*2)
std Y+WIDGET_OFFS_STYLE_HI, r16
textSelCreateRightButton_done:
pop xh
pop xl
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine textSelCreateLabel
;
; @param Y object
; @clobbers any, !Y
textSelCreateLabel:
push yl
push yh
; create label
clr r16 ; begin with first text ressource
rcall textSelGetRessIdAt
mov r20, xl
mov r21, xh
ldi r16, 0 ; OPTS
ldi r17, (WIDGET_PACK_END<<WIDGET_PACK_HSELF0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VSELF0_BIT) | \
(WIDGET_PACK_END<<WIDGET_PACK_HCONTENT0_BIT) | (WIDGET_PACK_CENTER<<WIDGET_PACK_VCONTENT0_BIT) ; PACK
mov xl, yl
mov xh, yh
bigcall Label_new
pop yh
pop yl
ret
; @end
@@ -216,32 +244,49 @@ textSelCreateRightButton_done:
; @routine textSelSetValue
;
; @param Y widget
; @param X new value
; @param r16 new value
; @clobbers any, !Y
textSelSetValue:
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
rjmp textSelSendValue
ldd r17, Y+TEXTSEL_OFFS_COUNT
cp r16, r17
brcc textSelSetValue_ret
ldd r17, Y+TEXTSEL_OFFS_CURRIDX
std Y+TEXTSEL_OFFS_CURRIDX, r16
push r17
rcall textSelSendValue
pop r17
; only emit signal if changed
ldd r16, Y+TEXTSEL_OFFS_CURRIDX
cp r16, r17
breq textSelSetValue_ret
rcall textSelEmitCmdSignal
textSelSetValue_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine textSelSendValue
;
; @param Y widget
; @clobbers any, !Y
textSelSendValue:
ldi r16, TEXTSEL_CHILDIDX_VALUE
bigcall OBJ_GetChildAt ; r19:r18=value label (r16)
brcc textSelSendValue_ret
push yl
push yh
ldd xl, Y+TEXTSEL_OFFS_CURVALUE_LO
ldd xh, Y+TEXTSEL_OFFS_CURVALUE_HI
ldd r16, Y+TEXTSEL_OFFS_CURRIDX
rcall textSelGetRessIdAt ; X=ressource id (R16, R17)
mov yl, r18
mov yh, r19
ldi r17, LABEL_VALUE_TEXTRES
bigcall Widget_SetValue ; (any, !Y)
bigcall Widget_SetValue ; (any, !Y)
pop yh
pop yl
rcall textSelEmitCmdSignal
textSelSendValue_ret:
ret
; @end
@@ -257,8 +302,8 @@ textSelSendValue_ret:
textSelEmitCmdSignal:
ldi r16, WIDGET_SIGNAL_COMMAND
ldd xl, Y+TEXTSEL_OFFS_CURVALUE_LO
ldd xh, Y+TEXTSEL_OFFS_CURVALUE_HI
ldd xl, Y+TEXTSEL_OFFS_CURRIDX
clr xh
bigjmp OBJ_EmitSignal
; @end
@@ -302,7 +347,7 @@ textCountRessources_done:
; @param Y widget
; @param r16 idx
; @return CFLAG set if ressource id found
; @return X ressource id (if CFLAG set)
; @return X ressource id (if CFLAG set, otherwise NULL)
; @clobbers r16, r17
textSelGetRessIdAt:
@@ -316,8 +361,7 @@ textSelGetRessIdAt:
ldd zh, Y+TEXTSEL_OFFS_TEXTLIST_HI
mov r17, zl
or r17, zh
clc
breq textSelGetRessIdAt_done
breq textSelGetRessIdAt_notFound
add zl, r16
adc zh, r16
sub zh, r16
@@ -325,9 +369,13 @@ textSelGetRessIdAt:
lpm xh, Z
mov r17, xl
or r17, xh
clc
breq textSelGetRessIdAt_done
breq textSelGetRessIdAt_notFound
sec
rjmp textSelGetRessIdAt_done
textSelGetRessIdAt_notFound:
clr xl
clr xh
clc
textSelGetRessIdAt_done:
pop zh
pop zl
@@ -336,47 +384,6 @@ textSelGetRessIdAt_done:
; ---------------------------------------------------------------------------
; @routine textGetIdxForRessource
;
; @param Y widget
; @param X ressource id to look for
; @return CFLAG set if found, cleared otherwise
; @return r16 idx
textGetIdxForRessource:
push zl
push zh
ldd zl, Y+TEXTSEL_OFFS_TEXTLIST_LO
ldd zh, Y+TEXTSEL_OFFS_TEXTLIST_HI
mov r16, zl
or r16, zh
breq textGetIdxForRessource_done
clr r16
textGetIdxForRessource_loop:
lpm r18, Z+
lpm r19, Z+
mov r17, r18
or r17, r19
clc
breq textGetIdxForRessource_done
cp r18, xl
brne textGetIdxForRessource_next
cp r19, xh
brne textGetIdxForRessource_next
sec
rjmp textGetIdxForRessource_done
textGetIdxForRessource_next:
inc r16
rjmp textGetIdxForRessource_loop
textGetIdxForRessource_done:
pop zh
pop zl
ret
; @end
; ***************************************************************************
@@ -393,11 +400,6 @@ TextSel_OnCmdLeft:
tst r16
breq TextSel_OnCmdLeft_ret
dec r16
std Y+TEXTSEL_OFFS_CURRIDX, r16
rcall textSelGetRessIdAt ; X=ressource id (r16, r17)
brcc TextSel_OnCmdLeft_ret
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
rcall textSelSetValue
TextSel_OnCmdLeft_ret:
sec
@@ -413,15 +415,7 @@ TextSel_OnCmdLeft_ret:
TextSel_OnCmdRight:
ldd r16, Y+TEXTSEL_OFFS_CURRIDX
ldd r17, Y+TEXTSEL_OFFS_COUNT
inc r16
cp r16, r17
brcc TextSel_OnCmdRight_ret
std Y+TEXTSEL_OFFS_CURRIDX, r16
rcall textSelGetRessIdAt ; X=ressource id (r16, r17)
brcc TextSel_OnCmdRight_ret
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
rcall textSelSetValue
TextSel_OnCmdRight_ret:
sec
@@ -434,14 +428,13 @@ TextSel_OnCmdRight_ret:
; @routine TextSel_OnSetValue @global
;
; @param Y widget
; @param X new value (selected text ressource id)
; @param X new value
TextSel_OnSetValue:
rcall textGetIdxForRessource
brcc TextSel_OnSetValue_ret
std Y+TEXTSEL_OFFS_CURRIDX, r16
std Y+TEXTSEL_OFFS_CURVALUE_LO, xl
std Y+TEXTSEL_OFFS_CURVALUE_HI, xh
tst xh
brne TextSel_OnSetValue_ret
ldd r17, Y+TEXTSEL_OFFS_COUNT
mov r16, xl
rcall textSelSendValue
TextSel_OnSetValue_ret:
sec
@@ -457,8 +450,8 @@ TextSel_OnSetValue_ret:
; @return r19:r18 value
TextSel_OnGetValue:
ldd r18, Y+TEXTSEL_OFFS_CURVALUE_LO
ldd r19, Y+TEXTSEL_OFFS_CURVALUE_HI
ldd r18, Y+TEXTSEL_OFFS_CURRIDX
clr r19
sec
ret
; @end