diff --git a/uxn-client/xrxs.tal b/uxn-client/xrxs.tal index bd2b274..801d44d 100644 --- a/uxn-client/xrxs.tal +++ b/uxn-client/xrxs.tal @@ -53,6 +53,9 @@ @select-index $1 @ncarts $1 @btn-state $1 +@sb-len $1 +@sb-pos $1 +@sb-step $1 @cart $32 @realm $32 @@ -548,49 +551,41 @@ RTN RTN -( this scrollbar breaks down with about 2x as many cartridges as the scren - has room for. A better method would be keeping track of the height, step, - and position ) - @draw-scrollbar ( -> ) .Screen/width DEI2 #0048 SUB2 .Screen/x DEO2 #0028 .Screen/y DEO2 - - &trough-only + ( draw the trough no matter what ) ;scrollbar-trough .Screen/addr DEO2 .list-height LDZ #00 - &while-trough-only EQUk ,&end-trough-only JCN + &while-trough EQUk ,&end-trough JCN #81 .Screen/sprite DEO INC-Y - INC ,&while-trough-only JMP &end-trough-only POP2 + INC ,&while-trough JMP &end-trough POP2 + ( stop here if there is no overflow ) .ncarts LDZ .list-height LDZ LTH ,&no-handle JCN - ,&start-loop JMP + ,&draw-handle JMP &no-handle RTN - &start-loop + ( if there are more carts than will fit in the view area, draw the handle ) + &draw-handle #0028 .Screen/y DEO2 - ( store the number of carts per tile of the scroll bar ) - .ncarts LDZ .list-height LDZ DIV STH - - .list-height LDZ #00 - &while EQUk ,&end JCN - ( trough top ) - DUP INC STHrk MUL .list-top LDZ GTH ,&handle JCN - INC - INC-Y - ,&while JMP - &handle - DUP INC INC STHrk .ncarts LDZ [ .list-top LDZ .list-height LDZ ADD ] SUB MUL ADD .list-height LDZ GTH ,&trough-bottom JCN - ;scrollbar .Screen/addr DEO2 - #81 .Screen/sprite DEO - &trough-bottom - INC-Y - INC ,&while JMP &end POP2 POPr + ( store the number of carts per tile of the scrollbar ) + .ncarts LDZ .list-height LDZ DIV .sb-step STZ + + ( set the length of the scrollbar ) + .list-height LDZ .ncarts LDZ .list-height LDZ SUB .sb-step LDZ DIV SUB .sb-len STZ + + ;scrollbar .Screen/addr DEO2 + #0028 .sb-pos LDZ #30 SFT TOS ADD2 .Screen/y DEO2 + .sb-len LDZ #00 &while-handle EQUk ,&end-handle JCN + .Screen/y DEI2 .Screen/height DEI2 #0028 SUB2 EQU2 ,&end-handle JCN + #81 .Screen/sprite DEO + INC INC-Y ,&while-handle JMP &end-handle POP2 RTN @@ -632,6 +627,7 @@ BRK .list-top LDZ #00 EQU ,&no-scroll-up JCN .list-top LDZ #01 SUB .list-top STZ &no-scroll-up + ;update-sb-pos JSR2 RTN @try-scroll-down-mouse ( -> ) @@ -639,6 +635,7 @@ RTN .list-top LDZ .list-height LDZ ADD .ncarts LDZ #01 ADD EQU ,&no-scroll-down JCN .list-top LDZ INC .list-top STZ &no-scroll-down + ;update-sb-pos JSR2 RTN @@ -648,6 +645,7 @@ RTN .list-top LDZ #00 EQU ,&no-scroll-up JCN .list-top LDZ #01 SUB .list-top STZ &no-scroll-up + ;update-sb-pos JSR2 RTN @try-scroll-down ( -> ) @@ -656,6 +654,13 @@ RTN .list-top LDZ .list-height LDZ ADD .ncarts LDZ #01 ADD EQU ,&no-scroll-down JCN .list-top LDZ INC .list-top STZ &no-scroll-down + ;update-sb-pos JSR2 +RTN + +@update-sb-pos ( -> ) + + .list-top LDZ .sb-step LDZ DIV .sb-pos STZ + RTN @get-select-idx-by-key ( -> )