Header color in ListIconGadget

Mac OSX specific forum
User_Russian
Addict
Addict
Posts: 1582
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Header color in ListIconGadget

Post by User_Russian »

Is there a way to change the header color in ListIconGadget?
AZJIO
Addict
Addict
Posts: 2211
Joined: Sun May 14, 2017 1:48 am

Re: Header color in ListIconGadget

Post by AZJIO »

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.
User_Russian
Addict
Addict
Posts: 1582
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Header color in ListIconGadget

Post by User_Russian »

This is the code for Windows. It's needed for MacOS.
User avatar
Piero
Addict
Addict
Posts: 1025
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Header color in ListIconGadget

Post by Piero »

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! :?
User avatar
Shardik
Addict
Addict
Posts: 2064
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: Header color in ListIconGadget

Post by Shardik »

User_Russian wrote: Tue Sep 30, 2025 9:03 pm Is there a way to change the 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):

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
User_Russian
Addict
Addict
Posts: 1582
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Header color in ListIconGadget

Post by User_Russian »

Thank you.
User avatar
Piero
Addict
Addict
Posts: 1025
Joined: Sat Apr 29, 2023 6:04 pm
Location: Italy

Re: Header color in ListIconGadget

Post by Piero »

Thanks Shardik!
Post Reply