[Modules] ListEx (all OS / DPI)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Rinzwind wrote:Impressive job. What's yet missing is full keyboard navigation.
Yes! :D

I just coded this piece, but I don't know how to scroll the ListEx to display current position when the selected row goes beyond the bottom of the gadget.

Code: Select all

Procedure key_up(listExID.l, steps.l = 1)
  Debug "key up!" 
  Protected curPos.l  
  
  curPos = ListEx::GetState(listExID)
  If curPos > 0    
    curPos - steps
    If curPos < 0: curPos = 0: EndIf
    ListEx::SetState(listExID, curPos)
  EndIf  
EndProcedure

Procedure key_down(listExID.l, steps.l = 1)
  Debug "key down!"    
  Protected rowCount.l = 0
  Protected curPos.l
  
  rowCount = ListEx::CountItems(listExID)    
  curPos = ListEx::GetState(listExID)  
  If curPos < (rowCount - steps)
    curPos + steps
    If curPos > (rowCount - steps): curPos = (rowCount - steps): EndIf
    ListEx::SetState(listExID, curPos)    
  EndIf
EndProcedure  

#Window  = 0
Enumeration 1
  #List
  #MyEventKeyUP
  #MyEventKeyDOWN
EndEnumeration

If OpenWindow(#Window, 0, 0, 400, 300, "Window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  
  ListEx::Gadget(#List, 10, 10, 380, 280, "header", 360, "", ListEx::#GridLines)
  For cont = 1 To 30
    ListEx::AddItem(#List, ListEx::#LastItem, "Randy Roads")
    ListEx::AddItem(#List, ListEx::#LastItem, "Ozzy Osbourne")
  Next
  
  AddKeyboardShortcut(#Window, #PB_Shortcut_Up, #MyEventKeyUP)
  AddKeyboardShortcut(#Window, #PB_Shortcut_Down, #MyEventKeyDOWN)
  
  SetActiveGadget(#List)
  ListEx::SetState(#List,0)
  
  Repeat
    Event = WindowEvent()      
    MenuID = EventMenu()
    GadgetID = EventGadget()
    Select Event
        
      Case #PB_Event_Menu
        Select EventMenu()
          Case #myEventKeyDOWN
            If GetActiveGadget() = #List
              key_down(#List)
            EndIf
          Case #MyEventKeyUP
            If GetActiveGadget() = #List
              key_up(#List)
            EndIf          
        EndSelect
        
      Case #PB_Event_CloseWindow
      Case #PB_Event_Gadget
    EndSelect      
  Until Event = #PB_Event_CloseWindow
EndIf
CompilerEndIf
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

Update:
  • SetState() moves now the row into the visible area
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Thorsten1867 wrote:Update:
  • SetState() moves now the row into the visible area
Thank you :!:

With my previous example, It works fine with down-key, but not for up-key (selected row go out of visible area)
Image

:oops: Sorry for inconvenences
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

I made a small change. Try it again!
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Thorsten1867 wrote:I made a small change. Try it again!
Really thanks you!

Now it do a strange move:
Down-key is OK, but
first time UP-KEY is pressed it display from first row then, if you press UP-KEY again, it display the focused row
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

Update:
  • Key control (Up/Down, PageUp/PageDown, Home/End)
  • Bugfix
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Thorsten1867 wrote:Update:
  • Key control (Up/Down, PageUp/PageDown, Home/End)
  • Bugfix
Nice! but I still have the same issue that I mentioned in the previous post. With 20 or 30 more rows, when you press key down everything goes well, but when you press key up makes the effect of the image I put in my previous post.

Really, thank you very much for all these changes!
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

Try it again
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Edited/Updated

I think I found the issue: In Procedure SetVisible_(Row.i) I changed this line

ListEx()\Row\Offset = ListEx()\Row\Offset - Row to

ListEx()\Row\Offset = Row

And now everything seems to be fine (but I don't know if this change negatively affects other parts of code).

-------- ORIGINAL POST -------
Thorsten1867 wrote:Try it again
The problem persists (PB 5.70, Windows10 x64) :(
I just added these lines to have more rows to try.

Code: Select all

For cont = 1 To 100
  ListEx::AddItem(#List, ListEx::#LastItem, "Jack"     + #LF$ + "Jones"    + #LF$ + #LF$ + #LF$ + "Push")
Next
Image

Thank you for your effort and help!
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

Update: Bugfix

The problem was a small mistake in thinking and the formula was really very simple. :shock:
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Nice, all ok with cursor and focused row :D

On the other hand, would it be possible, after sorting the list, to keep the focus of the current row?

Thank you very much and I'm sorry to be so boring! :oops:
User avatar
Lord
Addict
Addict
Posts: 849
Joined: Tue May 26, 2009 2:11 pm

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Lord »

Lord wrote:...
Another thing:
Is it true, that ListEx::EventState(#List) in the example
always returns "0" when changing the three state checkbox?
In the meantime: has this been fixed?
Image
User avatar
Thorsten1867
Addict
Addict
Posts: 1366
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by Thorsten1867 »

Update:
  • Restore focus after sorting
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Thorsten1867 wrote:Update:
  • Restore focus after sorting
:D Thank you!
I am really amazed at what you are able to do for some of the members of this forum!
zikitrake
Addict
Addict
Posts: 834
Joined: Thu Mar 25, 2004 2:15 pm
Location: Spain

Re: [Modules] Editable and sortable ListGadget (all OS / DPI

Post by zikitrake »

Hi Thorsten1867, can you check this issue

After making ListEx::ClearItems() or ListEx::RemoveItem()
the value of ListEx::CountItems(#List) does not vary
(If the list had 10 rows, it continues to show 10)

Code: Select all

  If OpenWindow(0, 0, 0, 500, 200, "Window", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_SizeGadget)    
    ListEx::Gadget(1, 10, 10, 400, 70, "header1", 125, "", ListEx::#GridLines)    
    For c  = 1 To 10
      ListEx::AddItem(1, ListEx::#LastItem, "Randy Rhoads")
    Next
    
    Debug ListEx::CountItems(1)
    ListEx::ClearItems(1)
    Debug ListEx::CountItems(1)
    
    Repeat: Until WaitWindowEvent()  = #PB_Event_CloseWindow     
  EndIf
For now I added this line on these procedures (clearItems() and removeItem())

Code: Select all

ListEx()\Row\Number  = ListSize(ListEx()\Rows())
And it seem works fine :D

Thank you!
Post Reply