ContainerGadget Attributes

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

ContainerGadget Attributes

Post 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
Tranquil
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post by Fluid Byte »

GadgetWidth() / GadgetHeight(0) ? :?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post by Tranquil »

This seems not to return the real inner width and height. I get in conflicts with a drawn border.
Tranquil
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Fluid Byte
Addict
Addict
Posts: 2336
Joined: Fri Jul 21, 2006 4:41 am
Location: Berlin, Germany

Post 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?
Windows 10 Pro, 64-Bit / Whose Hoff is it anyway?
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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... ^^
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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!
Tranquil
Justin
Addict
Addict
Posts: 948
Joined: Sat Apr 26, 2003 2:49 pm

Re: ContainerGadget Attributes

Post 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.
Post Reply