ListIconGadget color-matching grid lines

Share your advanced PureBasic knowledge/code with the community.
BarryG
Addict
Addict
Posts: 4173
Joined: Thu Apr 18, 2019 8:17 am

ListIconGadget color-matching grid lines

Post by BarryG »

When I use gridlines with a colored ListIconGadget, the lines look horrible unless you color them to match. Here's how I do it:

Code: Select all

Procedure SetBackColorAndLines(gad,color)
  r=Red(color)-20 : If r<0 : r=0 : EndIf
  g=Green(color)-20 : If g<0 : g=0 : EndIf
  b=Blue(color)-20 : If b<0 : b=0 : EndIf
  SetGadgetColor(gad,#PB_Gadget_LineColor,RGB(r,g,b))
  SetGadgetColor(gad,#PB_Gadget_BackColor,color)
EndProcedure

If OpenWindow(0, 100, 100, 400, 100, "ListIcon Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ListIconGadget(0, 5, 5, 390, 90, "Name", 100, #PB_ListIcon_GridLines | #PB_ListIcon_FullRowSelect)
  AddGadgetColumn(0, 1, "Address", 250)
  AddGadgetItem(0, -1, "Harry Rannit"+Chr(10)+"12 Parliament Way, Battle Street, By the Bay")
  AddGadgetItem(0, -1, "Ginger Brokeit"+Chr(10)+"130 PureBasic Road, BigTown, CodeCity")
  
  ;SetGadgetColor(0,#PB_Gadget_BackColor,RGB(255,225,170)) ; The usual ugly way. :(
  
  SetBackColorAndLines(0,RGB(255,225,170)) ; The nice color-matching way. :)
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf
Comparison of yucky on the left, and color-matching on the right:

Image
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: ListIconGadget color-matching grid lines

Post by Caronte3D »

Looks better :D
Thanks! :wink:
User avatar
jacdelad
Addict
Addict
Posts: 2010
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: ListIconGadget color-matching grid lines

Post by jacdelad »

Very nice, never thought about the grid lines, but I will definitely look closer at them from now on.
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: ListIconGadget color-matching grid lines

Post by Kwai chang caine »

Nice thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply