|
Post by zzz000abc on Jul 29, 2022 7:42:32 GMT
here is a function to calculate window button positions and button width function btwp$(al,n) el=0.8*al : m = int(al/2) :k=int(el/(6*n-1)) 'bl=5*k : gl=k k=k-(k mod 2<>0) bp=m-(k/2)*(6*n-1) l$=str$(bp) for i=2 to n bp=bp+(6*k) l$=l$+chr$(32)+str$(bp) next l$=l$+chr$(32)+str$(5*k) btwp$=l$ end function for example run the above function with the code given below
n=4 :l$=btwp$(300,n) print l$
here n is number of buttons and 300 is window width you get the out put: 35 95 155 215 50 last number is width of the button(bw) and first four numbers positions of the buttons from UL corner. now we calculate the button height. if the button width is multiple of 4 simply use the formula (bw/4)*3. if not take nearest multiple of 4 to button width and do same thing again. in our example button width is 50 so we take 52 or 48 and using the formula we button height equals to 39 or 36 with this we information we write code for a window with four buttons WindowWidth=300: WindowHeight=200 button #w1.bt1,"hello",[clk1],UL,35,100,50,39 button #w1.bt2,"hello",[clk1],UL,95,100,50,39 button #w1.bt3,"hello",[clk1],UL,155,100,50,39 button #w1.bt4,"hello",[clk1],UL,215,100,50,39 open"main" for window as #w1 #w1,"font 12" wait you can do experiment with changing window width and number of buttons. Note 1. I will be adding few more posts on this topic
|
|
|
Post by Rod on Jul 29, 2022 13:11:24 GMT
Would be really cool if it produced the code for you to. Just needs the window handle passed.
|
|
|
Post by tsh73 on Jul 29, 2022 20:43:05 GMT
I made it so on window resize it calls this function and draws rectangles according to description. Play with it. (things to think about * allow to change number of buttons, say 7 * allow to set precise window or client size width, say set to 500 )
'making GUI for 'a function to calculate window button positions and button width 'by zzz000abc nomainwin open "button placer" for graphics_nsb as #gr #gr "trapclose [quit]" #gr "down" '#gr "fill white; flush" #gr "home; posxy cx cy"
numButtons=4
gosub [redraw] #gr "flush"
timer 100, [tick]
wait
[tick] cx0=cx:cy0=cy #gr "home; posxy cx cy" if cx0=cx and cy0=cy then wait 'no thing happened gosub [redraw] wait
[quit] timer 0 close #gr end
[redraw] #gr "cls" h=25 'sensible default #gr "place ";h;" ";h #gr "\Window client size is ";2*cx;"x";2*cy l$=btwp$(2*cx,numButtons) #gr "\";l$ w=val(word$(l$, numButtons+1)) for i = 1 to numButtons x= val(word$(l$,i)) #gr "place ";x;" ";2*cy-2*h #gr "box ";x+w;" ";2*cy-h next #gr "flush" return
function btwp$(al,n) el=0.8*al : m = int(al/2) :k=int(el/(6*n-1)) 'bl=5*k : gl=k k=k-(k mod 2<>0) bp=m-(k/2)*(6*n-1) l$=str$(bp) for i=2 to n bp=bp+(6*k) l$=l$+chr$(32)+str$(bp) next l$=l$+chr$(32)+str$(5*k) btwp$=l$ end function
|
|