|
propertygrid
propertygrid.modThis module will make it possible to use a property grid in your maxgui application without hassle. The propertygrid is event-driven and integrates into the maxgui event system by the use of custom events. This is what it looks like:
TypesThe module consists of the following types:
EventsThe module registeres two custom events: EVENT_PG_GROUPTOGGLED : This event is raised when a group is opened or closed. TPropertyGrid uses this event to refresh the grid layout when needed. EVENT_PG_ITEMCHANGED : This event is raised by a TPropertyItem when enter is pressed in a field, a gadget has been interacted with or the cursor leaves a text field. Your application main event loop can use this event to signal property value changes. EventSource contains the property item, EventData contains the property item ID, and EventExtra contains the new value. The event source is returned as an object, so it must be cast to the correct type. How to usePut the module source in the module folder. The path should look like blitzmax\mod\wdw\propertygrid.mod\. Here is some example code to show how to set up a simple propertygrid: Import wdw.propertygrid
Local w:TGadget = CreateWindow("test", 50, 50, 600, 600, Null, WINDOW_TITLEBAR | WINDOW_RESIZABLE | WINDOW_CLIENTCOORDS)
Local g:TPropertyGrid = TPropertyGrid.GetInstance()
g.Initialize(w, 1)Now we can create a group and add items to it. Each group and item must have a unique ID for event handling: Local group1:TPropertyGroup = g.AddGroup("Group 1", 9001)
CreatePropertyItemBool("Bool", 1, 100, group1)
Local choice:TPropertyItemChoice = CreatePropertyItemChoice("Choice", 101, group1)
choice.AddItem("A")
choice.AddItem("B")
choice.AddItem("C")
CreatePropertyItemColor("Color", 255, 255, 0, 102, group1)The layout of the grid must be refreshed so we can see the groups and items: g.RefreshLayout() The application main event loop can now react to changes in the items: Repeat
WaitEvent()
Select EventID()
Case EVENT_WINDOWCLOSE, EVENT_APPTERMINATE
TPropertyGrid.GetInstance().CleanUp()
End
Case EVENT_PG_ITEMCHANGED
Select EventData()
Case 100
Local i:TPropertyItemBool = TPropertyItemBool(EventSource())
Print "Changed item: " + i.GetLabel() + ". New value is: " + EventText()
Case 101
Local i:TPropertyItemChoice = TPropertyItemChoice(EventSource())
Print "Changed item: " + i.GetLabel() + ". New value is: " + EventText()
Case 102
Local i:TPropertyItemColor = TPropertyItemColor(EventSource())
Print "Changed item:" + i.GetLabel() + ". New value is: " + EventText()
End Select
End Select
Forever
| |