The following example allows you to set the color of text and background of an OptionGadget (successfully tested on MacOS 15.7.1 'Sequoia' with PB 6.21):
Code: Select all
EnableExplicit
Procedure SetOptionGadgetColor(GadgetID.I, ColorType.I, Color.I)
Protected Alpha.CGFloat
Protected AttributedTitle.I
Protected Cell.I
Protected Blue.CGFloat
Protected Green.CGFloat
Protected NSColor.I
Protected Range.NSRange
Protected Red.CGFloat
If GadgetType(GadgetID) = #PB_GadgetType_Option
Alpha = 1.0
Red = Red(Color) / 255
Green = Green(Color) / 255
Blue = Blue(Color) / 255
Select ColorType
Case #PB_Gadget_BackColor
Alpha = 1.0
Red = Red(Color) / 255
Green = Green(Color) / 255
Blue = Blue(Color) / 255
CocoaMessage(0, CocoaMessage(0, GadgetID(GadgetID), "cell"),
"setBackgroundColor:", CocoaMessage(0, 0,
"NSColor colorWithDeviceRed:@", @Red,
"green:@", @Green,
"blue:@", @Blue,
"alpha:@", @Alpha))
Case #PB_Gadget_FrontColor
Cell = CocoaMessage(0, GadgetID(GadgetID), "cell")
AttributedTitle = CocoaMessage(0, CocoaMessage(0, 0,
"NSMutableAttributedString alloc"), "initWithAttributedString:",
CocoaMessage(0, Cell, "attributedTitle"))
Range\length = CocoaMessage(0, AttributedTitle, "length")
NSColor = CocoaMessage(0, 0,
"NSColor colorWithDeviceRed:@", @Red,
"green:@", @Green,
"blue:@", @Blue,
"alpha:@", @Alpha)
CocoaMessage(0, AttributedTitle,
"addAttribute:$", @"NSColor",
"value:", NSColor,
"range:@", @Range)
CocoaMessage(0, Cell,
"setAttributedTitle:", AttributedTitle)
EndSelect
EndIf
EndProcedure
OpenWindow(0, 270, 100, 370, 70, "Colored OptionGadget")
OptionGadget(0, 10, 20, 350, 30,
"OptionGadget with indigo background and khaki text")
SetOptionGadgetColor(0, #PB_Gadget_BackColor, $82004B)
SetOptionGadgetColor(0, #PB_Gadget_FrontColor, $8CE6F0)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow