Header color in ListIconGadget
-
- Addict
- Posts: 1582
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Header color in ListIconGadget
Is there a way to change the header color in ListIconGadget?
Re: Header color in ListIconGadget
I didn't pay attention to which section
Last edited by AZJIO on Wed Oct 01, 2025 4:37 pm, edited 1 time in total.
-
- Addict
- Posts: 1582
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Header color in ListIconGadget
This is the code for Windows. It's needed for MacOS.
Re: Header color in ListIconGadget
What should an Italian think about Russians after reading this thread?
Jokes apart, what happened? Something was deleted?
Edit: Oooh; probably it was because AZJIO didn't get a Mac!
Jokes apart, what happened? Something was deleted?
Edit: Oooh; probably it was because AZJIO didn't get a Mac!

Re: Header color in ListIconGadget
The following example demonstrates how to change the text and background color of a header cell in a ListIconGadget (tested successfully on MacOS 15.7.1 'Sequoia' with PB 6.21 and Intel processor):User_Russian wrote: Tue Sep 30, 2025 9:03 pm Is there a way to change the header color in ListIconGadget?
Code: Select all
EnableExplicit
CompilerIf #PB_Compiler_Version < 600
Import "-fno-pie" : EndImport
CompilerEndIf
Procedure ChangeHeaderCellColor(ListIconID.I, Column.I, ColorTarget.I,
RGBColor.I)
Protected Alpha.CGFloat = 1.0
Protected *AttributedTitle
Protected Blue.CGFloat
Protected ColumnObject.I
Protected ColumnID.S = Str(Column)
Protected Green.CGFloat
Protected HeaderCell.I
Protected NSColor.I
Protected Range.NSRange
Protected Red.CGFloat
Alpha = 1.0
Red = Red(RGBColor) / 255
Green = Green(RGBColor) / 255
Blue = Blue(RGBColor) / 255
; ----- Convert RGB color to NSColor
NSColor = CocoaMessage(0, 0,
"NSColor colorWithDeviceRed:@", @Red,
"green:@", @Green,
"blue:@", @Blue,
"alpha:@", @Alpha)
; ----- Get column object of column
CocoaMessage(@ColumnObject, GadgetID(ListIconID),
"tableColumnWithIdentifier:$", @ColumnID)
; ----- Get header cell
HeaderCell = CocoaMessage(0, ColumnObject, "headerCell")
Select ColorTarget
Case #PB_Gadget_TitleBackColor
CocoaMessage(0, HeaderCell, "setDrawsBackground:", #True)
CocoaMessage(0, HeaderCell,
"setBackgroundColor:", NSColor)
Case #PB_Gadget_TitleFrontColor
*AttributedTitle = CocoaMessage(0, CocoaMessage(0, 0,
"NSMutableAttributedString alloc"), "initWithAttributedString:",
CocoaMessage(0, HeaderCell, "attributedStringValue"))
Range\length = CocoaMessage(0, *AttributedTitle, "length")
CocoaMessage(0, *AttributedTitle,
"addAttribute:$", @"NSColor",
"value:", NSColor,
"range:@", @Range)
CocoaMessage(0, HeaderCell,
"setAttributedStringValue:", *AttributedTitle)
EndSelect
EndProcedure
OpenWindow(0, 200, 100, 428, 122,
"Change text and background color of header cell")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20, "Name",
110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", GadgetWidth(0) - GetGadgetItemAttribute(0, 0,
#PB_ListIcon_ColumnWidth) - 8)
AddGadgetItem(0, -1, "Harry Rannit" + #LF$ +
"12 Parliament Way, Battle Street, By the Bay")
AddGadgetItem(0, -1, "Ginger Brokeit" + #LF$ +
"130 PureBasic Road, BigTown, CodeCity")
AddGadgetItem(0, -1, "Didi Foundit" + #LF$ +
"321 Logo Drive, Mouse House, Downtown")
ChangeHeaderCellColor(0, 0, #PB_Gadget_TitleBackColor, #Blue)
ChangeHeaderCellColor(0, 0, #PB_Gadget_TitleFrontColor, #Yellow)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Collection of cross-platform examples with API functions to extend PureBasic
-
- Addict
- Posts: 1582
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: Header color in ListIconGadget
Thank you.
Re: Header color in ListIconGadget
Thanks Shardik!