Page 3 of 3

Re: ListIconGadget with Sort and Arrow Icons

Posted: Mon Jul 13, 2020 11:52 pm
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).

Re: ListIconGadget with Sort and Arrow Icons

Posted: Tue Jul 14, 2020 2:17 am
by Rinzwind
Should be buildin and cross platform. The gui toolkit needs more attention from devs... its all very BASIC bad pun intended.

Re: ListIconGadget with Sort and Arrow Icons

Posted: Wed Jul 15, 2020 7:27 am
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.)

Re: ListIconGadget with Sort and Arrow Icons

Posted: Thu Apr 29, 2021 9:27 am
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

Re: ListIconGadget with Sort and Arrow Icons

Posted: Fri Dec 10, 2021 1:15 am
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?

Re: ListIconGadget with Sort and Arrow Icons

Posted: Tue Mar 01, 2022 4:54 am
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).

Re: ListIconGadget with Sort and Arrow Icons

Posted: Wed Mar 02, 2022 2:30 am
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.

Re: ListIconGadget with Sort and Arrow Icons

Posted: Wed Mar 02, 2022 4:59 am
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

Re: ListIconGadget with Sort and Arrow Icons

Posted: Wed Mar 02, 2022 5:13 am
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.

Re: ListIconGadget with Sort and Arrow Icons

Posted: Wed Sep 14, 2022 3:36 am
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!