Colorize text in ListViewGadget
Colorize text in ListViewGadget
I've used this code in my program and with 6.0 Beta 7-M1 it no longer works.
https://www.purebasic.fr/english/viewto ... 70#p487570
The text no longer shows.
It doesn't work in 6.0 Beta 7x64 either
			
			
									
									https://www.purebasic.fr/english/viewto ... 70#p487570
The text no longer shows.
It doesn't work in 6.0 Beta 7x64 either
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
						Re: [6.0B7M1] Colorize text in ListViewGadget
We changed the way yo render a cell to be better looking, so you need to adapt your OS code to match it unfortunately.
			
			
									
									
						Re: [6.0B7M1] Colorize text in ListViewGadget
Fred, thanks for the reply.
Maybe this thread should be moved to the Mac OSX forum so more people can see it and, maybe, come up with a solution.
See example by Shardik that works below...
			
			
													Maybe this thread should be moved to the Mac OSX forum so more people can see it and, maybe, come up with a solution.
See example by Shardik that works below...
					Last edited by WilliamL on Fri May 13, 2022 3:05 pm, edited 1 time in total.
									
			
									MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
						Re: [6.0B7M1] Colorize text in ListViewGadget
I can confirm that my example linked above doesn't work anymore correctly (text isn't displayed) with PB 6.00 x64 Beta 7 on MacOS Catalina, Big Sur and Monterey (tested in Light and Dark Mode). The same example still works like a charm with PB 6.00 x64 Beta 6 and PB 5.73 x64 (in Light Mode, for Dark Mode the chosen colors still should be adjusted).
					Last edited by Shardik on Wed May 11, 2022 12:20 pm, edited 1 time in total.
									
			
									
						Re: [6.0B7M1] Colorize text in ListViewGadget
It would be nice if we knew how the cell is rendered now.
			
			
									
									My Projects ThreadToGUI / OOP-BaseClass /  EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
						PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: [6.0B7M1] Colorize text in ListViewGadget
We now use a specialized PBIconTextCell for ListIconGadget and ListViewGadget (in the :dataCellForTableColumn callback). It allows us to properly display an icon in the same column as text for ListIconGadget() instead of having a separate column as before (which was not good looking).
			
			
									
									
						Re: [6.0B7M1] Colorize text in ListViewGadget
Thus, many of our codes for NSTableView no longer work 
Link: https://www.purebasic.fr/english/viewtopic.php?t=77111
Link: https://www.purebasic.fr/english/viewto ... 25#p448525
and more
			
			
									
									Link: https://www.purebasic.fr/english/viewtopic.php?t=77111
Link: https://www.purebasic.fr/english/viewto ... 25#p448525
and more
My Projects ThreadToGUI / OOP-BaseClass /  EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
						PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: [6.0B7M1] Colorize text in ListViewGadget
This is an insanely big issue for me and surely for other people who used any customization on ListIcon and ListView gadgets on macOS. Even the most basic things stopped working now. Can anyone please explain how to work with those gadgets now? Just a general approach would be extremely useful to figure out the rest.
			
			
									
									
						Re: [6.0B7M1] Colorize text in ListViewGadget
WilliamL wrote: Mon May 09, 2022 9:29 pm I've used this code in my program and with 6.0 Beta 7-M1 it no longer works.
https://www.purebasic.fr/english/viewto ... 70#p487570
The text no longer shows.
It doesn't work in 6.0 Beta 7x64 either
I have patched my CellDisplayCallback() to work with PB 6.00 x64 Beta 7 in Light Mode (for Dark Mode you should still adapt the colors). It's also working in pre Beta 7 and PB 5.73. The trick is to not only set the front and back color but also to display the text in each call of the CellDisplayCallback (which wasn't necessary in pre Beta 7):
Code: Select all
EnableExplicit
Define AppDelegate.I = CocoaMessage(0, CocoaMessage(0, 0,
  "NSApplication sharedApplication"), "delegate")
Define DelegateClass.I = CocoaMessage(0, AppDelegate, "class")
Define i.I
Define Selector.I = sel_registerName_("tableView:willDisplayCell:" +
  "forTableColumn:row:")
Dim ListViewCellColor.Q(0)
ProcedureC CellDisplayCallback(Object.I, Selector.I, TableView.I, Cell.I,
  *Column, Row.I)
  Shared ListViewCellColor.Q()
  Protected Alpha.CGFloat
  Protected BackColor.L
  Protected Blue.CGFloat
  Protected CellColor.Q
  Protected CellText.S
  Protected FrontColor.L
  Protected Green.CGFloat
  Protected Red.CGFloat
  CellColor = ListViewCellColor(Row)
  If CellColor = 0
    CocoaMessage(0, Cell, "setDrawsBackground:", #NO)
    CocoaMessage(0, Cell, 
      "setTextColor:", CocoaMessage(0, 0, "NSColor textColor"))
  Else
    BackColor = CellColor & $FFFFFF
    If BackColor = 0
      CocoaMessage(0, Cell, "setDrawsBackground:", #NO)
    Else
      CocoaMessage(0, Cell, "setDrawsBackground:", #YES)
      Alpha = 1
      Red = Red(BackColor) / 255
      Green = Green(BackColor) / 255
      Blue = Blue(BackColor) / 255
      CocoaMessage(0, Cell, "setBackgroundColor:", CocoaMessage(0, 0,
        "NSColor colorWithDeviceRed:@", @Red,
        "green:@", @Green,
        "blue:@", @Blue,
        "alpha:@", @Alpha))
    EndIf
    FrontColor = (CellColor >> 32) & $FFFFFF
    If FrontColor = 0
      CocoaMessage(0, Cell, 
        "setTextColor:", CocoaMessage(0, 0, "NSColor textColor"))
    Else
      Alpha = 1
      Red = Red(FrontColor) / 255
      Green = Green(FrontColor) / 255
      Blue = Blue(FrontColor) / 255
      CocoaMessage(0, Cell, "setTextColor:", CocoaMessage(0, 0,
        "NSColor colorWithDeviceRed:@", @Red,
        "green:@", @Green,
        "blue:@", @Blue,
        "alpha:@", @Alpha))
    EndIf
  EndIf
  CellText = GetGadgetItemText(CocoaMessage(0, TableView, "tag"), Row, 0)
  CocoaMessage(0, Cell, "setStringValue:$", @CellText)
EndProcedure
Procedure SetGadgetItemColorEx(GadgetID.I, Row.I, ColorType.I, Color.I)
  Shared ListViewCellColor.Q()
  Protected CellColor.Q
  Protected RowCount.I
  If ArraySize(ListViewCellColor()) = 0
    RowCount = CocoaMessage(0, GadgetID(GadgetID), "numberOfRows")
    Dim ListViewCellColor(RowCount - 1)
  EndIf
  CellColor = ListViewCellColor(Row)
  Select ColorType
    Case #PB_Gadget_BackColor
      CellColor ! (Color & $FFFFFF)
    Case #PB_Gadget_FrontColor
      CellColor ! ((Color & $FFFFFF) << 32)
  EndSelect
  ListViewCellColor(Row) = CellColor
EndProcedure
Macro SetGadgetItemColor(GadgetID, Row, ColorType, Color)
  SetGadgetItemColorEx(GadgetID, Row, ColorType, Color)
EndMacro
OpenWindow(0, 200, 100, 430, 150,
  "Change color of text and background in single rows")
ListViewGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20)
For i = 1 To 10
  AddGadgetItem(0, -1, "Line " + Str(i))
Next i
class_addMethod_(DelegateClass, Selector, @CellDisplayCallback(), "v@:@@@@")
CocoaMessage(0, GadgetID(0), "setDelegate:", AppDelegate)
; ----- Set background color of line 1 to yellow
SetGadgetItemColor(0, 0, #PB_Gadget_BackColor, $FFFF)
; ----- Set background color of line 5 to X11 color "Aquamarine"
SetGadgetItemColor(0, 4, #PB_Gadget_BackColor, $D4FF7F)
; ----- Set text color of line 3 to blue
SetGadgetItemColor(0, 2, #PB_Gadget_FrontColor, $FF0000)
; ----- Set text color of line 5 to red
SetGadgetItemColor(0, 4, #PB_Gadget_FrontColor, $FF)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
					Last edited by Shardik on Thu May 12, 2022 6:55 pm, edited 2 times in total.
									
			
									
						Re: [6.0B7M1] Colorize text in ListViewGadget
You can get the gadget number inside callback with

			
			
									
									Code: Select all
Gadget = CocoaMessage(0, TableView, "tag")
My Projects ThreadToGUI / OOP-BaseClass /  EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
						PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: [6.0B7M1] Colorize text in ListViewGadget
You are right, I always forget that...mk-soft wrote: Thu May 12, 2022 6:31 pm You can get the gadget number inside callback withCode: Select all
Gadget = CocoaMessage(0, TableView, "tag")![]()
I have also removed the variable Column.I from the callback because it's not needed for the ListViewGadget: the Column is always 0.
Re: [6.0B7M1] Colorize text in ListViewGadget
Thanks Shardik,
That works for me. (whew!)

			
			
									
									That works for me. (whew!)
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
						Re: [6.0B7M1] Colorize text in ListViewGadget
Is it now possible to color the Gadget with PB commands like Windows?Fred wrote: Tue May 10, 2022 9:54 am We changed the way yo render a cell to be better looking, so you need to adapt your OS code to match it unfortunately.
Re: [6.0B7M1] Colorize text in ListViewGadget
No better looking. It looks worse. The horizontal distance between the grid and the text is almost zero now. The text looks pushed to the edge. The horizontal distance between the grid and the header title text seems unchanged:Fred wrote: Tue May 10, 2022 9:54 am We changed the way yo render a cell to be better looking, so you need to adapt your OS code to match it unfortunately.
before:

now (Typesetters would shake their heads):

- Thorsten1867
 - Addict

 - Posts: 1372
 - Joined: Wed Aug 24, 2005 4:02 pm
 - Location: Germany
 
Re: Colorize text in ListViewGadget
Translated with http://www.DeepL.com/Translator
Download of PureBasic - Modules
Download of PureBasic - Programs
[Windows 11 x64] [PB V5.7x]
						Download of PureBasic - Modules
Download of PureBasic - Programs
[Windows 11 x64] [PB V5.7x]


