ListIconGadget with Sort and Arrow Icons

Share your advanced PureBasic knowledge/code with the community.
AMpos
Enthusiast
Enthusiast
Posts: 128
Joined: Fri Jun 05, 2020 12:47 am

Re: ListIconGadget with Sort and Arrow Icons

Post by AMpos »

My gosh, it works so fine and easy...

Note to newbies like me:

If you want to use this library, after creating your list, you just have to type

Code: Select all

nalorLIG::Enable(#ListIcon)
where #ListIcon is just your list pointer.

Also, use the latest version posted by "Dige" (in the 2nd page of this post, not the very first version).
Rinzwind
Enthusiast
Enthusiast
Posts: 638
Joined: Wed Mar 11, 2009 4:06 pm
Location: NL

Re: ListIconGadget with Sort and Arrow Icons

Post by Rinzwind »

Should be buildin and cross platform. The gui toolkit needs more attention from devs... its all very BASIC bad pun intended.
User avatar
Jac de Lad
Enthusiast
Enthusiast
Posts: 106
Joined: Wed Jul 15, 2020 7:10 am
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by Jac de Lad »

Hello,
I'm pretty new to PureBasic, coming from XProfan like some other people here. I have 2 things to say (beside, that this module is really great!):

First, there's a bug in the code, or let's say some "unwanted behaviour". Looking at the comparison functions (I picked "CompareFloat" to demonstrate it) sorting is not stable:

Code: Select all

 Procedure   CompareFloat(sEntry1.s, sEntry2.s, SortOrder.b)
    ; ' -----------------------------------------------------
    ; ' Gibt zurück, ob das erste der beiden unterschiedlichen
    ; ' Elemente nach Maßgabe des Parameters SortOrder größer
    ; ' (1 bei aufsteigender Sortierung) oder kleiner (-1 bei
    ; ' aufsteigender Sortierung) als das zweite Element ist.
    ; ' Gleiche Elemente wurden bereits in CompareFunc ausge-
    ; ' schlossen; für sie wäre sonst 0 zurückzugeben.
    ; ' -----------------------------------------------------
    ; ' Rückgabewert je nach erwünschter Sortierung:
   
    ReplaceString(sEntry1, ",", ".", #PB_String_InPlace, 1, 1) ; ersetze Dezimalkomma durch Punkt, damit ValF korrekt arbeitet
    ReplaceString(sEntry2, ",", ".", #PB_String_InPlace, 1, 1)
   
    If SortOrder = #AscSort
      ; Aufsteigende Sortierung zweier unterschiedlicher Zahlen
      If ValF(sEntry1) < ValF(sEntry2)
        ProcedureReturn -1
      Else
        ProcedureReturn 1
      EndIf
    Else ; Absteigende Sortierung
      If ValF(sEntry1) > ValF(sEntry2)
        ProcedureReturn -1
      Else
        ProcedureReturn 1
      EndIf
    EndIf         
   
  EndProcedure
When sorting ascending this code looks up if the first entry lower than the second. If so it stays the same, otherwise they are swapped. If both entries are the same, they are swapped. This is usually not wanted. It should be either

Code: Select all

      If ValF(sEntry1) <= ValF(sEntry2)
or

Code: Select all

      ValF(sEntry2) > If ValF(sEntry1) 
for ascending sorting. this would make sorting stable.
https://en.wikipedia.org/wiki/Sorting_a ... #Stability

Second: If possible I would like to get some enhancements, but if not I will do them by myself (it will just take longer since I'm very new to PureBasic). I would really appreciate some more functions, including RefreshSort (do the last sort again, I need this for a ListIconGadget that is cleared and filled again), SortNow (sort a ListIconGadget by a selected Column and Order (I already edited the code for myself to do this)) and ResetSort (speaks for itself.)
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by jacdelad »

There's another minor "bug" inside, which isn't really a bug. If the ListIcon is placed on another control, like a splitter, the sorting won't work, because the module tries to retrieve the messages from the splitter and not the window. A little change in one line of the Enable-function is all you need:

Change

Code: Select all

SetWindowSubclass(GetParent_(GadgetID(gadget)), @ColumnClickCallback(), 0, 0)
to

Code: Select all

SetWindowSubclass(GetAncestor_(GadgetID(gadget), #GA_ROOT), @ColumnClickCallback(), 0, 0)
which will always retrieve the window. No changes for projects that use this module needed.

This fix was not directly found by me, it is from RSBasic. Kudos to him (though I didn't tell him why I had this problem, lol). See here: https://www.purebasic.fr/german/viewtop ... 53#p359753
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by jacdelad »

@nalor: I've done some improvements, like in the last post and the one before. Would you mind me posting a slightly tweaked version of your module?
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Amundo
Enthusiast
Enthusiast
Posts: 191
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: ListIconGadget with Sort and Arrow Icons

Post by Amundo »

Hi Jac, thanks to you (and of course, the OP and others) for input into this module.

I can't speak for Nalor, but I would welcome if you posted your improvements.

(And, as always, sorry for necro'ing this and any post, but people always find stuff long after things have been posted, and to add to it only helps yet more people who will come after, looking for the same help).
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by jacdelad »

I'm not sure if I'm allowed to post it since the base isn't my code and nalor didn't answer.
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Amundo
Enthusiast
Enthusiast
Posts: 191
Joined: Thu Feb 16, 2006 1:41 am
Location: New Zealand

Re: ListIconGadget with Sort and Arrow Icons

Post by Amundo »

I respect your integrity, but Nalor may never answer and I see people post their additions/changes all the time without requesting permission

:D
Win8.1, PB5.x, okayish CPU, onboard video card, fuzzy monitor (or is that my eyesight?)
"When the facts change, I change my mind" - John Maynard Keynes
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by jacdelad »

Thanks for your respect, but without explicit permission I won't post the full code. I mentioned the changes above, so everyone can change himself/herself. The other changes aren't so important, just some minor improvements.
Nalor was last active on November 3rd, so chances aren't too bad he will read it and answer.
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
User avatar
jacdelad
Addict
Addict
Posts: 1492
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: ListIconGadget with Sort and Arrow Icons

Post by jacdelad »

Replying to myself on this post (viewtopic.php?p=569404#p569404):

Code: Select all

SetWindowSubclass(GetAncestor_(GadgetID(gadget), #GA_ROOT), @ColumnClickCallback(), 0, 0)
is not completely right, especially if the ListIconGadget is placed within a SplitterGadget or on a Container. It hast to be

Code: Select all

SetWindowSubclass(GetAncestor_(GadgetID(gadget), #GA_PARENT), @ColumnClickCallback(), 0, 0)
...still a great Module!
PureBasic 6.11/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/150TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
Post Reply