Page 1 of 2
Set alignment of ListIconGadget columns in PB 6
Posted: Fri May 27, 2022 9:43 am
by Lebostein
so far I used this code:
Code: Select all
Procedure SetListIconColumnJustification(ListIconID.i, ColumnIndex.i, Alignment.i)
Protected ColumnHeaderCell.i
Protected ColumnObject.i
Protected ColumnObjectArray.i
CocoaMessage(@ColumnObjectArray, GadgetID(ListIconID), "tableColumns")
CocoaMessage(@ColumnObject, ColumnObjectArray, "objectAtIndex:", ColumnIndex)
CocoaMessage(0, CocoaMessage(0, ColumnObject, "dataCell"), "setAlignment:", Alignment)
CocoaMessage(@ColumnHeaderCell, ColumnObject, "headerCell")
CocoaMessage(0, ColumnHeaderCell, "setAlignment:", Alignment)
EndProcedure
But with PB 6 it dont' work.
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Fri May 27, 2022 2:11 pm
by mk-soft
This is due to "PBIconTextCell".
I wanted to start a bug discussion to see if Fred might return to the old NSTableView procedure for the Cell.
https://www.purebasic.fr/english/viewtopic.php?t=79156
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Wed Jun 08, 2022 12:48 pm
by Lebostein
How I could align the colums center an right with Mac OS API? Is it possible with the new "PBIconTextCell"? I wonder why such basic format functions are not implemented if the Gadget is rewritten anyway...
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Jun 09, 2022 8:56 pm
by deseven
Code: Select all
EnableExplicit
#justifyLeft = 0
#justifyCenter = 1
#justifyRight = 2
Define app.i = CocoaMessage(0,0,"NSApplication sharedApplication")
Define appDelegate.i = CocoaMessage(0,app,"delegate")
Define delegateClass.i = CocoaMessage(0,appDelegate,"class")
ProcedureC CellDisplayCallback(Object.I,Selector.I,TableView.I,Cell.I,*Column,Row.I)
Protected LineFrame.NSRect
Protected RowFrame.NSRect
Protected TextSize.NSSize
Protected CellFrame.NSRect
Protected BoldFontSize.CGFloat = 15.0
Protected FontSize.CGFloat = 13.0
Protected Column.i = CocoaMessage(0,CocoaMessage(0,TableView,"tableColumns"),"indexOfObject:",*Column)
Protected Gadget.i = CocoaMessage(0,TableView,"tag")
Protected CellText.s = GetGadgetItemText(Gadget,Row,Column)
Select Column
Case 0
CocoaMessage(0,Cell,"setAlignment:",#justifyCenter)
Case 1
CocoaMessage(0,Cell,"setAlignment:",#justifyRight)
EndSelect
CocoaMessage(0,Cell,"setStringValue:$",@CellText)
EndProcedure
OpenWindow(0,0,0,400,300,"ListIconGadget - centered text",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,380,280,"Column A",100)
AddGadgetColumn(0,1,"Column B",100)
AddGadgetItem(0,-1,"Test 1" + Chr(10) + "Test 2")
AddGadgetItem(0,-1,"Test 3" + Chr(10) + "Test 4")
class_addMethod_(delegateClass,sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),@CellDisplayCallback(),"v@:@@@@")
CocoaMessage(0,GadgetID(0),"setDelegate:",appDelegate)
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Jun 09, 2022 10:58 pm
by mk-soft
And
Code: Select all
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Wed Oct 26, 2022 8:48 pm
by Lebostein
It is possible to transform this in a function like:
SetListIconColumnAlignment(GadgetID, ColumnIndex, Alignment)
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Wed Oct 26, 2022 8:52 pm
by deseven
It's possible, as a module for example, but inside you'll still have the same callback that defines how things should look like when they are being displayed.
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Oct 27, 2022 10:00 am
by Lebostein
deseven wrote: Wed Oct 26, 2022 8:52 pm
It's possible, as a module for example, but inside you'll still have the same callback that defines how things should look like when they are being displayed.
OK, but I need a callback? With the old implementation von ListView no callback was needed to change the alignment (see code in the first posting).
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Oct 27, 2022 10:04 am
by deseven
Lebostein wrote: Thu Oct 27, 2022 10:00 am
OK, but I need a callback? With the old implementation von ListView no callback was needed to change the alignment (see code in the first posting).
Yes, you do need a callback now. But you can create an abstraction layer that will allow you to set alignment and other types of styling using simple procedure calls.
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Oct 27, 2022 7:08 pm
by Lebostein
Hard to understand for me. At the moment your callback functions is called 4 to 6 times per click (!) on this gadet. Is that really necessary?
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Oct 27, 2022 8:04 pm
by deseven
You should ask Apple whether it's necessary or not, we can't control how often a callback is being called.
Docs for the reference:
https://developer.apple.com/documentati ... guage=objc
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Nov 17, 2022 12:37 pm
by Lebostein
The code seems not combatible with icons. Add this two lines before the Forever-Loop:
Biggest problem: #PB_EventType_Change is not triggered if you click in the gadget (or press the arrow keys up/down if a line is selected)
Code: Select all
EnableExplicit
#justifyLeft = 0
#justifyCenter = 1
#justifyRight = 2
Define app.i = CocoaMessage(0,0,"NSApplication sharedApplication")
Define appDelegate.i = CocoaMessage(0,app,"delegate")
Define delegateClass.i = CocoaMessage(0,appDelegate,"class")
ProcedureC CellDisplayCallback(Object.I,Selector.I,TableView.I,Cell.I,*Column,Row.I)
Protected LineFrame.NSRect
Protected RowFrame.NSRect
Protected TextSize.NSSize
Protected CellFrame.NSRect
Protected BoldFontSize.CGFloat = 15.0
Protected FontSize.CGFloat = 13.0
Protected Column.i = CocoaMessage(0,CocoaMessage(0,TableView,"tableColumns"),"indexOfObject:",*Column)
Protected Gadget.i = CocoaMessage(0,TableView,"tag")
Protected CellText.s = GetGadgetItemText(Gadget,Row,Column)
Select Column
Case 0
CocoaMessage(0,Cell,"setAlignment:",#justifyCenter)
Case 1
CocoaMessage(0,Cell,"setAlignment:",#justifyRight)
EndSelect
CocoaMessage(0,Cell,"setStringValue:$",@CellText)
EndProcedure
OpenWindow(0,0,0,400,300,"ListIconGadget - centered text",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(0,10,10,380,280,"Column A",100)
AddGadgetColumn(0,1,"Column B",100)
AddGadgetItem(0,-1,"Test 1" + Chr(10) + "Test 2")
AddGadgetItem(0,-1,"Test 3" + Chr(10) + "Test 4")
class_addMethod_(delegateClass,sel_registerName_("tableView:willDisplayCell:forTableColumn:row:"),@CellDisplayCallback(),"v@:@@@@")
CocoaMessage(0,GadgetID(0),"setDelegate:",appDelegate)
LoadImage(0, #PB_Compiler_Home+"Examples/Sources/Data/File.bmp")
SetGadgetItemImage(0, 0, ImageID(0))
Repeat
Define Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
Debug "Gadget"
If EventType() = #PB_EventType_Change
Debug "Changed"
EndIf
EndSelect
Case #PB_Event_CloseWindow
Break
EndSelect
ForEver
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Nov 17, 2022 6:24 pm
by mk-soft
The gadget no longer works as it did before. The delegate of gadget can no longer be redirected and there is no column for the image.
PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Thu Nov 17, 2022 7:46 pm
by Lebostein
mk-soft wrote: Thu Nov 17, 2022 6:24 pm
The gadget no longer works as it did before. The delegate of gadget can no longer be redirected and there is no column for the image.
PB now also uses the class PBIconTextCell for the ListIconGadget. Search for it in the forum
Yes, I know. My question was referred to the code that
deseven suggested. I wonder why #PB_EventType_Change is not riggered with this code...
Re: Set alignment of ListIconGadget columns in PB 6
Posted: Fri Nov 18, 2022 9:24 am
by mk-soft
Is also destroyed with setDelegate.
I wish for the old ListIconGadget back. This way, all the standard NSTableView functions of Objective-C will work again.
The one size adjustment in the old NSTableView would be:
Code: Select all
CocoaMessage(0, Cell, "_setVerticallyCentered:", #YES)