
da es ohne CanvasGadget besser ist habe ich es jetzt durch normale gelöst. war mal eine kleiner versuch ein eigenschaften gadget zu erstellen. es ist eine kostenlose etwas umfangreichere lösung zu der von srod(tBox)
es gibt
#PropertiesBox_String
#PropertiesBox_CheckBox
#PropertiesBox_ComboBox
#PropertiesBox_Spin
#PropertiesBox_Text
es werden immer gruppen erstellt.. wenn eine gruppe kein falten-button hat kann diese auch nicht zusammengeklappt werden.
jedes item verwendet ein normales gadget das auch die flags annehmen kann. auch das handling kann über die ganz normalen fuktionen gemacht werden. size ist relativ! (zb bei größeren schriftarten)
ToDo
- skrollt man ganz runter kann eine gruppe nicht geklappt werden.. außer man klickt oder skrollt wieder etwas hoch.
- noch minimal flimmriges klappen
- API invalidRect_ muss noch ersetzt werden
- resize des gadgets (momentan passt sich der inhalt nicht an)
Code: Alles auswählen
EnableExplicit
Define id.i
#PropertiesBox_Test=#True
Enumeration ; PropertiesBox types
#PropertiesBox_String
#PropertiesBox_CheckBox
#PropertiesBox_ComboBox
#PropertiesBox_Spin
#PropertiesBox_Text
EndEnumeration
Enumeration ; PropertiesBox flags
#PropertiesBox_Fold = %0001
EndEnumeration
Structure PropertiesBoxItem
id.i
head.i
back.i ; To avoid API to color the CheckBox background
h.i ; Height of item
EndStructure
Structure PropertiesBoxGroup
id.i
head.i
fold_visible.i
folder.i
fold.i
List item.PropertiesBoxItem()
EndStructure
Structure PropertiesBox
BackColor.i
List item.PropertiesBoxGroup()
EndStructure
CompilerIf #PropertiesBox_Test=#True
Global FontCourier = LoadFont(#PB_Any, "Arial", 12, #PB_Font_Bold)
Global FontItalic = LoadFont(#PB_Any, "Arial", 7, #PB_Font_Italic)
Global FontBold = LoadFont(#PB_Any, "Arial", 8, #PB_Font_Bold)
CompilerEndIf
UsePNGImageDecoder()
Global ImagePropertiesBoxFoldClose = CatchImage(#PB_Any, ?ProptertiesBoxFoldClose, 216)
Global ImagePropertiesBoxFoldOpen = CatchImage(#PB_Any, ?PropertiesBoxFoldOpen, 246)
Procedure.i EventPropertiesBox(GadgetID)
Protected *PBG.PropertiesBox = GetGadgetData(GadgetID), h.i=6, hy.i, y.i, id.i
With *PBG
ForEach \item()
If EventGadget()=\item()\folder And \item()\fold_visible=#True
If \item()\fold=#False
If \item()\fold_visible=#True:y=20:Else:y=2:EndIf
ResizeGadget(\item()\id, #PB_Ignore, GadgetY(\item()\id)-20, #PB_Ignore, y)
SetGadgetState(\item()\folder, ImageID(ImagePropertiesBoxFoldOpen))
\item()\fold=#True
h=0
ForEach \item()
ResizeGadget(\item()\id, #PB_Ignore, h, #PB_Ignore, #PB_Ignore)
h + GadgetHeight(\item()\id)
Next
SetGadgetAttribute(GadgetID, #PB_ScrollArea_InnerHeight, y+h)
Else
ForEach \item()\item()
h + \item()\item()\h
Next
ResizeGadget(\item()\id, #PB_Ignore, GadgetY(\item()\id)-20, #PB_Ignore, y+22+h)
SetGadgetState(\item()\folder, ImageID(ImagePropertiesBoxFoldClose))
\item()\fold=#False
h=0
ForEach \item()
ResizeGadget(\item()\id, #PB_Ignore, h, #PB_Ignore, #PB_Ignore)
h + GadgetHeight(\item()\id)
Next
SetGadgetAttribute(GadgetID, #PB_ScrollArea_InnerHeight, y+h)
EndIf
Break
EndIf
Next
EndWith
invalidateRect_(GadgetID(GadgetID),0,0)
EndProcedure
Procedure.i PropertiesBoxAddItem(GadgetID.i, group.i, type.i, title.s, value.s, min.i=0, max.i=0, flags.i=#Null, size.i=0)
Protected *PBG.PropertiesBox = GetGadgetData(GadgetID), h.i, y.i
OpenGadgetList(GadgetID)
With *PBG
SelectElement(\item(), group)
ForEach \item()\item()
h + \item()\item()\h + 2
Next
OpenGadgetList(\item()\id)
If \item()\fold_visible=#True:y=20:Else:y=2:EndIf
Select type
Case #PropertiesBox_String
AddElement(\item()\item())
\item()\item()\h = 15+size
\item()\item()\head = TextGadget(#PB_Any, 20, y+h, ((GadgetWidth(\item()\id)-15)/2)-2, \item()\item()\h, " "+title)
\item()\item()\id = StringGadget(#PB_Any, 20+(GadgetWidth(\item()\id)-15)/2, y+h, ((GadgetWidth(\item()\id)-15)/2)-6, \item()\item()\h, value, #PB_String_BorderLess+flags)
SetGadgetColor(\item()\item()\head, #PB_Gadget_BackColor, #White)
Case #PropertiesBox_Spin
AddElement(\item()\item())
\item()\item()\h = 20+size
\item()\item()\head = TextGadget(#PB_Any, 20, y+h, ((GadgetWidth(\item()\id)-15)/2)-2, \item()\item()\h, " "+title)
\item()\item()\id = SpinGadget(#PB_Any, 20+(GadgetWidth(\item()\id)-15)/2, y+h, ((GadgetWidth(\item()\id)-15)/2)-6, \item()\item()\h, min, max, #PB_String_BorderLess+flags)
SetGadgetColor(\item()\item()\head, #PB_Gadget_BackColor, #White)
Case #PropertiesBox_CheckBox
AddElement(\item()\item())
\item()\item()\h = 18+size
\item()\item()\head = TextGadget(#PB_Any, 20, y+h, ((GadgetWidth(\item()\id)-15)/2)-1, \item()\item()\h, " "+title)
\item()\item()\back = TextGadget(#PB_Any, 20+(GadgetWidth(\item()\id)-15)/2, y+h, ((GadgetWidth(\item()\id)-15)/2)-6, \item()\item()\h,"")
\item()\item()\id = CheckBoxGadget(#PB_Any, 2+20+(GadgetWidth(\item()\id)-15)/2, 2+y+h, 12, 12, "")
SetGadgetColor(\item()\item()\head, #PB_Gadget_BackColor, #White)
SetGadgetColor(\item()\item()\back, #PB_Gadget_BackColor, #White)
Case #PropertiesBox_ComboBox
AddElement(\item()\item())
\item()\item()\h = 20+size
\item()\item()\head = TextGadget(#PB_Any, 20, y+h, ((GadgetWidth(\item()\id)-15)/2)-2, \item()\item()\h, " "+title)
\item()\item()\id = ComboBoxGadget(#PB_Any, 20+(GadgetWidth(\item()\id)-15)/2, y+h, ((GadgetWidth(\item()\id)-15)/2)-8, \item()\item()\h, flags)
SetGadgetColor(\item()\item()\head, #PB_Gadget_BackColor, #White)
Case #PropertiesBox_Text
AddElement(\item()\item())
\item()\item()\h = 17+size
\item()\item()\head = TextGadget(#PB_Any, 20, y+h, (GadgetWidth(\item()\id)-15)-2, \item()\item()\h, title, flags)
SetGadgetColor(\item()\item()\head, #PB_Gadget_BackColor, GetGadgetColor(GadgetID, #PB_Gadget_BackColor))
EndSelect
ResizeGadget(\item()\id, #PB_Ignore, #PB_Ignore, #PB_Ignore, y+h+\item()\item()\h+2) ; Set new height of group
h=0
ForEach \item()
ResizeGadget(\item()\id, #PB_Ignore, h, #PB_Ignore, #PB_Ignore) ; Align groups
h + GadgetHeight(\item()\id)
Next
SetGadgetAttribute(GadgetID, #PB_ScrollArea_InnerHeight, y+24+h)
EndWith
ProcedureReturn *PBG\item()\item()\id
EndProcedure
Procedure.i PropertiesBoxAddGroup(GadgetID.i, title.s, flags.i=#Null)
Protected *PBG.PropertiesBox = GetGadgetData(GadgetID), h.i=0
ForEach *PBG\item()
h + GadgetHeight(*PBG\item()\id)
Next
OpenGadgetList(GadgetID)
With *PBG
AddElement(\item())
If flags&#PropertiesBox_Fold:\item()\fold_visible=#True:Else:\item()\fold_visible=#False:EndIf
\item()\id = ContainerGadget(#PB_Any, 0, h, GetGadgetAttribute(GadgetID, #PB_ScrollArea_InnerWidth), 20, #PB_Container_BorderLess)
If flags&#PropertiesBox_Fold
\item()\head = TextGadget(#PB_Any, 20, 2, GadgetWidth(\item()\id)-20, 18, title)
\item()\folder = ImageGadget(#PB_Any, 4, 4, 20, 20, ImageID(ImagePropertiesBoxFoldClose))
EndIf
; SetGadgetColor(\item()\id, #PB_Gadget_BackColor, GetSysColor_(#COLOR_3DLIGHT))
; SetGadgetColor(\item()\head, #PB_Gadget_BackColor, GetSysColor_(#COLOR_3DLIGHT))
SetGadgetColor(\item()\head, #PB_Gadget_FrontColor, RGB(Red(\BackColor)-80,Green(\BackColor)-80,Blue(\BackColor)-80))
SetGadgetColor(\item()\head, #PB_Gadget_BackColor, \BackColor)
SetGadgetColor(\item()\id, #PB_Gadget_BackColor, \BackColor)
CloseGadgetList()
EndWith
EndProcedure
Procedure.i PropertiesBoxGadget(GadgetID.i, x.i ,y.i, Width.i, Height.i, BackColor.i, flags.i=#Null)
Protected *PBG.PropertiesBox = AllocateMemory(SizeOf(PropertiesBox)), result.i
InitializeStructure(*PBG, PropertiesBox)
result = ScrollAreaGadget(GadgetID, x, y, Width, Height, Width-20, Height-20, 1, flags)
SetGadgetColor(GadgetID, #PB_Gadget_BackColor, #White)
CloseGadgetList()
SetGadgetData(GadgetID, *PBG)
*PBG\BackColor = BackColor
ProcedureReturn result
EndProcedure
Procedure.i PropertiesBoxItemID(GadgetID, group.i, item.i, field.i=0) ; 0 = title, 1 = value
Protected *PBG.PropertiesBox = GetGadgetData(GadgetID)
With *PBG
SelectElement(\item(), group)
SelectElement(\item()\item(), item)
If field=0
ProcedureReturn \item()\item()\head
ElseIf field=1
ProcedureReturn \item()\item()\id
EndIf
EndWith
EndProcedure
CompilerIf #PropertiesBox_Test=#True
Define x.i, id.i
OpenWindow(0, 0, 0, 250, 300, "PropertiesBoxGadget Example", #PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_Tool)
PropertiesBoxGadget(0, 10, 10, 230, 280, RGB($DF,$DF,$DF), #PB_ScrollArea_Flat)
PropertiesBoxAddGroup(0, "Settings", #PropertiesBox_Fold)
id = PropertiesBoxAddItem(0, 0, #PropertiesBox_String, "Position", "0,0,0")
SetGadgetFont(id, FontID(FontBold))
PropertiesBoxAddItem(0, 0, #PropertiesBox_String, "Rotation", "0,0,0")
id = PropertiesBoxAddItem(0, 0, #PropertiesBox_String, "Position", "0,0")
SetGadgetFont(id, FontID(FontItalic))
PropertiesBoxAddItem(0, 0, #PropertiesBox_ComboBox, "ID", "", 0, 0, #PB_ComboBox_Editable)
PropertiesBoxAddItem(0, 0, #PropertiesBox_ComboBox, "Type", "", 0, 0)
id = PropertiesBoxAddItem(0, 0, #PropertiesBox_Spin, "Spin", "", 0, 10, #PB_Spin_Numeric)
SetGadgetText(id, "2")
For x=0 To 10
AddGadgetItem(PropertiesBoxItemID(0, 0, 4, 1), -1, "item"+Str(x))
Next
SetGadgetState(PropertiesBoxItemID(0, 0, 4, 1), 0)
PropertiesBoxAddGroup(0, "Other")
PropertiesBoxAddItem(0, 1, #PropertiesBox_Text, "Text with additional 20px", "", 0, 0,0, 20)
PropertiesBoxAddItem(0, 1, #PropertiesBox_String, "Name", "test", 0, 0, #PB_Ignore, 20) ; Add 20px
SetGadgetFont(PropertiesBoxItemID(0, 1, 1, 0), FontID(FontCourier))
SetGadgetFont(PropertiesBoxItemID(0, 1, 1, 1), FontID(FontCourier))
SetGadgetColor(PropertiesBoxItemID(0, 1, 1, 1), #PB_Gadget_BackColor, RGB($F9,$CC,$CD))
PropertiesBoxAddItem(0, 1, #PropertiesBox_ComboBox, "Type", "", 0, 0)
PropertiesBoxAddItem(0, 1, #PropertiesBox_Text, "*maybe a comment", "", 0, 0,0, 20)
SetGadgetFont(PropertiesBoxItemID(0, 1, 3, 0), FontID(FontItalic))
SetGadgetColor(PropertiesBoxItemID(0, 1, 3, 0), #PB_Gadget_FrontColor, #Gray)
PropertiesBoxAddItem(0, 1, #PropertiesBox_ComboBox, "Type", "", 0, 0, #PB_ComboBox_Editable)
PropertiesBoxAddItem(0, 1, #PropertiesBox_String, "Passwort", "", 0, 0, #PB_String_Password)
PropertiesBoxAddItem(0, 1, #PropertiesBox_String, "Read only", "test", 0, 0, #PB_String_ReadOnly)
PropertiesBoxAddGroup(0, "Other", #PropertiesBox_Fold)
PropertiesBoxAddItem(0, 2, #PropertiesBox_CheckBox, "Enable", "")
PropertiesBoxAddItem(0, 2, #PropertiesBox_String, "Position", "0,0")
PropertiesBoxAddItem(0, 2, #PropertiesBox_ComboBox, "Type", "", 0, 0)
PropertiesBoxAddGroup(0, "Other", #PropertiesBox_Fold)
PropertiesBoxAddItem(0, 3, #PropertiesBox_String, "Position", "0,0")
PropertiesBoxAddItem(0, 3, #PropertiesBox_ComboBox, "Type", "", 0, 0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
Case #PB_Event_Gadget
EventPropertiesBox(0)
EndSelect
ForEver
CompilerEndIf
DataSection
PropertiesBoxFoldOpen:
Data.b $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$0A
Data.b $00,$00,$00,$0A,$08,$06,$00,$00,$00,$8D,$32,$CF,$BD,$00,$00,$00,$09,$70,$48,$59
Data.b $73,$00,$00,$0B,$12,$00,$00,$0B,$12,$01,$D2,$DD,$7E,$FC,$00,$00,$00,$A8,$49,$44
Data.b $41,$54,$18,$95,$5D,$D0,$3D,$6A,$02,$51,$14,$C5,$F1,$DF,$0C,$CF,$8F,$14,$56,$71
Data.b $0D,$56,$82,$A0,$4D,$76,$10,$C8,$36,$2C,$25,$1B,$B1,$1C,$6B,$F7,$91,$2C,$C2,$CE
Data.b $CA,$0D,$D8,$24,$95,$48,$12,$32,$CE,$A4,$C8,$1D,$7C,$7A,$E1,$F0,$E7,$9C,$73,$E1
Data.b $F2,$5E,$81,$37,$EC,$30,$F0,$3F,$5F,$C1,$87,$E0,$0F,$16,$B0,$B9,$2B,$5E,$43,$79
Data.b $B6,$29,$D1,$B8,$9D,$A7,$50,$3E,$4D,$42,$19,$E6,$12,$3C,$67,$0B,$5D,$56,$26,$D4
Data.b $98,$63,$8A,$0F,$4C,$A2,$7C,$C1,$18,$7B,$D4,$05,$D6,$18,$E2,$19,$9F,$D9,$E2,$01
Data.b $8F,$78,$C7,$37,$54,$51,$F4,$83,$DB,$50,$9E,$55,$25,$8A,$30,$29,$38,$70,$FD,$AA
Data.b $2E,$2B,$12,$DA,$30,$75,$F0,$98,$3D,$A6,$CB,$DA,$84,$19,$96,$18,$E1,$37,$BB,$B0
Data.b $42,$0F,$27,$CC,$FE,$00,$72,$E7,$1E,$F0,$F7,$E0,$58,$5C,$00,$00,$00,$00,$49,$45
Data.b $4E,$44,$AE,$42,$60,$82
PropertiesBoxFoldOpenend:
EndDataSection
DataSection
ProptertiesBoxFoldClose:
Data.b $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44,$52,$00,$00,$00,$0A
Data.b $00,$00,$00,$0A,$08,$06,$00,$00,$00,$8D,$32,$CF,$BD,$00,$00,$00,$09,$70,$48,$59
Data.b $73,$00,$00,$0B,$12,$00,$00,$0B,$12,$01,$D2,$DD,$7E,$FC,$00,$00,$00,$8A,$49,$44
Data.b $41,$54,$18,$95,$85,$D0,$C1,$09,$C2,$40,$14,$04,$D0,$97,$75,$21,$08,$1E,$AC,$C3
Data.b $4B,$40,$8B,$B0,$0D,$C1,$8E,$92,$66,$B4,$08,$AF,$D6,$E1,$41,$50,$71,$4D,$BC,$AC
Data.b $18,$63,$C4,$81,$39,$FC,$99,$0F,$33,$4C,$81,$1D,$0E,$28,$D1,$F9,$44,$81,$1B,$56
Data.b $D0,$64,$B1,$C4,$64,$C0,$32,$7B,$4D,$40,$EB,$3F,$DA,$88,$90,$8F,$47,$E6,$30,$1A
Data.b $42,$44,$C2,$12,$0B,$5C,$7A,$66,$87,$29,$8E,$48,$11,$77,$6C,$B0,$C6,$A9,$97,$D0
Data.b $62,$8E,$3D,$AE,$50,$67,$23,$8E,$74,$7B,$69,$75,$EC,$45,$FD,$7A,$4C,$28,$A2,$F7
Data.b $76,$29,$73,$0C,$5D,$44,$85,$2D,$66,$BE,$A7,$0A,$38,$A3,$7A,$02,$70,$B5,$1C,$75
Data.b $7D,$2B,$96,$44,$00,$00,$00,$00,$49,$45,$4E,$44,$AE,$42,$60,$82
ProptertiesBoxFoldCloseend:
EndDataSection