Centre gadgets on Window???

BlitzPlus Forums/BlitzPlus Programming/Centre gadgets on Window???

Pineapple(Posted 2004) [#1]
Hiya All,

Now i'm (sorta) up to speed on events, gadgets and what not, and I've created a window, got a menu (which works) hehehe, and got a program that actually does summit... The only problem is, is there a quicker way to centre gadgets on the window, maybe like handling the gadget from the middle, like you can do with images and text???

it'll be a real help if anyone knows a way, cos I hate adding values to parameters then testing it, then finding it doesnt look right.. etc etc

Cheers in advanced

:D


Pineapple(Posted 2004) [#2]
got it:

dabsWindow = CreateWindow("My App",348,240,310,350,0,13)

windowX = ClientWidth(dabsWindow)
txtGadgetLength = 200

gadgetItem=CreateTextField((windowX/2)-(txtGadgetLength/2),20,txtGadgetLength,20,dabsWindow)


hehehe

:)


Rottbott(Posted 2004) [#3]
This is a general purpose function to do that for any gadget, I use it all the time:

; Puts a gadget in the centre of its group
Function CentreGadget(G)
  CX = ClientWidth(GadgetGroup(G)) / 2 : CY = ClientHeight(GadgetGroup(G)) / 2
  SetGadgetShape G, CX - (GadgetWidth(G)/2), CY - (GadgetHeight(G)/2), GadgetWidth(G), GadgetHeight(G)
End Function