List Icon Gadget: force number of columns

Windows specific forum
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

List Icon Gadget: force number of columns

Post by IdeasVacuum »

Scenario: You have a form with a ListIcon Gadget that has n Columns (say 0,1,2) and the Gadget is nailed to the form so that it will resize with it (I use gonzal's PureRESIZE lib).

The snag is that, when you drag the Window size out to the right, "column 3" is stretched to suit, rather than a column you are actually using. Is there a way around that conundrum?

Code: Select all

#Win = 0
#ListIcon = 1

Procedure OpenWin()
;------------------

          If OpenWindow(#Win, 100, 100, 400, 300,"4th Column",#PB_Window_SizeGadget|#PB_Window_SystemMenu|#PB_Window_TitleBar)

                          ListIconGadget(#ListIcon,10,25,380,250,"Col 0", 80,#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
                         AddGadgetColumn(#ListIcon, 1, "Col 1", 150)
                         AddGadgetColumn(#ListIcon, 2, "Col 2", 150)

                   ; Gadget Resizing
                     PureRESIZE_SetGadgetResize(#ListIcon, 1, 1, 1, 1)
                          SendMessage_(GadgetID(#ListIcon), #LVM_SETEXTENDEDLISTVIEWSTYLE, #LVS_EX_GRIDLINES, #LVS_EX_GRIDLINES)
          EndIf

EndProcedure


OpenWin()

          Repeat
                  iEvent = WaitWindowEvent(1)

           Until  iEvent = #PB_Event_CloseWindow

CloseWindow(#Win)
End
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: List Icon Gadget: force number of columns

Post by RASHAD »

Hi
I hope I understood you correctly.
Sorry I do not use any user lib.

Code: Select all

  Global Dim width(3)
  
  If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 200,#PB_ListIcon_GridLines)
      For x = 1 To 3 
        AddGadgetColumn(0, x, "Column " + Str(x), 300)
      Next
      For x = 0 To 8
        AddGadgetItem(0, x, "Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4")
      Next

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1            
          EndSelect
          
      Case #WM_ENTERSIZEMOVE
          WWidth.d = WindowWidth(0)
          width(0) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,0)
          width(1) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,1)
          width(2) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,2)

          
      Case #WM_EXITSIZEMOVE
          ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
          Scale.d = WindowWidth(0)/WWidth
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(0),#PB_Round_Up),0)
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(1),#PB_Round_Up),1)
          SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(2),#PB_Round_Up),2)      
      
  EndSelect
Until Quit = 1
EndIf
Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: List Icon Gadget: force number of columns

Post by IdeasVacuum »

Hi Rashad

That's exactly what I meant. 8)

I like the simplicity of your methods, I can apply those to other gadgets too. Thank you!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4997
Joined: Sun Apr 12, 2009 6:27 am

Re: List Icon Gadget: force number of columns

Post by RASHAD »

Hi IdeasVacuum
Enhanced Zoom Out - Zoom In ListIcon :)

Code: Select all

    
  If OpenWindow(0, 0, 0, 640, 300, "ListIconGadgets", #PB_Window_SystemMenu | #PB_Window_ScreenCentered|#PB_Window_SizeGadget)
    ListIconGadget(0,  10,  10, 620, 280, "Column 0", 200,#PB_ListIcon_GridLines)
      For x = 1 To 9 
        AddGadgetColumn(0, x, "Column " + Str(x), 300)
      Next
      For x = 0 To 8
        AddGadgetItem(0, x, "Item 0"+Chr(10)+"Item 1"+Chr(10)+"Item 2"+Chr(10)+"Item 3"+Chr(10)+"Item 4"+Chr(10)+"Item 5"+Chr(10))
      Next
      
      Col_No = 9
      
      Global Dim width(Col_No)

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
       
      
      Case #PB_Event_Gadget
            Select EventGadget()
             Case 1            
            EndSelect
            
            
      Case #WM_SIZE
            ResizeGadget(0,10,10,WindowWidth(0)-20,WindowHeight(0)-20)
            
          
      Case #WM_ENTERSIZEMOVE
            WWidth.d = WindowWidth(0)
            For i = 0 To Col_No
                width(i) = GetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,i)
            Next
          
      Case #WM_EXITSIZEMOVE
            Scale.d = WindowWidth(0)/WWidth
            For i = 0 To Col_No
                SetGadgetItemAttribute(0, 0, #PB_ListIcon_ColumnWidth ,Round(Scale*width(i),#PB_Round_Up),i)
            Next
      
  EndSelect
Until Quit = 1
EndIf

Egypt my love
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: List Icon Gadget: force number of columns

Post by IdeasVacuum »

ah, not really sure what to expect with the second example - what ever it is, it does not seem to want to do it on my machine :) (WinXP 32bit, PB4.60). Not to worry, the first example does exactly what I need.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Re: List Icon Gadget: force number of columns

Post by electrochrisso »

ah, not really sure what to expect with the second example - what ever it is, it does not seem to want to do it on my machine :) (WinXP 32bit, PB4.60).
Resizes the ListIconGadget as the window size is being resized, you might have this feature switched off and only updating when the mouse is released. I am using Win7 Starter, PB4.60.
PureBasic! Purely the best 8)
Post Reply