ListIconGadget Row Height

Mac OSX specific forum
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

ListIconGadget Row Height

Post by syntonica »

Is there a way to change this? I don't see anything in the PB docs. I'm using a 12x12 png icon, which is fine, with a 12-point font, but the margins/insets are too big.

Does this gadget map to an NSTableView? Using "setRowSizeStyle:" or "setIntercellSpacing:" doesn't seem to affect it. Once again, the Apple documentation is awful. I can't tell if I need to set it to "custom" somewhere, nor can I find the enum for small, medium, large, etc..

Also, is there a way to center the header cell text? I've tracked it all the way up to NSCell. I got nothing.
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ListIconGadget Row Height

Post by mk-soft »

I'm not at my Mac right now....

Should work like this

Code: Select all

rowHeigth.d = 32.0
CocoaMessage(0,GadgetID(gadget?), "setRowHeight:@", @rowHeigth)
Internally, PB draws the cells using Owner Draw. Unfortunately, this means that some older examples for NSTableView no longer work.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
Shardik
Addict
Addict
Posts: 2079
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ListIconGadget Row Height

Post by Shardik »

syntonica wrote: Also, is there a way to center the header cell text?

Code: Select all

EnableExplicit

Procedure CenterHeaderText(ListIconID.I, ColumnID.I)
  Protected ColumnIDString.S = Str(ColumnID)
  Protected ColumnObject.I
  Protected HeaderCell.I

  ; ----- Get HeaderCell
  CocoaMessage(@ColumnObject, GadgetID(ListIconID),
    "tableColumnWithIdentifier:$", @ColumnIDString)
  HeaderCell = CocoaMessage(0, ColumnObject, "headerCell")

  ; ----- Center text in HeaderCell horizontally
  CocoaMessage(0, HeaderCell, "setAlignment:", #NSCenterTextAlignment)
EndProcedure

OpenWindow(0, 200, 100, 450, 122, "ListIcon Example")
ListIconGadget(0, 10, 10, WindowWidth(0) - 20, WindowHeight(0) - 20,
  "Name", 110, #PB_ListIcon_GridLines)
AddGadgetColumn(0, 1, "Address", 0)
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 Findit" + #LF$ +
  "321 Logo Drive, Mouse House, Downtown")

; ----- Autoadjust width of last column
CocoaMessage(0, GadgetID(0), "sizeLastColumnToFit")

; ----- Center text in header of 2nd column
CenterHeaderText(0, 1)

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
Collection of cross-platform examples with API functions to extend PureBasic
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: ListIconGadget Row Height

Post by syntonica »

mk-soft wrote: Fri Feb 13, 2026 11:44 am I'm not at my Mac right now....

Should work like this

Code: Select all

rowHeigth.d = 32.0
CocoaMessage(0,GadgetID(gadget?), "setRowHeight:@", @rowHeigth)
Internally, PB draws the cells using Owner Draw. Unfortunately, this means that some older examples for NSTableView no longer work.
That worked a treat. Thanks! I would have never gotten the pass-by-reference since a float should be a primative.
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: ListIconGadget Row Height

Post by syntonica »

Thanks, Shardik. That worked as well. This is getting embarrassing. I'm not used to having to ask so many questions. Normally, if I can't figure it out, there's something on StackOverflow that can point me in the right direction.

Also, Is there areference for CocoaMessage beyond what's in the manual?
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ListIconGadget Row Height

Post by mk-soft »

For CocoaMessage -> Objective C, unfortunately you have to search Apple.
Example: https://developer.apple.com/documentati ... guage=objc

The method names are sometimes not entirely correct. Save this as a template.
Link: Dump Object Methods
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
mk-soft
Always Here
Always Here
Posts: 6579
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: ListIconGadget Row Height

Post by mk-soft »

syntonica wrote: Fri Feb 13, 2026 1:38 pm
mk-soft wrote: Fri Feb 13, 2026 11:44 am I'm not at my Mac right now....

Should work like this

Code: Select all

rowHeigth.d = 32.0
CocoaMessage(0,GadgetID(gadget?), "setRowHeight:@", @rowHeigth)
Internally, PB draws the cells using Owner Draw. Unfortunately, this means that some older examples for NSTableView no longer work.
That worked a treat. Thanks! I would have never gotten the pass-by-reference since a float should be a primative.
Since the type of the parameters can vary, a pointer is passed in CocoaMessage. (Integer values can also be passed directly.)
"methode:@", Pointer to Parameter, "methode:$", Pointer to String (inter convert to UTF8)

If the return value is not an integer or object, pass a pointer for the result.

Code: Select all

Global rowHeigth.d ; rowHeigth.CGFLoat

CocoaMessage(@rowHeigth, GadgetID(gadget?), "rowHeight")
Debug rowHeigth

rowHeigth.d = 32.0
CocoaMessage(0,GadgetID(gadget?), "setRowHeight:@", @rowHeigth)
Last edited by mk-soft on Fri Feb 13, 2026 3:10 pm, edited 1 time in total.
My Projects EventDesigner V3 / ThreadToGUI / OOP-BaseClass / Windows: Module ActiveScript
PB v3.30 / v5.75 - OS Mac Mini - VM Window Pro / Linux Ubuntu
Downloads on my OneDrive
User avatar
Shardik
Addict
Addict
Posts: 2079
Joined: Thu Apr 21, 2005 2:38 pm
Location: Germany

Re: ListIconGadget Row Height

Post by Shardik »

mk-soft wrote: rowHeigth.d = 32.0
CocoaMessage(0,GadgetID(gadget?), "setRowHeight:@", @rowHeigth)
RowHeight should be declared as

Code: Select all

  RowHeight.CGFloat

For a complete working example that gets and sets row height using a slider you may take a look into this more than 13 year old example (though you have to change Frame3DGadget() to FrameGadget() before trying).

By the way, when looking for MacOS API functions you should at first take a look into this thread where Wilbert collected a lot of links with API extensions for MacOS. Wilbert's list also contains the posted link above.
Collection of cross-platform examples with API functions to extend PureBasic
User avatar
syntonica
User
User
Posts: 26
Joined: Fri Feb 06, 2026 10:34 pm

Re: ListIconGadget Row Height

Post by syntonica »

Wow, ton of usefil info. Thanks everyone.

I'm beginning to remember this from when I wrote some C code to call out to Cocoa, which I don't recommend to anyone. It seems to me that the float special treatment goes back to changes made when Apple transitioned from PPC->Intel in regards to method return values.
Post Reply