Can ListIconGadgets have large icons in rows only?

Just starting out? Need help? Post your questions and find answers here.
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Can ListIconGadgets have large icons in rows only?

Post by BarryG »

Per the subject... is there a way to have a ListIconGadget with large icons (32x32 pixels) but in individual rows, instead of spanning the items horizontally?

Update: I worked out that it's do with the #LVM_SETVIEW message. But it still spans over multiple columns. Assuming my window has to be 700 pixels wide (and that each item text is long), then how do I make these one row only for each item?

I think the answer is here somewhere: http://www.cplusplus.com/forum/windows/169984/

Code: Select all

If OpenWindow(0, 300, 200, 700, 200, "Food", #PB_Window_SystemMenu)
  icon = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico")
  ListIconGadget(0, 5, 5, 690, 190, "Name", 690, #PB_ListIcon_FullRowSelect)
  AddGadgetItem(0, -1, "Apple", icon)
  AddGadgetItem(0, -1, "Banana", icon)
  AddGadgetItem(0, -1, "Carrot", icon)
  AddGadgetItem(0, -1, "Donut", icon)
  AddGadgetItem(0, -1, "Egg", icon)
  SendMessage_(GadgetID(0), #LVM_SETVIEW, #LV_VIEW_TILE, 0)
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Image

I'm not getting far with this, either:

Code: Select all

If OpenWindow(0, 300, 200, 600, 200, "Food", #PB_Window_SystemMenu)
  icon = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico")
  ListIconGadget(0, 5, 5, 590, 190, "Name", 590, #PB_ListIcon_FullRowSelect)
  AddGadgetItem(0, -1, "Apple", icon)
  AddGadgetItem(0, -1, "Banana", icon)
  AddGadgetItem(0, -1, "Carrot", icon)
  AddGadgetItem(0, -1, "Donut", icon)
  AddGadgetItem(0, -1, "Egg", icon)
  hWnd = GadgetID(0)
  SendMessage_(hWnd, #LVM_SETVIEW, #LV_VIEW_TILE, 0)
  LVTILEVIEWINFO.tvi = 0
  tvi\cbSize = SizeOf(LVTILEVIEWINFO)
  tvi\dwMask = #LVTVIM_COLUMNS
  tvi\cLines = 1
  SendMessage(hWnd, #LVM_SETTILEVIEWINFO, 0, tvi)
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Can ListIconGadgets have large icons in rows only?

Post by RASHAD »

@BarrG
Hi again
- Any icon size
- Many different icons can be used

Code: Select all

imgsize = 64
LoadFont(0,"Tahoma",16)
If OpenWindow(0, 300, 200, 400, 200, "Food", #PB_Window_SystemMenu)
  icon = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico")
  icon2 = CopyImage_(icon,#IMAGE_ICON	,imgsize,imgsize,#LR_COPYDELETEORG	)
  ListIconGadget(0, 5, 5, 390, 190, "Name", 180,#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines)
  SetGadgetFont(0,FontID(0))
  ILwnd = ImageList_Create_(imgsize,imgsize,#ILC_COLOR32| #ILC_MASK, 0, 100)
  ImageList_AddIcon_(ILwnd,icon2)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
  AddGadgetItem(0, -1, "Apple")
  AddGadgetItem(0, -1, "Banana")
  AddGadgetItem(0, -1, "Carrot")
  AddGadgetItem(0, -1, "Donut")
  AddGadgetItem(0, -1, "Egg")
  items = CountGadgetItems(0)
  ILwnd = ImageList_Create_(imgsize,imgsize,#ILC_COLOR32| #ILC_MASK, 0, 100)
  
  ;Add differet icons as you like
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
  lvi.LV_ITEM
  lvi\mask = #LVIF_IMAGE
  For i = 0 To items
    lvi\iItem = i : lvi\iImage = i
    SendMessage_(GadgetID(0),#LVM_SETITEM,0,lvi)
  Next 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Egypt my love
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: Can ListIconGadgets have large icons in rows only?

Post by BarryG »

Hi Rashad, your code works great but now I wondered if it can be done in like Report mode, where the icons are in columns and rows? So I have big icons in a grid? That would be appreciated. I've seen some code here but can't shoe-horn it into your example -> viewtopic.php?p=550964#p550964
User avatar
jacdelad
Addict
Addict
Posts: 1473
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: Can ListIconGadgets have large icons in rows only?

Post by jacdelad »

...RASHADs example uses report mode. Do you mean icons in every column? Than you have to add "#LVS_EX_SUBITEMIMAGES" to the style and modify "lvi\iSubItem = 1" with the correct column (counting starts with 0 and the first column ALWAYS has an image).

RASHADs example modified:

Code: Select all

imgsize = 64
LoadFont(0,"Tahoma",16)
If OpenWindow(0, 300, 200, 400, 200, "Food", #PB_Window_SystemMenu)
  icon = LoadImage(0, #PB_Compiler_Home + "Examples\Sources\Data\CdPlayer.ico")
  icon2 = CopyImage_(icon,#IMAGE_ICON	,imgsize,imgsize,#LR_COPYDELETEORG	)
  ListIconGadget(0, 5, 5, 390, 190, "Name", 180,#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect| #PB_ListIcon_GridLines|#LVS_EX_SUBITEMIMAGES)
  SetGadgetFont(0,FontID(0))
  ILwnd = ImageList_Create_(imgsize,imgsize,#ILC_COLOR32| #ILC_MASK, 0, 100)
  ImageList_AddIcon_(ILwnd,icon2)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
  AddGadgetItem(0, -1, "Apple")
  AddGadgetItem(0, -1, "Banana")
  AddGadgetItem(0, -1, "Carrot")
  AddGadgetItem(0, -1, "Donut")
  AddGadgetItem(0, -1, "Egg")
  items = CountGadgetItems(0)
  ILwnd = ImageList_Create_(imgsize,imgsize,#ILC_COLOR32| #ILC_MASK, 0, 100)
  
  ;Add differet icons as you like
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  ImageList_AddIcon_(ILwnd,icon2)
  SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
  lvi.LV_ITEM
  lvi\mask = #LVIF_IMAGE
  For i = 0 To items
    lvi\iItem = i : lvi\iImage = i
    lvi\iSubItem = 1
    SendMessage_(GadgetID(0),#LVM_SETITEM,0,lvi)
  Next 
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
PureBasic 6.04/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/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4659
Joined: Sun Apr 12, 2009 6:27 am

Re: Can ListIconGadgets have large icons in rows only?

Post by RASHAD »

Hi BarryG
You can change the size of the images by changing the size of the image and the ImageList()
line 54
If you want to use different sizes in the same list you can play with the canvas of the image

Code: Select all

Procedure InsertImg(Row,Col,Img)
  var.lv_item    
  Var\mask     =  #LVIF_IMAGE
  Var\iItem    = Row
  Var\iSubItem = Col
  Var\iImage   = Img ;Index of image in the list
  SendMessage_(GadgetID(0), #LVM_SETITEM, 0, @Var)
EndProcedure

CreateImage(0,64,64)
CreateImage(1,64,64)
StartDrawing(ImageOutput(1))
Box(0,0,64,64,#White)
Circle(32,32,28,0)
Circle(32,32,24,$00FAFB)
StopDrawing()

iinf.ICONINFO
iinf\xHotspot = 32
iinf\yHotspot = 32
iinf\hbmMask = ImageID(0)
iinf\hbmColor = ImageID(1)

Icwnd = CreateIconIndirect_(iinf)

CreateImage(2,64,64)
CreateImage(3,64,64)
StartDrawing(ImageOutput(3))
Box(0,0,64,64,#White)
Circle(32,32,28,0)
Circle(32,32,24,$0004FB)
StopDrawing()

iinf\hbmMask = ImageID(2)
iinf\hbmColor = ImageID(3)

Icwnd2 = CreateIconIndirect_(iinf)

For Img = 0 To 3
   FreeImage(Img)
Next

LoadFont(0,"Broadway",24)

OpenWindow(0,0,0,800,600, "Test", #PB_Window_ScreenCentered |#PB_Window_SystemMenu)       
ListIconGadget(0,10,10,780,540,"Column 1",255,#PB_ListIcon_MultiSelect|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
;SetGadgetColor(0,#PB_Gadget_LineColor,0)
SetGadgetFont(0,FontID(0)) 
AddGadgetColumn(0, 1, "Column 2",255) 
AddGadgetColumn(0, 2, "Column 3",255) 

SendMessage_(GadgetID(0), #LVM_SETEXTENDEDLISTVIEWSTYLE , #LVS_EX_SUBITEMIMAGES, #LVS_EX_SUBITEMIMAGES)

ILwnd = ImageList_Create_(64,64,#ILC_COLOR32| #ILC_MASK, 0, 100)
ImageList_AddIcon_(ILwnd,Icwnd)
ImageList_AddIcon_(ILwnd,Icwnd2)

SendMessage_(GadgetID(0), #LVM_SETIMAGELIST, #LVSIL_SMALL, ILwnd)
For i = 0 To 5 
  AddGadgetItem(0, -1, "111"+Chr(10)+ "222"+Chr(10)+"333"+Chr(10)+ "444",0) 
Next

ButtonGadget(1,10,570,60,24,"Insert") 
ButtonGadget(2,80,570,60,24,"Change")

;InsertImg(0,1,0)

Repeat
  Select WaitWindowEvent()
      
      Case #PB_Event_CloseWindow
            Quit = 1
      
      Case #PB_Event_Gadget
          Select EventGadget()
           Case 1
                InsertImg(0,1,0)
                InsertImg(3,2,0)
                
           Case 2
                Image ! 1
                InsertImg(0,1,Image)
                InsertImg(3,2,Image)
                
          EndSelect             
  EndSelect 

Until Quit = 1
End
Egypt my love
BarryG
Addict
Addict
Posts: 3318
Joined: Thu Apr 18, 2019 8:17 am

Re: Can ListIconGadgets have large icons in rows only?

Post by BarryG »

Thanks to both of you!
Post Reply