Cheap 'n easy listicon jumping

Share your advanced PureBasic knowledge/code with the community.
Jagermeister
Enthusiast
Enthusiast
Posts: 137
Joined: Thu Nov 15, 2012 11:38 pm
Location: Los Angeles

Cheap 'n easy listicon jumping

Post by Jagermeister »

Crossplatform.

Technical findings:

The bottommost FULLY viewed row counts to a listicon. Experiment:
- Change height of #listicon_pages to 282 and observe highlighted row. Now 283...

Code: Select all

Enumeration
  #window
  #listicon_chapters
  #listicon_pages
EndEnumeration

Dim array_chapters.s(4)
array_chapters(0) = "One"
array_chapters(1) = "Two"
array_chapters(2) = "Three"
array_chapters(3) = "Four"
array_chapters(4) = "Five"

Dim array_pages(99)

Declare ChapterJump()

OpenWindow(#window, 0, 0, 230, 300, "Chapter Jump", #PB_Window_ScreenCentered)
ListIconGadget(#listicon_chapters, 10, 10, 100, 280, "Chapter", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines)
ListIconGadget(#listicon_pages, 120, 10, 100, 280, "Pages", 100, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection)
BindGadgetEvent(#listicon_chapters, @ChapterJump(),  #PB_EventType_Change)

For chapter = 0 To 4
  AddGadgetItem(#listicon_chapters, chapter, array_chapters(chapter))
  last = CountGadgetItems(#listicon_pages)
  SetGadgetItemData(#listicon_chapters, chapter, last)
  page = 0
  While page < 20
    AddGadgetItem(#listicon_pages, -1, array_chapters(chapter) + " : " + Str(page))
    page + 1
  Wend
Next chapter

Procedure ChapterJump()
  chapter_begin = GetGadgetItemData(#listicon_chapters, GetGadgetState(#listicon_chapters))
  ;Debug chapter_begin
  SetGadgetState(#listicon_pages, 0) ; Resets ListIcon to the top...
  SetGadgetState(#listicon_pages, chapter_begin + 12) ; Pushes selection to the top... [ the + 12 can be adjusted relative to listicon height ]
  SetGadgetState(#listicon_pages, chapter_begin) ; Highlights selection
EndProcedure

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
End