AppKit.NSOutlineView: How to get width of indentation marker(disclosure triangle) area

I'm using NSOutlineView that is view based and is single column.

To calculate each row view height in delegate method, I need to know row view width in column, before drawn.
I think I need to subtract indent width from column width to know row view width.
But I couldn't find how to get width of indentation marker(disclosure triangle) area.
Is there any solution?

Code Block
// MARK: NSOutlineViewDelegate
func outlineView(_ outlineView: NSOutlineView, heightOfRowByItem item: Any) -> CGFloat {
let columnWidth = outlineView.tableColumns.first!.width
let indentationMarkerWidth = CGFloat(17)//<- I want get it dynamically!!
let indentWidth = outlineView.indentationPerLevel * CGFloat(outlineView.level(forItem: item))
let viewWidth = columnWidth - (indentWidth + indentationMarkerWidth)
return calcRowHeightFor(item: item, inViewWidth: viewWidth)//my custom function
}


I need to know row view width in column

I'm not totally sure, but this func should directly return the frame without the disclosure button:
Code Block
func frameOfOutlineCell(atRow row: Int) -> NSRect

Is it what you are looking for ?

If you want the size of disclosure area, you could :
  • loop through all subviews of the NSOutlineView,

  • searching for buttons.

  • Disclosure buttons should be there.

Have a look at this post, which could help find the solution:
https ://www.reddit. com/r/swift/comments/e2xi4n/position_of_a_disclosure_button_inside/
Thanks for reply.

Calling frameOfOutlineCell(atRow:) in outlineView(_:heightOfRowByItem:) caused crash by infinite loop.
I think the function is for row that already displaying.

There are other way to get disclosure triangle area width from row view that already display.
Code Block
override func viewDidAppear() {
super.viewDidAppear()
/* view in column 0,row 0 needs to already displaying. */
if let v = outlineView.view(atColumn: 0, row: 0, makeIfNecessary: false) {
print("disclosure width: \(v.superview!.convert(v.frame, to: outlineView).minX)")
}
}

But I need to get it before display, like indentationPerLevel.

AppKit.NSOutlineView: How to get width of indentation marker(disclosure triangle) area
 
 
Q