My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
propertygrid  
event-driven property grid for maxgui applications
Phase-Deploy, Featured
Updated Feb 6, 2012 by wiebo.de.wit

propertygrid.mod

Repo location

This 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:

Types

The module consists of the following types:

  • TPropertyGrid : This is the main container object. It holds the property groups on a scrollpanel and handles group events. You can create one property grid, as it is a singleton.
  • TPropertyGroup : A group contains items. It can also contain other groups, etc.
  • TPropertyItem : there are several property item types:
    • TpropertyItemBool : a button to select True or False.
    • TpropertyItemChoice : a pull-down gadget to select a choice from a list
    • TpropertyItemColor : click-able color select icon.
    • TpropertyItemFloat : a field to enter a FLOAT value. Input is filtered.
    • TpropertyItemInt : a field to enter an INT value. Input is filtered.
    • TpropertyItemSeparator : an empty item which can contain a label. Useful for grouping items.
    • TpropertyItemString : a field to enter a STRING value. Input is filtered.
    • TpropertyItemPath : a click-able folder icon to select a file.

Events

The 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 use

Put 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

Sign in to add a comment
Powered by Google Project Hosting