Need Help with Function
#1
this function automatically sets the navigation for a set of buttons depending on how many buttons in columns/rows there are.

this is working fine in one of my scripts where i have several rows & columns.

in my new script i have only one row, with 11 buttons (horizontal)... and when i use the 'up' button, it moves the highlight to the left, and 'down' to the right... i want to make it opposite.

thanks in advance!

if someone can explain 'how' it works that would be great too!

Quote:        for n in range(btns):                                                   # loop to create button navigation
           nud = (n+1)%btns                                                    # (n+1)%totalnum  --- wraps navigation
           nei = n + buttonspercolumn
           if nei >= btns:
               nei = nei % buttonspercolumn
           self.btnevent[nud].controlup(self.btnevent[n])
           self.btnevent[n].controldown(self.btnevent[nud])                    
           self.btnevent[nei].controlleft(self.btnevent[n])
           self.btnevent[n].controlright(self.btnevent[nei])



I'm not an expert but I play one at work.
Reply
#2
you really have to keep this picture in your head when you are writing this code.

Quote:buttons were layed out top to bottom then left to right
xxxxx --
xxxxx |
xxxxx |
xxxxx | buttonspercolumn
cxxa |
xxxb |
xxxx --

# of x's = btns
a = btn[n] - current node in loop
b = btn[nud] - the node 'below a'
c = btn[nei] - the node 'to the right' of a

i think it would make more sense for scrolling off the bottom to go to the top of the same column than to go to the top of the next column. this would make up and down in a one row example do nothing though.

anyway that code would be:


Quote: for n in range(btns): # loop to create button navigation
# wraps navigation off the end if not a multiple of buttonspercolumn
nud = (n+1)%btns# (n+1)%totalnum
nud = nud%buttonspercolumn+(n/buttonspercolumn)*buttonspercolumn
# the first part above gives us the column position of c and the second adjusts it to n's column
# note this is integer division
nei = n + buttonspercolumn
if nei >= btns:
nei = nei % buttonspercolumn
self.btnevent[nud].controlup(self.btnevent[n])
self.btnevent[n].controldown(self.btnevent[nud])
self.btnevent[nei].controlleft(self.btnevent[n])
self.btnevent[n].controlright(self.btnevent[nei])



Reply
#3
you are correct... the original code works fine, except as i noted when you have multiple columns, each with a single row like so..

xxxabcxxx

left/right works fine
up when at b moves to a
down when at b moves to c

i hope that is clearer then my first post.
I'm not an expert but I play one at work.
Reply
#4
i understood. i think thats either acceptable behavior or up and down should do nothing in that case.
else you will need to special case the one row condition.... so
if numrow = 1 do this
else
do the loop



Reply

Logout Mark Read Team Forum Stats Members Help
Need Help with Function0