Uses "TBGL"
#INCLUDE "SHEET.tBasicU"
Type t_myType
Identity As String
Phone As String
Reputation As Long
Cash As Double
End Type
Dim myList() As t_myType
Dim mySheet As Long
Dim hWnd As DWord
Dim lCharwidth, lCharHeight As Long
Function TBMain()
' -- Create and show window
hWnd = TBGL_CreateWindowEx("TBGL script - press ESC to quit", 640, 480, 32, %TBGL_WS_WINDOWED)
TBGL_ShowWindow
TBGL_BuildFont TBGL_FontHandle("Lucida Console", 12), 1
TBGL_SetActiveFont 1
TBGL_GetFontTextSize("X", lCharWidth, lCharHeight)
' make the rows a little higher
lCharHeight += 4
Fill_myList() ' just fill the demonstration-UDT-array with some data
' now "bind" the data-structure to some sheet which manages the grid to sort those
' items and draw them all below their headers, so tell every header which UDT-Element to use
' name of variable, size of one element
mySheet = SHEET_Create("myList", SizeOf(t_myType))
' sheetID, Header-Caption, Variable-Type, Flags, Offset from first Element, number of chars = width of header
SHEET_AddHeader(mySheet, "Name", %VarType_String, 0, UDT_ElementOffset(myList(1).Identity), 10)
SHEET_AddHeader(mySheet, "Phone", %VarType_String, 0, UDT_ElementOffset(myList(1).Phone) , 12)
SHEET_AddHeader(mySheet, "Reputation", %VarType_Long, 0, UDT_ElementOffset(myList(1).Reputation))
SHEET_AddHeader(mySheet, "Cash", %VarType_Double, 0, UDT_ElementOffset(myList(1).Cash), 10)
' -- Resets status of all keys
TBGL_ResetKeyState()
TBGL_UseTexturing(FALSE) ' will just draw text and boxes...
TBGL_RenderMatrix2D(0, 480, 640, 0) ' and just 2D
TBGL_DepthFunc(%TBGL_ALWAYS)
TBGL_SetActiveFont 1
TBGL_Color 255, 255, 127
' -- Main loop
While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
' call to draw some Listview-alike sheet now...
Draw_Sheet(mySheet)
TBGL_DrawFrame
' -- ESCAPE key to exit application
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Exit While
Wend
TBGL_DestroyWindow
End Function
' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Sub Draw_Sheet(ByVal Index As Long)
Static sHeader As String
Static X, Y, Vartype, Flags, Offset, nChars, lLeft As Long
Static MainType, SubType, IsArray, DataPtr, nElements As Long
Static pPtr As DWord
' as you see- this sub does not know anything about myList() but displays it's content...
thinBasic_VariableGetInfoEX(Sheet(Index).VarName, MainType, SubType, IsArray, DataPtr, nElements)
lLeft = 8 ' leave a little border
For X = 1 To Sheet(Index).nHeaders
If SHEET_GetHeaderInfo(Index, X, sHeader, VarType, Flags, Offset, nChars) Then
TBGL_PrintFont sHeader, lLeft, lCharHeight
If nElements Then
For Y = 1 To nElements
pPtr = DataPtr + Offset + (Y-1) * Sheet(Index).Varsize
Select Case VarType
Case %VarType_Long
TBGL_PrintFont( TStr$(Peek(Long, pPtr)), lLeft, (1+Y) * lCharHeight)
Case %VarType_Double
TBGL_PrintFont( Format$(Peek(Double, pPtr), "0.00" ), lLeft, (1+Y) * lCharHeight )
Case %VarType_String
TBGL_PrintFont( Peek$(Peek(DWord, pPtr), StrPtrLen(Peek(DWord, pPtr)) ), lLeft, (1+Y) * lCharHeight)
' for this script I just used those 3 VarTypes- more would be too confusing here
End Select
Next
End If
EndIf
' calculate left margin for next header:
lLeft += nChars * lCharWidth + 8
Next
End Sub
' ----------------------------------------------------------------------------------------
Sub Fill_myList()
ReDim myList(5)
With myList(1)
.Identity = "Petr"
.Phone = "unknown"
.Reputation = 10000
.Cash = 12345.67
End With
With myList(2)
.Identity = "Eros"
.Phone = "busy"
.Reputation = 10000
.Cash = 23456.78
End With
With myList(3)
.Identity = "John"
.Phone = "911"
End With
With myList(4)
.Identity = "Michael"
.Phone = "iPhone 4"
.Reputation = 5000
.Cash = -5.67
End With
With myList(5)
.Identity = "Max"
.Phone = "000-000-0000"
.Reputation = 10
.Cash = 1.00
End With
'add more elements to myList or change the content... Draw_Sheet() will be up-to-date anytime
End Sub
' ---------------------------------------------------------------------------------------
Maybe this is an idea to populate UI-Controls as MLGrid or Listview.
Bookmarks