PB5 : Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

PB5 : Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

For PB5.0+
- auto resize gadgets
- UseWindowLayout / UseGadgetLayout (layout management)
- resize priority parameter
- layout with margins & paddings
- DockGadget (docking modes: left, right, top, bottom, fill)
- AnchorGadget
- cross-platform (ios/win/linux)

For PB4.3 you can find the old version here :http://www.purebasic.fr/english/viewtop ... 12&t=34464

GadgetLayout.pbi

Code: Select all

;-TOP
; Comment : Gadget Layout
; Author  : eddy
; Web     : http://www.purebasic.fr/english/viewtopic.php?f=12&t=53113
; 
; File:   : GadgetLayout.pbi
; Version : v1.01
EnableExplicit
Enumeration 
   #Layout_IsParentWindow=0
   #Layout_IsParentGadget
   #Layout_IsAnchor   
   #Dock_None
   #Dock_Left
   #Dock_Right
   #Dock_Top
   #Dock_Bottom
   #Dock_Fill
EndEnumeration

Structure GADGET_LAYOUT
   ;child gadget layouts
   List Layouts.GADGET_LAYOUT()
   
   ;parent window or parent gadget or child gadget
   Object.i
   ;item layout identifier (only for panel gadget)
   ItemLayout.i
   
   ;layout mode
   LayoutMode.i
   
   ;auto-resize priority 
   AutoResizePriority.i
   
   ;child margins / parent paddings
   StructureUnion
      MarginLeft.i
      PaddingLeft.i
   EndStructureUnion   
   StructureUnion
      MarginTop.i
      PaddingTop.i
   EndStructureUnion   
   StructureUnion
      MarginRight.i
      PaddingRight.i
   EndStructureUnion   
   StructureUnion
      MarginBottom.i      
      PaddingBottom.i      
   EndStructureUnion   
   
   ;offset from centered anchor
   CenterOffsetX.i
   CenterOffsetY.i
EndStructure
Global NewList ParentLayouts.GADGET_LAYOUT()

Procedure.i SelectParentLayout(Parent.i, LayoutMode, ItemLayout=#PB_Ignore)
   With ParentLayouts()
      ForEach ParentLayouts()
         If \Object=Parent And \LayoutMode=LayoutMode
            If \LayoutMode=#Layout_IsParentWindow Or ItemLayout=#PB_Ignore Or \ItemLayout=ItemLayout
               ProcedureReturn ParentLayouts()
            EndIf 
         EndIf          
      Next
      ProcedureReturn #Null 
   EndWith
EndProcedure 

Procedure.i UseParentDefaultPriority(Parent.i, LayoutMode, Priority)
   If Priority<>#PB_Ignore               : ProcedureReturn Priority : EndIf       
   If LayoutMode=#Layout_IsParentWindow  : ProcedureReturn 100000   : EndIf 
   If LayoutMode=#Layout_IsParentGadget 
      Select GadgetType(Parent)
         Case #PB_GadgetType_ScrollArea,#PB_GadgetType_Container  : ProcedureReturn 10000 
         Case #PB_GadgetType_Panel                                : ProcedureReturn 1000
         Case #PB_GadgetType_Frame3D                              : ProcedureReturn 100
      EndSelect 
   EndIf 
EndProcedure

Procedure.i UseParentLayout(Parent.i, LayoutMode, PaddingLeft=#PB_Ignore, PaddingTop=#PB_Ignore, PaddingRight=#PB_Ignore, PaddingBottom=#PB_Ignore, ItemLayout=#PB_Ignore, Priority=#PB_Ignore)
   With ParentLayouts()      
      If Not SelectParentLayout(Parent, LayoutMode, ItemLayout)
         AddElement(ParentLayouts())
         Priority=UseParentDefaultPriority(Parent,LayoutMode,Priority)
      EndIf 
      
      \Object=Parent
      \LayoutMode=LayoutMode
      If PaddingLeft<>#PB_Ignore    : \PaddingLeft=PaddingLeft     : EndIf 
      If PaddingTop<>#PB_Ignore     : \PaddingTop=PaddingTop       : EndIf 
      If PaddingRight<>#PB_Ignore   : \PaddingRight=PaddingRight   : EndIf 
      If PaddingBottom<>#PB_Ignore  : \PaddingBottom=PaddingBottom : EndIf        
      If ItemLayout<>#PB_Ignore     : \ItemLayout=ItemLayout       : EndIf        
      If Priority<>#PB_Ignore      
         \AutoResizePriority=Priority   
         SortStructuredList(ParentLayouts(), #PB_Sort_Descending, OffsetOf(GADGET_LAYOUT\AutoResizePriority), #PB_Integer)
      EndIf 
      
      ProcedureReturn ParentLayouts()
   EndWith    
EndProcedure

Procedure.i UseWindowLayout(Window.i, PaddingLeft=#PB_Ignore, PaddingTop=#PB_Ignore, PaddingRight=#PB_Ignore, PaddingBottom=#PB_Ignore, Priority=#PB_Ignore)
   If IsWindow(Window)
      ProcedureReturn UseParentLayout(Window, #Layout_IsParentWindow, PaddingLeft, PaddingTop, PaddingRight, PaddingBottom, #PB_Ignore, Priority)
   EndIf   
EndProcedure

Procedure.i UseGadgetLayout(Gadget.i, PaddingLeft=#PB_Ignore, PaddingTop=#PB_Ignore, PaddingRight=#PB_Ignore, PaddingBottom=#PB_Ignore, Priority=#PB_Ignore)
   If IsGadget(Gadget)
      ProcedureReturn UseParentLayout(Gadget, #Layout_IsParentGadget, PaddingLeft, PaddingTop, PaddingRight, PaddingBottom, #PB_Ignore, Priority)
   EndIf   
EndProcedure

Procedure.i UseGadgetItemLayout(Gadget.i, ItemLayout.i, PaddingLeft=#PB_Ignore, PaddingTop=#PB_Ignore, PaddingRight=#PB_Ignore, PaddingBottom=#PB_Ignore, Priority=#PB_Ignore)
   If IsGadget(Gadget)         
      ProcedureReturn UseParentLayout(Gadget, #Layout_IsParentGadget, PaddingLeft, PaddingTop, PaddingRight, PaddingBottom, ItemLayout, Priority)
   EndIf
EndProcedure

Procedure DockGadget(Gadget, DockMode, MarginLeft=0, MarginTop=0, MarginRight=0, MarginBottom=0) 
   AddElement(ParentLayouts()\Layouts())
   With ParentLayouts()\Layouts()
      \Object=Gadget
      \LayoutMode=DockMode
      \MarginLeft=MarginLeft
      \MarginTop=MarginTop 
      \MarginRight=MarginRight
      \MarginBottom=MarginBottom 
   EndWith 
EndProcedure   

Procedure AnchorGadget(Gadget, MarginLeft=#PB_Ignore,MarginTop=#PB_Ignore, MarginRight=#PB_Ignore, MarginBottom=#PB_Ignore) 
   AddElement(ParentLayouts()\Layouts())
   With ParentLayouts()\Layouts()
      \Object=Gadget
      \LayoutMode=#Layout_IsAnchor
      \MarginLeft=MarginLeft
      \MarginTop=MarginTop 
      \MarginRight=MarginRight
      \MarginBottom=MarginBottom 
      
      If \MarginLeft=#PB_Ignore And \MarginRight=#PB_Ignore : \CenterOffsetX=GadgetX(Gadget) : EndIf 
      If \MarginTop=#PB_Ignore And \MarginBottom=#PB_Ignore : \CenterOffsetY=GadgetY(Gadget) : EndIf 
   EndWith    
EndProcedure 

Procedure AutoResizeGadgets()
   ForEach ParentLayouts()
      With ParentLayouts()
         ;calculate parent position and available space
         Protected x=0,y=0,w=0,h=0,px=0,py=0
         Select \LayoutMode
            Case #Layout_IsParentWindow
               If Not IsWindow(\Object)
                  ClearList(\Layouts())
                  DeleteElement(ParentLayouts())
                  Continue
               EndIf 
               
               w=WindowWidth(\Object)
               h=WindowHeight(\Object)
            Case #Layout_IsParentGadget
               If Not IsGadget(\Object)
                  ClearList(\Layouts())
                  DeleteElement(ParentLayouts())
                  Continue
               EndIf 
               
               Select GadgetType(\Object)
                  Case #PB_GadgetType_ScrollArea,#PB_GadgetType_Container
                     w=GadgetWidth(\Object)
                     h=GadgetHeight(\Object)
                  Case #PB_GadgetType_Panel
                     w=GetGadgetAttribute(\Object,#PB_Panel_ItemWidth)
                     h=GetGadgetAttribute(\Object,#PB_Panel_ItemHeight)
                  Default
                     px=GadgetX(\Object)
                     py=GadgetY(\Object)
                     w=GadgetWidth(\Object)
                     h=GadgetHeight(\Object)
               EndSelect
         EndSelect
         If w<=0 Or h<=0 : Continue : EndIf 
         x+\PaddingLeft
         y+\PaddingTop
         w-\PaddingRight-x
         h-\PaddingBottom-y         
      EndWith
      
      ForEach ParentLayouts()\Layouts()
         With ParentLayouts()\Layouts()
            
            If Not IsGadget(\Object)
               DeleteElement(ParentLayouts()\Layouts())
               Continue
            EndIf
            
            ;calculate gadget position and its needed space
            Protected totalW=\MarginLeft+GadgetWidth(\Object)+\MarginRight
            Protected totalH=\MarginTop+GadgetHeight(\Object)+\MarginBottom
            Protected gx=#PB_Ignore
            Protected gy=#PB_Ignore
            Protected gw=#PB_Ignore
            Protected gh=#PB_Ignore            
            Select \LayoutMode
               Case #Layout_IsAnchor
                  If \MarginLeft<>#PB_Ignore
                     gx=x+\MarginLeft
                     If \MarginRight<>#PB_Ignore
                        gw=w-\MarginRight-\MarginLeft
                     EndIf                      
                  ElseIf \MarginRight<>#PB_Ignore
                     gx=x+w-\MarginRight-GadgetWidth(\Object)
                  Else 
                     gx=x+(w-GadgetWidth(\Object))/2+\CenterOffsetX
                  EndIf 
                  If \MarginTop<>#PB_Ignore
                     gy=y+\MarginTop
                     If \MarginBottom<>#PB_Ignore
                        gh=h-\MarginBottom-\MarginTop
                     EndIf                      
                  ElseIf \MarginBottom<>#PB_Ignore
                     gy=y+h-\MarginBottom-GadgetHeight(\Object)
                  Else 
                     gy=y+(h-GadgetHeight(\Object))/2+\CenterOffsetY
                  EndIf 
                  
               Case #Dock_Left
                  gx=x+\MarginLeft
                  gy=y+\MarginTop
                  gh=h-\MarginBottom-\MarginTop
                  x+totalW
                  w-totalW
               Case #Dock_Right
                  gx=x+\MarginLeft+w-totalW
                  gy=y+\MarginTop
                  gh=h-\MarginBottom-\MarginTop
                  w-totalW
               Case #Dock_Top
                  gx=x+\MarginLeft
                  gy=y+\MarginTop
                  gw=w-\MarginRight-\MarginLeft
                  y+totalH
                  h-totalH
               Case #Dock_Bottom
                  gx=x+\MarginLeft
                  gy=y+\MarginTop+h-totalH
                  gw=w-\MarginRight-\MarginLeft
                  h-totalH                  
               Case #Dock_Fill
                  gx=x+\MarginLeft
                  gy=y+\MarginTop
                  gw=w-\MarginRight-\MarginLeft
                  gh=h-\MarginBottom-\MarginTop
            EndSelect
            If (gw<>#PB_Ignore And gw<0) : gw=0 : EndIf  
            If (gh<>#PB_Ignore And gh<0) : gh=0 : EndIf 
            ResizeGadget(\Object,px+gx,py+gy,gw,gh)
         EndWith
      Next       
   Next    
EndProcedure
Last edited by eddy on Fri Jul 26, 2013 1:13 pm, edited 17 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout

Post by eddy »

Here is a complete example.
- Click on buttons to delete them

Image

Code: Select all

; ********************
; EXAMPLE
; ********************

Enumeration 
   #MainWindow
   
   #Button1
   #Button2
   #Button3
   #Button4
   #Button5
   
   #Container
   #Frame
   #Anchor1
   #Anchor2
   #Anchor3
   #Anchor4   
   #Anchor5
   #Anchor6
   #Anchor7
   #Anchor8
EndEnumeration 

If OpenWindow(#MainWindow, 200, 200, 230, 220, "Docking by Eddy", #PB_Window_SizeGadget | #PB_Window_SystemMenu)
   WindowBounds(#MainWindow, 220, 170, 500, 500)
   SmartWindowRefresh(#MainWindow, 1)   
   
   UseWindowLayout(#MainWindow,2,2,2,2)      
   ButtonGadget(#Button1, 0, 0, 20, 20, "R")
   DockGadget(#Button1, #Dock_Right, 0, 0, 5, 0)
   
   ButtonGadget(#Button2, 0, 0, 20, 20, "T")
   DockGadget(#Button2, #Dock_top, 5, 5, 5, 5)
   
   ButtonGadget(#Button3, 0, 0, 20, 20, "B")
   DockGadget(#Button3, #Dock_Bottom, 5, 5, 5, 5)
   
   UseWindowLayout(#MainWindow)      
   ButtonGadget(#Button4, 0, 0, 20, 20, "L")
   DockGadget(#Button4, #Dock_Left, 0, 5, 0, 5)
   ButtonGadget(#Button5, 0, 0, 20, 20, "L")
   DockGadget(#Button5, #Dock_Left)   
   
   If ContainerGadget(#Container, 50, 50, 0, 0, #PB_Container_Single)
      SetGadgetColor(#Container, #PB_Gadget_BackColor, RGB(217, 214, 173))      
      DockGadget(#Container, #Dock_Fill)
      
      UseGadgetLayout(#Container)      
      Frame3DGadget(#Frame,0,0,100,100,"Frame")
      AnchorGadget(#Frame,  5, #PB_Ignore, 5, 5)
      
      ButtonGadget(#Anchor1, 0, 0, 20, 20, "1")
      AnchorGadget(#Anchor1,  #PB_Ignore, 10, 10)
      
      ButtonGadget(#Anchor2, 0, 0, 20, 20, "2")
      AnchorGadget(#Anchor2, #PB_Ignore, #PB_Ignore, 10, 10)
      
      ButtonGadget(#Anchor3, 0, 0, 20, 20, "3")
      AnchorGadget(#Anchor3, 10,10)
      
      ButtonGadget(#Anchor4, 5, -5, 20, 20, "4")
      AnchorGadget(#Anchor4, 10, #PB_Ignore, #PB_Ignore, 10)
      
      ButtonGadget(#Anchor5, 0, 0, 20, 20, "5")
      AnchorGadget(#Anchor5, #PB_Ignore, 10, #PB_Ignore, #PB_Ignore)
      
      ButtonGadget(#Anchor6, 0, 0, 20, 20, "6")
      AnchorGadget(#Anchor6, #PB_Ignore, #PB_Ignore, 10, #PB_Ignore)
      
      ButtonGadget(#Anchor7, 0, 0, 20, 20, "7")
      AnchorGadget(#Anchor7, #PB_Ignore, #PB_Ignore, #PB_Ignore,10)
      
      ButtonGadget(#Anchor8, 5, -5, 20, 20, "8")
      AnchorGadget(#Anchor8, 10, #PB_Ignore, #PB_Ignore, #PB_Ignore)
      
      CloseGadgetList()
   EndIf   
EndIf

Repeat
   Define e=WaitWindowEvent()
   If e=#PB_Event_SizeWindow
      AutoResizeGadgets()
   EndIf
   If e=#PB_Event_Gadget And GadgetType(EventGadget())=#PB_GadgetType_Button
      FreeGadget(EventGadget())
      AutoResizeGadgets()
   EndIf
Until e=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

- minor fix : layout of panelgadget item
- new function to manage layout of panel gadget items

Image

Code: Select all

; ********************
; EXAMPLE - TEXT EDITOR
; ********************

DisableExplicit
win=OpenWindow(#PB_Any, 0, 0, 500, 500, "Text Editor",
               #PB_Window_ScreenCentered|
               #PB_Window_SizeGadget|
               #PB_Window_SystemMenu)
SmartWindowRefresh(win,1)

toolbar=CreateToolBar(#PB_Any, WindowID(win))
If toolbar
   ToolBarStandardButton(0, #PB_ToolBarIcon_New)
   ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
   ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
EndIf

menu=CreateMenu(#PB_Any, WindowID(win))
If menu
   MenuTitle("&File")
   MenuItem( 1, "&Load...")
   MenuItem( 2, "&Save")
   MenuBar()
   MenuItem( 7, "&Quit")
EndIf

status=CreateStatusBar(#PB_Any, WindowID(win))
AddStatusBarField(70)
AddStatusBarField(70)
StatusBarText(status, 0, "Column")
StatusBarText(status, 1, "Row")

UseWindowLayout(win,2,2+ToolBarHeight(toolbar),2,2+MenuHeight()+StatusBarHeight(status))      
panel=PanelGadget(#PB_Any,0,0,200,100)
DockGadget(panel, #Dock_Right, 5)
AddGadgetItem(panel,-1,"Resources")
;> item layout custom identifier = 0
   UseGadgetItemLayout(panel,0, 5,5,5,5)
   listIcon=ListIconGadget(#PB_Any,0,0,0,0,"Packages",100)
   DockGadget(listIcon, #Dock_Fill)
;<
AddGadgetItem(panel,-1,"Projects")
;> item layout custom identifier = 1
   UseGadgetItemLayout(panel,1, 5,5,5,5)
   listIcon=ListIconGadget(#PB_Any,0,0,0,300,"Files",100)
   AnchorGadget(listIcon, 0,0,0,100)
   
   ip=IPAddressGadget(#PB_Any,0,0,100,20)
   DockGadget(ip, #Dock_Bottom)
   server=TextGadget(#PB_Any,0,0,100,14,"server address:")
   DockGadget(server, #Dock_Bottom)

;<
CloseGadgetList() 

UseWindowLayout(win)
version=TextGadget(#PB_Any,0,0,200,28,"version: 1.0.0"+#LF$+"memory usage: 100 Ko",#PB_Text_Right  )
AnchorGadget(version,#PB_Ignore,#PB_Ignore,0,0)

editor=EditorGadget(#PB_Any,0,0,0,0)
DockGadget(editor, #Dock_Fill,0,0,0,30)
SetGadgetText(editor,"Hello World")

Repeat
   Define e=WaitWindowEvent()
   If e=#PB_Event_SizeWindow
      AutoResizeGadgets()
   ElseIf e=#PB_Event_Gadget 
      ;your code here...
   EndIf    
Until e=#PB_Event_CloseWindow
Last edited by eddy on Sun Jan 27, 2013 1:05 am, edited 1 time in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 796
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by Zebuddi123 »

Thanks Eddy works great, win 7 64.

Zebuddi. :D
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

Zebuddi123 wrote:Thanks Eddy works great, win 7 64.

Zebuddi. :D
Thx.

Update
- new function to manage layout of PanelGadget items.
- text editor example updated
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by mk-soft »

Thanks. Very nice work :D
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

Here is the last example

Image

Code: Select all

; ********************
; EXAMPLE - MDI
; ********************

DisableExplicit
CompilerIf #PB_Compiler_OS <> #PB_OS_Windows
   MessageRequester("Info","MDI gadget is only supported by Windows OS")
   End 
CompilerEndIf   
win=OpenWindow(#PB_Any, 0, 0, 700, 600, "Multi-Windows", 
               #PB_Window_SystemMenu| 
               #PB_Window_SizeGadget|
               #PB_Window_ScreenCentered| 
               #PB_Window_MaximizeGadget)

menu=CreateMenu(#PB_Any, WindowID(win))
MenuTitle("&File")
MenuTitle("&Windows") ;<---- SubMenu 1
MenuItem(0, "&Arrange")
MenuItem(1, "Close &All")

UseWindowLayout(win,5,5,5,5+MenuHeight())

MDI=MDIGadget(#PB_Any, 0, 0, 100, 100, 1, 200) ;<--- first MenuID associated to MDI child windows
AnchorGadget(MDI,200,10,10,10)

winStats=AddGadgetItem(MDI, #PB_Any, "Stats")
ResizeWindow(winStats,0,0,350,350)
UseWindowLayout(winStats)
vprogress=ProgressBarGadget(#PB_Any,0,0,30,100,0,100,#PB_ProgressBar_Vertical)
SetGadgetState(vprogress,40)
DockGadget(vprogress,#Dock_Left,5,5,5,5)

winDataset=AddGadgetItem(MDI, #PB_Any, "Dataset")
ResizeWindow(winDataset,70,70,300,300)
UseWindowLayout(winDataset,10,10,10,10)
progress=ProgressBarGadget(#PB_Any,0,0,100,30,0,100)
SetGadgetState(progress,40)
DockGadget(progress,#Dock_Bottom)

Repeat
   Define e=WaitWindowEvent()
   If e=#PB_Event_SizeWindow
      AutoResizeGadgets()
   ElseIf e=#PB_Event_Gadget 
      ;your code here...
   EndIf    
Until e=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
said
Enthusiast
Enthusiast
Posts: 342
Joined: Thu Apr 14, 2011 6:07 pm

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by said »

Nice & compact, thanks for sharing :)
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

Update
- fix position if you use a non-container gadget (e.g.: Frame3DGadget)
- UseParentDefaultPriority : new function to manage default layout priority
- removed resize priority constants
- minor optimisation (I reduced number of lines )
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by mk-soft »

Bug in UseParentDefaultPriority on first example

Gadget not intialziert

P.S. Please use versions numbers
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

My bad :oops: ... copy/paste an old session version

[fixed] All examples work now.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by mk-soft »

No problem. Works now fine :wink: :D
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6253
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by mk-soft »

Please use this as header

Code: Select all

;-TOP
; Comment : Gadget Layout
; Author  : eddy
; Web     : http://www.purebasic.fr/english/viewtopic.php?f=12&t=53113
; 
; File:   : GadgetLayout.pbi
; Version : v1.03
Thanks
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by eddy »

Image

Code: Select all

; ********************
; EXAMPLE - FORM FIELDS
; ********************

DisableExplicit
win=OpenWindow(#PB_Any, 0, 0, 500, 500, "Form Helpers",
               #PB_Window_ScreenCentered|
               #PB_Window_SizeGadget|
               #PB_Window_SystemMenu)
SmartWindowRefresh(win,1)
WindowBounds(win,500,500,#PB_Ignore,#PB_Ignore)

UseWindowLayout(win)      

form=Frame3DGadget(#PB_Any,0,0,200,300,"Form")
AnchorGadget(form,20,10,20,#PB_Ignore)

meetings=Frame3DGadget(#PB_Any,0,0,200,150,"Meetings")
AnchorGadget(meetings,#PB_Ignore,#PB_Ignore,20,20)

archive=Frame3DGadget(#PB_Any,0,0,200,150,"Archive")
AnchorGadget(archive,20,#PB_Ignore,250,20)

;> use a frame3DGadget as container
   UseGadgetLayout(archive,10,20,10,10)   
   files=ExplorerTreeGadget(#PB_Any, 0, 0, 280, 100, "*.pb;*.pbi")
   DockGadget(files,#Dock_Top)
   progress=ProgressBarGadget(#PB_Any,0,0,0,0,0,100)
   DockGadget(progress,#Dock_Fill,0,5)
   SetGadgetState(progress,80)
;<

;> use a frame3DGadget as container
   UseGadgetLayout(meetings,10,20,10,10)
   dates=ListIconGadget(#PB_Any,0,0,0,0,"Dates",100)
   AddGadgetColumn(dates,1,"Status",70)
   DockGadget(dates, #Dock_Fill)
;<

;> use a frame3DGadget as container
   *formLayout.GADGET_LAYOUT=UseGadgetLayout(form,10,20,10,10)
   submit=ButtonGadget(#PB_Any,0,0,100,30,"Submit")
   AnchorGadget(submit,#PB_Ignore,#PB_Ignore,0,0)
   name=TextGadget(#PB_Any,0,0,0,14,"Name:")
   DockGadget(name, #Dock_top,0,5)
   namefield=StringGadget(#PB_Any,0,0,0,20,"DOE")
   DockGadget(namefield, #Dock_top)
   firstname=TextGadget(#PB_Any,0,0,0,14,"FirstName:")
   DockGadget(firstname, #Dock_top,0,5)
   fnamefield=StringGadget(#PB_Any,0,0,0,20,"JOHN")
   DockGadget(fnamefield, #Dock_top)
   gender=ContainerGadget(#PB_Any,0,0,0,80,#PB_Container_Single)
   SetGadgetColor(gender,#PB_Gadget_BackColor,RGB(229, 227, 199))
   CloseGadgetList()
   DockGadget(gender, #Dock_top,0,5)
;<

;> use a container
   OpenGadgetList(gender)
   UseGadgetLayout(gender,7,7,10,10,*formLayout\AutoResizePriority-1)
   gender1=OptionGadget(#PB_Any,0,0,60,20,"male")   
   AnchorGadget(gender1,0,0,#PB_Ignore,#PB_Ignore)
   gender2=OptionGadget(#PB_Any,0,0,60,20,"female")
   AnchorGadget(gender2,#PB_Ignore,0,0,#PB_Ignore)
   gender3=OptionGadget(#PB_Any,0,0,60,20,"alien")
   AnchorGadget(gender3,#PB_Ignore,0,#PB_Ignore,#PB_Ignore)
   
   gender4=OptionGadget(#PB_Any,0,0,60,20,"robot")   
   AnchorGadget(gender4,0,#PB_Ignore,#PB_Ignore,0)
   gender5=OptionGadget(#PB_Any,0,0,60,20,"zombie")
   AnchorGadget(gender5,#PB_Ignore,#PB_Ignore,0,0)
   gender6=OptionGadget(#PB_Any,0,0,60,20,"banana")
   AnchorGadget(gender6,#PB_Ignore,#PB_Ignore,#PB_Ignore,0)
   
   CloseGadgetList()
;<

Repeat
   Define e=WaitWindowEvent()
   If e=#PB_Event_ActivateWindow
      AutoResizeGadgets() ;<------------- resize at start
   ElseIf e=#PB_Event_SizeWindow
      AutoResizeGadgets()
   ElseIf e=#PB_Event_Gadget 
      ;your code here...
   EndIf    
Until e=#PB_Event_CloseWindow
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
flaith
Enthusiast
Enthusiast
Posts: 704
Joined: Mon Apr 25, 2005 9:28 pm
Location: $300:20 58 FC 60 - Rennes
Contact:

Re: Gadget+ Auto-Resize, Docking, Anchor, Layout, Margins

Post by flaith »

Great, thanks eddy :D
A little issue in the Text Editor example
When I resized it to the minimum and then to the max, the panel gadget has disappeared
“Fear is a reaction. Courage is a decision.” - WC
Post Reply