Re: Listicongadget column identity
Posted: Sat Feb 25, 2023 2:53 am
Thanks Shardik for testing
I expected that so I am using always Maybe to be in the safe side
I expected that so I am using always Maybe to be in the safe side

http://www.purebasic.com
https://www.purebasic.fr/english/
Hi RASHAD, very nice trick indeed. It doesn't work on MacOS because SetGadgetItemColor() is not supported on MacOSX...
I had seen your Maybe and I'm very grateful that you are cautious about the use in other operatings systems when not having tested it. I have already stated several times that I am very impressed about your clever and ingenious solutions in Windows to try native PB solutions without any Windows API.RASHAD wrote: Sat Feb 25, 2023 2:53 am Thanks Shardik for testing
I expected that so I am using always Maybe to be in the safe side![]()
True. Thanks for all your efforts to make a code crossplatform
Code: Select all
EnableExplicit
; Some shortcoming: first column must be visible, because the shift cannot be taken into account.
; ---------------------------------------------------------------------------------------------------------------------
Procedure.i ListIcon_GetColumnMouseClick(Gadget, MousePosX, MousePosY) ; index of the Column or -1 in case of failure
Protected column, count, width
count = GetGadgetAttribute(Gadget, #PB_ListIcon_ColumnCount)
For column = 0 To count - 1
width + GetGadgetItemAttribute(Gadget, 0, #PB_ListIcon_ColumnWidth, column)
If MousePosX < width
ProcedureReturn Column ; success, zero based index of column
EndIf
Next column
ProcedureReturn -1 ; failure, not a valid column ...
EndProcedure
; ---------------------------------------------------------------------------------------------------------------------
Procedure main()
Protected i, x, y, line$
If OpenWindow(0,0,0,640,480,"Test",#PB_Window_SystemMenu| #PB_Window_ScreenCentered)
ListIconGadget(0,10,10,620,460,"-0-",32,#PB_ListIcon_GridLines)
AddGadgetColumn(0,1,"Column 1",110)
AddGadgetColumn(0,2,"Column 2",100)
AddGadgetColumn(0,3,"Column 3",100)
AddGadgetColumn(0,4,"Column 4",100)
AddGadgetColumn(0,5,"Column 5",100)
For i = 0 To 16
line$ = LSet(Str(i),3," ")
AddGadgetItem(0, -1, "-0-" + Chr(10)+"Text on Line "+line$+" in Column 1"+Chr(10)+"Text on Line "+line$+" in Column 2"+Chr(10)+"Text on Line "+line$+" in Column 3")
Next
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break ; bye
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Select EventType()
Case #PB_EventType_LeftClick
x = WindowMouseX(0)
y = WindowMouseY(0)
Debug "Column " + Str(ListIcon_GetColumnMouseClick(0, x, y))
EndSelect
EndSelect
EndSelect
ForEver
EndIf
EndProcedure
main()