One of the things I've always wanted to be able to do is auto-size/anchor Gadgets like Interface Builder allows one to do.
So I downloaded the latest Mac beta of PB last night, and started playing. Here's what I have:
Code: Select all
;
; ------------------------------------------------------------
;
; Live Gadget Auto Resizing Demo
;
; ------------------------------------------------------------
;
;
; Open a window, and try resizing it...
;
Enumeration
#Window
#Entry
#Button
#Editor
#Combo
EndEnumeration
Enumeration
#akNone
#akRight ; anchor to right side of Window, no resize
#akWidth ; resize width of Gadget, based on width of Window
#akLeft = 4 ; anchor to left side of Window, no resize
#akTop = 8 ; anchor to top of Window, no resize
#akHeight = 16 ; resize height of Gadget, based on height of Window
#akFull = #akWidth | #akHeight ; resize width/height of Gadget, based on width/height of Window
EndEnumeration
Procedure Anchor (handle, value)
Define tmp
Select GadgetType(handle)
Case #PB_GadgetType_Editor
; EDITOR GADGET IS COMPOSED OF NSTEXTVIEW->NSCLIPVIEW->NSSCROLLVIEW HIERARCHY
; So we have to traverse the hierarchy to get the actual NSScrollView object
tmp = CocoaMessage(0,CocoaMessage(0, GadgetID(handle),"superview"),"superview")
Default
tmp = GadgetID(handle)
EndSelect
CocoaMessage(0,tmp, "setAutoresizingMask:", value)
EndProcedure
If OpenWindow(#Window, 100, 200, 800, 600, "Live Gadget Auto Resizing Demo", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
; Set minimum window size
Define con.CGSize
con\width = 800
con\height = 622
CocoaMessage(0,WindowID(#Window), "setMinSize:@", @con)
Top = 16
GadgetHeight = 24
StringGadget(#Entry, 20, Top, 670, GadgetHeight, "Hello, World")
ButtonGadget(#Button, 710, Top-2, 70, GadgetHeight+4, "Click")
ComboBoxGadget(#Combo, 573, 50, 120, GadgetHeight)
AddGadgetItem(#Combo, -1, "Apples")
AddGadgetItem(#Combo, -1, "Oranges")
AddGadgetItem(#Combo, -1, "Peaches")
SetGadgetState(#Combo,1)
EditorGadget(#Editor, 20, 90,670, 480)
; Set up auto-resizing by specifying how Gadget is to be anchored in Window
Anchor(#Button,#akRight)
Anchor(#Entry,#akWidth)
Anchor(#Combo, #akRight)
Anchor(#Editor, #akFull)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_CloseWindow
Quit = 1
EndIf
Until Quit = 1
EndIf
End
I'd be interested in hearing what everyone thinks, and please excuse any sloppiness on my part.
AIR.