Listicongadget column identity

Just starting out? Need help? Post your questions and find answers here.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Listicongadget column identity

Post by RASHAD »

Thanks Shardik for testing
I expected that so I am using always Maybe to be in the safe side :)
Egypt my love
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 464
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Listicongadget column identity

Post by Mindphazer »

RASHAD wrote: Fri Feb 24, 2023 3:30 pm But guys no one report if it works with Linux & Mac :D
Hi RASHAD, very nice trick indeed. It doesn't work on MacOS because SetGadgetItemColor() is not supported on MacOSX...

Edit : sorry, i hadn't seen Shardik's reply...
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
Shardik
Addict
Addict
Posts: 2060
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Listicongadget column identity

Post by Shardik »

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 :)
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.

Unfortunately these solutions are often not working correctly in Linux and MacOS although theoretically they should work. But the implementation of PureBasic functions in Linux and MacOS are often very different, so that the corner cases you use sometimes only work in Windows.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Listicongadget column identity

Post by RASHAD »

@Mindphazer
Thank you for testing much appreciated

@Shardik
No one of the forum members [users of Linux or Mac] should be worry as long as we have you here
I am astonished that you have all these energy to control the 3 OS while I am struggling hard with just one [Windows] :lol:
I keep archiving your solutions for Linux and Mac just in case I will be enforced to use any
Thanks Shardik for everything
Egypt my love
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 464
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Listicongadget column identity

Post by Mindphazer »

RASHAD wrote: Sat Feb 25, 2023 12:17 pm Thanks Shardik for everything
True. Thanks for all your efforts to make a code crossplatform
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Axolotl
Addict
Addict
Posts: 852
Joined: Wed Dec 31, 2008 3:36 pm

Re: Listicongadget column identity

Post by Axolotl »

hello all,
here is another alternative, if you want to use the background color differently.

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() 
Happy coding and stay healthy.
Last edited by Axolotl on Mon Feb 27, 2023 3:23 pm, edited 1 time in total.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4955
Joined: Sun Apr 12, 2009 6:27 am

Re: Listicongadget column identity

Post by RASHAD »

Hi Axolotl
Sorry but it fails if you dragged and changed any column width to exceed the the listicon width and needed for Hal scroll
More work to do
Egypt my love
Axolotl
Addict
Addict
Posts: 852
Joined: Wed Dec 31, 2008 3:36 pm

Re: Listicongadget column identity

Post by Axolotl »

@RASHAD,
you are right. I need to consider the column shift. However, so far I can't find a PB-standard method for this.
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).
epog10
User
User
Posts: 93
Joined: Sat May 29, 2010 11:46 am
Location: UK

Re: Listicongadget column identity

Post by epog10 »

Sorry for the delay in answering - have been away.

Many thanks for the responses one of which I shall implement.

2015 ?????????????
Guess I am old and doddering but concerned that not only did I not remember this but when I searched the other day, whatever terms I used did not signal that thread.

Seems strange that the one function I suggested back then has not been implemented to complement the GetGadgetState for tabular lists.

Regards,
epog10
Post Reply