Page 1 of 1

ContainerGadget Attributes

Posted: Sat Dec 02, 2006 2:08 pm
by Tranquil
It would be nice, like the ScrollAreaGadget(), if the inner height and width could be get with these constants:

#PB_Container_InnerWidth
#PB_Container_InnerHeight

Posted: Sat Dec 02, 2006 4:39 pm
by Fluid Byte
GadgetWidth() / GadgetHeight(0) ? :?

Posted: Sat Dec 02, 2006 5:24 pm
by Tranquil
This seems not to return the real inner width and height. I get in conflicts with a drawn border.

Posted: Sat Dec 02, 2006 10:10 pm
by Fluid Byte
Tranquil wrote:This seems not to return the real inner width and height. I get in conflicts with a drawn border.
If I run this code I get exactly the width / height I specified. Regardless of the border style.

Code: Select all

OpenWindow(0,0,0,320,240,"untitled",#WS_OVERLAPPEDWINDOW | 1)

CreateGadgetList(WindowID(0))

ContainerGadget(0,5,5,100,100) : CloseGadgetList()
ContainerGadget(1,110,5,100,100,1) : CloseGadgetList()
ContainerGadget(2,5,110,100,100,2) : CloseGadgetList()
ContainerGadget(3,110,110,100,100,4) : CloseGadgetList()

For i=0 To 3
	Debug "Dimensions = " + Str(GadgetWidth(i)) + "," + Str(GadgetHeight(i))
Next

SetGadgetColor(0,#PB_Gadget_BackColor,#Red)

While WaitWindowEvent() ! 16 : Wend
I even copied the window content and checked the sizes in MS Paint.

All the same, so where's the problem?

Posted: Sat Dec 02, 2006 10:41 pm
by va!n
@Fluid Byte:
Your results are the gadgets including the border... tranquil need the innerwidth of the gadgets..

@Tranquil:
I wrote two small procedures that should solve your problem... I hope this is what you are looking for...

Code: Select all

OpenWindow(0,0,0,320,240,"untitled",#WS_OVERLAPPEDWINDOW | 1)

CreateGadgetList(WindowID(0))

ContainerGadget(0,5,5,100,100) : CloseGadgetList()
ContainerGadget(1,110,5,100,100,1) : CloseGadgetList()
ContainerGadget(2,5,110,100,100,2) : CloseGadgetList()
ContainerGadget(3,110,110,100,100,4) : CloseGadgetList()


Procedure GetGadgetInnerWidth(lGadget.l)
  lGadgetID.l = GadgetID(lGadget.l)
  If GetClientRect_(lGadgetID, @winRc.RECT)
    ProcedureReturn (winRc\right - winRc\left) - GetSystemMetrics_(#SM_CXBORDER ) +1
  EndIf  
EndProcedure

Procedure GetGadgetInnerHeight(lGadget.l)
  lGadgetID.l = GadgetID(lGadget.l)
  If GetClientRect_(lGadgetID, @winRc.RECT)
    ProcedureReturn (winRc\bottom - winRc\top) - GetSystemMetrics_(#SM_CYBORDER ) +1
  EndIf  
EndProcedure


For i=0 To 3
   Debug "Dimensions = " + Str(GetGadgetInnerWidth(i)) + "," + Str(GetGadgetInnerHeight(i))
Next

SetGadgetColor(0,#PB_Gadget_BackColor,#Red)

While WaitWindowEvent() ! 16 : Wend

Posted: Sat Dec 02, 2006 10:51 pm
by Fluid Byte
@Fluid Byte:
Your results are the gadgets including the border... tranquil need the innerwidth of the gadgets..
Perfectly normal, that's the way it should be. And if you need the size without the border what's so hard about subtracting 2, respectivley 4 pixels?

Posted: Sat Dec 02, 2006 10:56 pm
by va!n
just subtracting 2 or 4 pixel could return wrong results if you are using any special skins i.e... so why not using system commands to get always the correct results instead being to lazy and working with fixing values? I think the API is great, as long as people using this instead trying dirty tricks with fixed values. just my opinion

However, if you want use your methode... you have to check the type of the gadget... is is borderless, flat, double... ^^

Posted: Mon Dec 04, 2006 10:56 am
by Tranquil
va!n wrote:@Fluid Byte:
Your results are the gadgets including the border... tranquil need the innerwidth of the gadgets..

@Tranquil:
I wrote two small procedures that should solve your problem... I hope this is what you are looking for...

Code: Select all

OpenWindow(0,0,0,320,240,"untitled",#WS_OVERLAPPEDWINDOW | 1)

CreateGadgetList(WindowID(0))

ContainerGadget(0,5,5,100,100) : CloseGadgetList()
ContainerGadget(1,110,5,100,100,1) : CloseGadgetList()
ContainerGadget(2,5,110,100,100,2) : CloseGadgetList()
ContainerGadget(3,110,110,100,100,4) : CloseGadgetList()


Procedure GetGadgetInnerWidth(lGadget.l)
  lGadgetID.l = GadgetID(lGadget.l)
  If GetClientRect_(lGadgetID, @winRc.RECT)
    ProcedureReturn (winRc\right - winRc\left) - GetSystemMetrics_(#SM_CXBORDER ) +1
  EndIf  
EndProcedure

Procedure GetGadgetInnerHeight(lGadget.l)
  lGadgetID.l = GadgetID(lGadget.l)
  If GetClientRect_(lGadgetID, @winRc.RECT)
    ProcedureReturn (winRc\bottom - winRc\top) - GetSystemMetrics_(#SM_CYBORDER ) +1
  EndIf  
EndProcedure


For i=0 To 3
   Debug "Dimensions = " + Str(GetGadgetInnerWidth(i)) + "," + Str(GetGadgetInnerHeight(i))
Next

SetGadgetColor(0,#PB_Gadget_BackColor,#Red)

While WaitWindowEvent() ! 16 : Wend
This is exactly what I needed. Thanks va!n!

Re: ContainerGadget Attributes

Posted: Wed Jul 24, 2013 11:00 am
by Justin
Seven years and this is not implemented yet?
So it is imposible to position a gadget in a container with borders to match the width or height of the container? Crossplatform.
As in this example:

Code: Select all

If OpenWindow(0, 0, 0, 322, 150, "ContainerGadget", #PB_Window_SystemMenu | 
	#PB_Window_ScreenCentered)
    ContainerGadget(0, 8, 8, 306, 133, #PB_Container_Raised)
    	Debug GadgetWidth(0)
      ButtonGadget(1, 0, 0, GadgetWidth(0), 24, "Button 1")
    CloseGadgetList()
    Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
All the container border flags are useless if we can't retrieve the inner width/height.