progrium/darwinkit

DarwinKit: Rendering Problem with OutlineView

Opened this issue · 1 comments

Issue Description:
Encountering difficulties while attempting to use OutlineView. The UI rendering for OutlineView is not displaying correctly, despite various attempts.

Problem Details:

  • OutlineView does not render the UI correctly.
  • Customizing the DataSource and Delegate, even when using PTableViewDataSource and PTableViewDelegate, does not resolve the issue.
  • Why is OutlineView's SetDataSource receiving parameter is PTableViewDataSource and SetDelegate receiving parameter is PTableViewDelegate?
  • In contrast, a TableView works as expected.

Expected Outcome:
Expecting the OutlineView to display the UI correctly and function properly with a custom DataSource and Delegate.

Relevant Code:

  • main.go
    package main
    
    import (
        "fmt"
    
        "github.com/progrium/macdriver/macos"
        "github.com/progrium/macdriver/macos/appkit"
        "github.com/progrium/macdriver/macos/coregraphics"
        "github.com/progrium/macdriver/macos/foundation"
        "github.com/progrium/macdriver/objc"
    )
    
    var (
        column1 []foundation.String
        column2 []foundation.String
    )
    
    func init() {
        for i := 65; i < 65+26; i++ {
      	  column1 = append(column1, foundation.String_StringWithString(string(rune(i))))
      	  column2 = append(column2, foundation.String_StringWithString(fmt.Sprintf("%d", i)))
        }
    }
    
    func main() {
        macos.RunApp(func(app appkit.Application, _ *appkit.ApplicationDelegate) {
      	  w := appkit.NewWindowWithContentRectStyleMaskBackingDefer(
      		  foundation.Rect{Size: foundation.Size{Width: 600, Height: 500}},
      		  appkit.ClosableWindowMask|
      			  appkit.TitledWindowMask|
      			  appkit.MiniaturizableWindowMask|
      			  appkit.ResizableWindowMask|
      			  appkit.WindowStyleMaskFullSizeContentView|
      			  appkit.WindowStyleMaskUnifiedTitleAndToolbar,
      		  appkit.BackingStoreBuffered,
      		  false,
      	  )
      	  objc.Retain(&w)
    
      	  table := appkit.SplitViewItem_SplitViewItemWithViewController(getTableViewController())
      	  outline := appkit.SplitViewItem_SplitViewItemWithViewController(getOutlineViewController())
      	  splitter := appkit.NewSplitViewController()
      	  splitter.AddSplitViewItem(table)
      	  splitter.AddSplitViewItem(outline)
    
      	  w.SetTitle("TableView & OutlineView")
      	  w.SetContentMinSize(coregraphics.Size{Width: 600, Height: 500})
      	  w.SetToolbarStyle(appkit.WindowToolbarStyleUnifiedCompact)
      	  w.SetTitlebarAppearsTransparent(false)
      	  w.SetContentViewController(splitter)
      	  w.Center()
      	  w.MakeKeyAndOrderFront(nil)
      	  app.SetActivationPolicy(appkit.ApplicationActivationPolicyRegular)
      	  app.ActivateIgnoringOtherApps(true)
        })
    }
    
    func getRowView(supplier func() string) appkit.TableRowView {
        text := appkit.NewTextField()
        text.SetBordered(false)
        text.SetBezelStyle(appkit.TextFieldSquareBezel)
        text.SetEditable(false)
        text.SetDrawsBackground(false)
        text.SetTranslatesAutoresizingMaskIntoConstraints(false)
        text.SetStringValue(supplier())
    
        rowView := appkit.NewTableRowView()
        rowView.AddSubview(text)
    
        text.LeadingAnchor().ConstraintEqualToAnchor(rowView.LeadingAnchor()).SetActive(true)
        text.TrailingAnchor().ConstraintEqualToAnchor(rowView.TrailingAnchor()).SetActive(true)
        text.CenterYAnchor().ConstraintEqualToAnchor(rowView.CenterYAnchor()).SetActive(true)
        return rowView
    }
    
    func createTableColumn(identifier appkit.UserInterfaceItemIdentifier, title string) appkit.TableColumn {
        column := appkit.NewTableColumn()
        column.SetIdentifier(identifier)
        column.SetTitle(title)
        return column
    }
  • tableview.go
    package main
    
    import (
        "github.com/progrium/macdriver/helper/layout"
        "github.com/progrium/macdriver/macos/appkit"
        "github.com/progrium/macdriver/macos/foundation"
    )
    
    const (
        col1Identifier = appkit.UserInterfaceItemIdentifier("Column1")
        col2Identifier = appkit.UserInterfaceItemIdentifier("Column2")
    )
    
    func getTableViewController() appkit.ViewController {
        tableView := appkit.NewTableView()
        tableView.SetColumnAutoresizingStyle(appkit.TableViewSequentialColumnAutoresizingStyle)
        tableView.SetUsesAlternatingRowBackgroundColors(true)
        tableView.SetStyle(appkit.TableViewStyleAutomatic)
        tableView.SetSelectionHighlightStyle(appkit.TableViewSelectionHighlightStyleRegular)
        tableView.SetUsesSingleLineMode(true)
        tableView.SetAllowsColumnSelection(true)
        tableView.SetAutoresizingMask(appkit.ViewWidthSizable)
        tableView.AddTableColumn(createTableColumn(col1Identifier, "Letter"))
        tableView.AddTableColumn(createTableColumn(col2Identifier, "Code"))
    
        datasource := &TableViewDataSourceDelegate{}
        datasource.SetNumberOfRowsInTableView(func(tableView appkit.TableView) int { return len(column1) })
        tableView.SetDataSource(datasource)
    
        delegate := &appkit.TableViewDelegate{}
        delegate.SetTableViewViewForTableColumnRow(func(_ appkit.TableView, column appkit.TableColumn, row int) appkit.View {
      	  return getRowView(func() string {
      		  if column.Identifier() == col1Identifier {
      			  return column1[row].String()
      		  }
      		  return column2[row].String()
      	  }).View
        })
        tableView.SetDelegate(delegate)
        tableView.SelectRowIndexesByExtendingSelection(foundation.NewIndexSetWithIndex(0), true)
    
        scrollView := appkit.NewScrollView()
        scrollView.SetBorderType(appkit.NoBorder)
        scrollView.SetScrollerKnobStyle(appkit.ScrollerKnobStyleDefault)
        scrollView.SetScrollerStyle(appkit.ScrollerStyleOverlay)
        scrollView.SetFindBarPosition(appkit.ScrollViewFindBarPositionAboveContent)
        scrollView.SetAutohidesScrollers(true)
        scrollView.SetDocumentView(tableView)
        scrollView.SetHasVerticalScroller(true)
    
        layout.SetWidth(scrollView, 300)
        controller := appkit.NewViewController()
        controller.SetView(scrollView)
        return controller
    }
  • datasource.go
    package main
    
    import (
        "github.com/progrium/macdriver/macos/appkit"
        "github.com/progrium/macdriver/macos/foundation"
        "github.com/progrium/macdriver/objc"
    )
    
    type OutlineViewDatasource struct {
        _OutlineViewSortDescriptorsDidChange                   func(outlineView appkit.OutlineView, oldDescriptors []foundation.SortDescriptor)
        _OutlineViewChildOfItem                                func(outlineView appkit.OutlineView, index int, item objc.Object) objc.Object
        _OutlineViewPersistentObjectForItem                    func(outlineView appkit.OutlineView, item objc.Object) objc.Object
        _OutlineViewValidateDropProposedItemProposedChildIndex func(outlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) appkit.DragOperation
        _OutlineViewDraggingSessionWillBeginAtPointForItems    func(outlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, draggedItems []objc.Object)
        _OutlineViewAcceptDropItemChildIndex                   func(outlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) bool
        _OutlineViewDraggingSessionEndedAtPointOperation       func(outlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation)
        _OutlineViewSetObjectValueForTableColumnByItem         func(outlineView appkit.OutlineView, object objc.Object, tableColumn appkit.TableColumn, item objc.Object)
        _OutlineViewPasteboardWriterForItem                    func(outlineView appkit.OutlineView, item objc.Object) appkit.PasteboardWritingObject
        _OutlineViewNumberOfChildrenOfItem                     func(outlineView appkit.OutlineView, item objc.Object) int
        _OutlineViewObjectValueForTableColumnByItem            func(outlineView appkit.OutlineView, tableColumn appkit.TableColumn, item objc.Object) objc.Object
        _OutlineViewUpdateDraggingItemsForDrag                 func(outlineView appkit.OutlineView, draggingInfo appkit.DraggingInfoObject)
        _OutlineViewItemForPersistentObject                    func(outlineView appkit.OutlineView, object objc.Object) objc.Object
        _OutlineViewIsItemExpandable                           func(outlineView appkit.OutlineView, item objc.Object) bool
    }
    
    type TableViewDataSourceDelegate struct {
        _TableViewSetObjectValueForTableColumnRow              func(tableView appkit.TableView, object objc.Object, tableColumn appkit.TableColumn, row int)
        _NumberOfRowsInTableView                               func(tableView appkit.TableView) int
        _TableViewSortDescriptorsDidChange                     func(tableView appkit.TableView, oldDescriptors []foundation.SortDescriptor)
        _TableViewDraggingSessionEndedAtPointOperation         func(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation)
        _TableViewDraggingSessionWillBeginAtPointForRowIndexes func(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, rowIndexes foundation.IndexSet)
        _TableViewAcceptDropRowDropOperation                   func(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) bool
        _TableViewObjectValueForTableColumnRow                 func(tableView appkit.TableView, tableColumn appkit.TableColumn, row int) objc.Object
        _TableViewPasteboardWriterForRow                       func(tableView appkit.TableView, row int) appkit.PasteboardWritingObject
        _TableViewUpdateDraggingItemsForDrag                   func(tableView appkit.TableView, draggingInfo appkit.DraggingInfoObject)
        _TableViewValidateDropProposedRowProposedDropOperation func(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) appkit.DragOperation
    }
    
    func (t *TableViewDataSourceDelegate) TableViewSetObjectValueForTableColumnRow(tableView appkit.TableView, object objc.Object, tableColumn appkit.TableColumn, row int) {
        t._TableViewObjectValueForTableColumnRow(tableView, tableColumn, row)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewSetObjectValueForTableColumnRow() bool {
        if t._TableViewSetObjectValueForTableColumnRow != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewSetObjectValueForTableColumnRow(f func(tableView appkit.TableView, object objc.Object, tableColumn appkit.TableColumn, row int)) {
        t._TableViewSetObjectValueForTableColumnRow = f
    }
    
    func (t *TableViewDataSourceDelegate) NumberOfRowsInTableView(tableView appkit.TableView) int {
        return t._NumberOfRowsInTableView(tableView)
    }
    
    func (t *TableViewDataSourceDelegate) HasNumberOfRowsInTableView() bool {
        if t._NumberOfRowsInTableView != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetNumberOfRowsInTableView(f func(tableView appkit.TableView) int) {
        t._NumberOfRowsInTableView = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewSortDescriptorsDidChange(tableView appkit.TableView, oldDescriptors []foundation.SortDescriptor) {
        t._TableViewSortDescriptorsDidChange(tableView, oldDescriptors)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewSortDescriptorsDidChange() bool {
        if t._TableViewSortDescriptorsDidChange != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewSortDescriptorsDidChange(f func(tableView appkit.TableView, oldDescriptors []foundation.SortDescriptor)) {
        t._TableViewSortDescriptorsDidChange = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewDraggingSessionEndedAtPointOperation(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation) {
        t._TableViewDraggingSessionEndedAtPointOperation(tableView, session, screenPoint, operation)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewDraggingSessionEndedAtPointOperation() bool {
        if t._TableViewDraggingSessionEndedAtPointOperation != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewDraggingSessionEndedAtPointOperation(f func(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation)) {
        t._TableViewDraggingSessionEndedAtPointOperation = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewDraggingSessionWillBeginAtPointForRowIndexes(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, rowIndexes foundation.IndexSet) {
        t._TableViewDraggingSessionWillBeginAtPointForRowIndexes(tableView, session, screenPoint, rowIndexes)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewDraggingSessionWillBeginAtPointForRowIndexes() bool {
        if t._TableViewDraggingSessionWillBeginAtPointForRowIndexes != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewDraggingSessionWillBeginAtPointForRowIndexes(f func(tableView appkit.TableView, session appkit.DraggingSession, screenPoint foundation.Point, rowIndexes foundation.IndexSet)) {
        t._TableViewDraggingSessionWillBeginAtPointForRowIndexes = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewAcceptDropRowDropOperation(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) bool {
        return t._TableViewAcceptDropRowDropOperation(tableView, info, row, dropOperation)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewAcceptDropRowDropOperation() bool {
        if t._TableViewAcceptDropRowDropOperation != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewAcceptDropRowDropOperation(f func(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) bool) {
        t._TableViewAcceptDropRowDropOperation = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewObjectValueForTableColumnRow(tableView appkit.TableView, tableColumn appkit.TableColumn, row int) objc.Object {
        return t._TableViewObjectValueForTableColumnRow(tableView, tableColumn, row)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewObjectValueForTableColumnRow() bool {
        if t._TableViewObjectValueForTableColumnRow != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewObjectValueForTableColumnRow(f func(tableView appkit.TableView, tableColumn appkit.TableColumn, row int) objc.Object) {
        t._TableViewObjectValueForTableColumnRow = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewPasteboardWriterForRow(tableView appkit.TableView, row int) appkit.PasteboardWritingObject {
        return t._TableViewPasteboardWriterForRow(tableView, row)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewPasteboardWriterForRow() bool {
        if t._TableViewPasteboardWriterForRow != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewPasteboardWriterForRow(f func(tableView appkit.TableView, row int) appkit.PasteboardWritingObject) {
        t._TableViewPasteboardWriterForRow = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewUpdateDraggingItemsForDrag(tableView appkit.TableView, draggingInfo appkit.DraggingInfoObject) {
        t._TableViewUpdateDraggingItemsForDrag(tableView, draggingInfo)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewUpdateDraggingItemsForDrag() bool {
        if t._TableViewUpdateDraggingItemsForDrag != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewUpdateDraggingItemsForDrag(f func(tableView appkit.TableView, draggingInfo appkit.DraggingInfoObject)) {
        t._TableViewUpdateDraggingItemsForDrag = f
    }
    
    func (t *TableViewDataSourceDelegate) TableViewValidateDropProposedRowProposedDropOperation(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) appkit.DragOperation {
        return t._TableViewValidateDropProposedRowProposedDropOperation(tableView, info, row, dropOperation)
    }
    
    func (t *TableViewDataSourceDelegate) HasTableViewValidateDropProposedRowProposedDropOperation() bool {
        if t._TableViewValidateDropProposedRowProposedDropOperation != nil {
      	  return true
        }
        return false
    }
    
    func (t *TableViewDataSourceDelegate) SetTableViewValidateDropProposedRowProposedDropOperation(f func(tableView appkit.TableView, info appkit.DraggingInfoObject, row int, dropOperation appkit.TableViewDropOperation) appkit.DragOperation) {
        t._TableViewValidateDropProposedRowProposedDropOperation = f
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewSortDescriptorsDidChange(outlineView appkit.OutlineView, oldDescriptors []foundation.SortDescriptor) {
        datasource._OutlineViewSortDescriptorsDidChange(outlineView, oldDescriptors)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewSortDescriptorsDidChange(f func(foutlineView appkit.OutlineView, oldDescriptors []foundation.SortDescriptor)) {
        datasource._OutlineViewSortDescriptorsDidChange = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewSortDescriptorsDidChange() bool {
        return datasource._OutlineViewSortDescriptorsDidChange != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewChildOfItem(outlineView appkit.OutlineView, index int, item objc.Object) objc.Object {
        return datasource._OutlineViewChildOfItem(outlineView, index, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewChildOfItem(f func(foutlineView appkit.OutlineView, index int, item objc.Object) objc.Object) {
        datasource._OutlineViewChildOfItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewChildOfItem() bool {
        return datasource._OutlineViewChildOfItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewPersistentObjectForItem(outlineView appkit.OutlineView, item objc.Object) objc.Object {
        return datasource._OutlineViewPersistentObjectForItem(outlineView, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewPersistentObjectForItem(f func(foutlineView appkit.OutlineView, item objc.Object) objc.Object) {
        datasource._OutlineViewPersistentObjectForItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewPersistentObjectForItem() bool {
        return datasource._OutlineViewPersistentObjectForItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewValidateDropProposedItemProposedChildIndex(outlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) appkit.DragOperation {
        return datasource._OutlineViewValidateDropProposedItemProposedChildIndex(outlineView, info, item, index)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewValidateDropProposedItemProposedChildIndex(f func(foutlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) appkit.DragOperation) {
        datasource._OutlineViewValidateDropProposedItemProposedChildIndex = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewValidateDropProposedItemProposedChildIndex() bool {
        return datasource._OutlineViewValidateDropProposedItemProposedChildIndex != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewDraggingSessionWillBeginAtPointForItems(outlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, draggedItems []objc.Object) {
        datasource._OutlineViewDraggingSessionWillBeginAtPointForItems(outlineView, session, screenPoint, draggedItems)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewDraggingSessionWillBeginAtPointForItems(f func(foutlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, draggedItems []objc.Object)) {
        datasource._OutlineViewDraggingSessionWillBeginAtPointForItems = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewDraggingSessionWillBeginAtPointForItems() bool {
        return datasource._OutlineViewDraggingSessionWillBeginAtPointForItems != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewAcceptDropItemChildIndex(outlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) bool {
        return datasource._OutlineViewAcceptDropItemChildIndex(outlineView, info, item, index)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewAcceptDropItemChildIndex(f func(foutlineView appkit.OutlineView, info appkit.DraggingInfoObject, item objc.Object, index int) bool) {
        datasource._OutlineViewAcceptDropItemChildIndex = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewAcceptDropItemChildIndex() bool {
        return datasource._OutlineViewAcceptDropItemChildIndex != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewDraggingSessionEndedAtPointOperation(outlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation) {
        datasource._OutlineViewDraggingSessionEndedAtPointOperation(outlineView, session, screenPoint, operation)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewDraggingSessionEndedAtPointOperation(f func(foutlineView appkit.OutlineView, session appkit.DraggingSession, screenPoint foundation.Point, operation appkit.DragOperation)) {
        datasource._OutlineViewDraggingSessionEndedAtPointOperation = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewDraggingSessionEndedAtPointOperation() bool {
        return datasource._OutlineViewDraggingSessionEndedAtPointOperation != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewSetObjectValueForTableColumnByItem(outlineView appkit.OutlineView, object objc.Object, tableColumn appkit.TableColumn, item objc.Object) {
        datasource._OutlineViewSetObjectValueForTableColumnByItem(outlineView, object, tableColumn, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewSetObjectValueForTableColumnByItem(f func(foutlineView appkit.OutlineView, object objc.Object, tableColumn appkit.TableColumn, item objc.Object)) {
        datasource._OutlineViewSetObjectValueForTableColumnByItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewSetObjectValueForTableColumnByItem() bool {
        return datasource._OutlineViewSetObjectValueForTableColumnByItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewPasteboardWriterForItem(outlineView appkit.OutlineView, item objc.Object) appkit.PasteboardWritingObject {
        return datasource._OutlineViewPasteboardWriterForItem(outlineView, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewPasteboardWriterForItem(f func(foutlineView appkit.OutlineView, item objc.Object) appkit.PasteboardWritingObject) {
        datasource._OutlineViewPasteboardWriterForItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewPasteboardWriterForItem() bool {
        return datasource._OutlineViewPasteboardWriterForItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewNumberOfChildrenOfItem(outlineView appkit.OutlineView, item objc.Object) int {
        return datasource._OutlineViewNumberOfChildrenOfItem(outlineView, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewNumberOfChildrenOfItem(f func(foutlineView appkit.OutlineView, item objc.Object) int) {
        datasource._OutlineViewNumberOfChildrenOfItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewNumberOfChildrenOfItem() bool {
        return datasource._OutlineViewNumberOfChildrenOfItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewObjectValueForTableColumnByItem(outlineView appkit.OutlineView, tableColumn appkit.TableColumn, item objc.Object) objc.Object {
        return datasource._OutlineViewObjectValueForTableColumnByItem(outlineView, tableColumn, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewObjectValueForTableColumnByItem(f func(foutlineView appkit.OutlineView, tableColumn appkit.TableColumn, item objc.Object) objc.Object) {
        datasource._OutlineViewObjectValueForTableColumnByItem = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewObjectValueForTableColumnByItem() bool {
        return datasource._OutlineViewObjectValueForTableColumnByItem != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewUpdateDraggingItemsForDrag(outlineView appkit.OutlineView, draggingInfo appkit.DraggingInfoObject) {
        datasource._OutlineViewUpdateDraggingItemsForDrag(outlineView, draggingInfo)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewUpdateDraggingItemsForDrag(f func(foutlineView appkit.OutlineView, draggingInfo appkit.DraggingInfoObject)) {
        datasource._OutlineViewUpdateDraggingItemsForDrag = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewUpdateDraggingItemsForDrag() bool {
        return datasource._OutlineViewUpdateDraggingItemsForDrag != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewItemForPersistentObject(outlineView appkit.OutlineView, object objc.Object) objc.Object {
        return datasource._OutlineViewItemForPersistentObject(outlineView, object)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewItemForPersistentObject(f func(foutlineView appkit.OutlineView, object objc.Object) objc.Object) {
        datasource._OutlineViewItemForPersistentObject = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewItemForPersistentObject() bool {
        return datasource._OutlineViewItemForPersistentObject != nil
    }
    
    // optional
    func (datasource *OutlineViewDatasource) OutlineViewIsItemExpandable(outlineView appkit.OutlineView, item objc.Object) bool {
        return datasource._OutlineViewIsItemExpandable(outlineView, item)
    }
    func (datasource OutlineViewDatasource) SetOutlineViewIsItemExpandable(f func(foutlineView appkit.OutlineView, item objc.Object) bool) {
        datasource._OutlineViewIsItemExpandable = f
    }
    func (datasource *OutlineViewDatasource) HasOutlineViewIsItemExpandable() bool {
        return datasource._OutlineViewIsItemExpandable != nil
    }
  • outlineview.go

    package main
    
    import (
        "github.com/progrium/macdriver/helper/layout"
        "github.com/progrium/macdriver/macos/appkit"
        "github.com/progrium/macdriver/macos/foundation"
        "github.com/progrium/macdriver/objc"
    )
    
    const outlineCellIdentifier = appkit.UserInterfaceItemIdentifier("OutlineCell")
    
    func getOutlineViewController() appkit.ViewController {
        outlineView := appkit.NewOutlineView()
        outlineView.SetColumnAutoresizingStyle(appkit.TableViewSequentialColumnAutoresizingStyle)
        outlineView.SetUsesAlternatingRowBackgroundColors(false)
        outlineView.SetStyle(appkit.TableViewStyleSourceList)
        outlineView.SetSelectionHighlightStyle(appkit.TableViewSelectionHighlightStyleSourceList)
        outlineView.SetUsesSingleLineMode(true)
        outlineView.SetAllowsColumnSelection(true)
        outlineView.SetAutoresizingMask(appkit.ViewWidthSizable)
        outlineView.SetHeaderView(nil)
        outlineView.AddTableColumn(createTableColumn(outlineCellIdentifier, ""))
    
        // set delefate start
        delegate := &appkit.OutlineViewDelegate{}
        delegate.SetOutlineViewViewForTableColumnItem(func(_ appkit.OutlineView, tableColumn appkit.TableColumn, item objc.Object) appkit.View {
      	  return getRowView(func() string {
      		  str := foundation.StringFrom(item.Ptr())
      		  return str.String() + " -- outline"
      	  }).View
        })
        po0 := objc.WrapAsProtocol("NSOutlineViewDelegate", appkit.POutlineViewDelegate(delegate))
        objc.SetAssociatedObject(outlineView, objc.AssociationKey("setDelegate"), po0, objc.ASSOCIATION_RETAIN)
        objc.Call[objc.Void](outlineView, objc.Sel("setDelegate:"), po0)
        // set delegate ended
    
        // set datasource start
        datasource := &OutlineViewDatasource{}
        datasource.SetOutlineViewChildOfItem(func(foutlineView appkit.OutlineView, index int, item objc.Object) objc.Object {
      	  return column1[index].Object
        })
        datasource.SetOutlineViewIsItemExpandable(func(foutlineView appkit.OutlineView, item objc.Object) bool {
      	  return false
        })
        datasource.SetOutlineViewNumberOfChildrenOfItem(func(_ appkit.OutlineView, item objc.Object) int {
      	  return len(column1)
        })
        po1 := objc.WrapAsProtocol("NSOutlineViewDataSource", appkit.POutlineViewDataSource(datasource))
        objc.SetAssociatedObject(outlineView, objc.AssociationKey("setDataSource"), po1, objc.ASSOCIATION_RETAIN)
        objc.Call[objc.Void](outlineView, objc.Sel("setDataSource:"), po1)
        // set datasource ended
    
        // Using PTableViewDelegate and PTableViewDataSource still can't display properly
        // datasource := &TableViewDataSourceDelegate{}
        // datasource.SetNumberOfRowsInTableView(func(tableView appkit.TableView) int { return len(column1) })
        // outlineView.SetDataSource(datasource)
        // delegate := &appkit.TableViewDelegate{}
        // delegate.SetTableViewViewForTableColumnRow(func(_ appkit.TableView, column appkit.TableColumn, row int) appkit.View {
        // 	return getRowView(func() string {
        // 		if column.Identifier() == col1Identifier {
        // 			return column1[row].String()
        // 		}
        // 		return column2[row].String()
        // 	}).View
        // })
        // outlineView.SetDelegate(delegate)
        // outlineView.SelectRowIndexesByExtendingSelection(foundation.NewIndexSetWithIndex(0), true)
    
        scrollView := appkit.NewScrollView()
        clipView := appkit.ClipViewFrom(scrollView.ContentView().Ptr())
        clipView.SetDocumentView(outlineView)
        clipView.SetAutomaticallyAdjustsContentInsets(false)
        clipView.SetContentInsets(foundation.EdgeInsets{Top: 10})
    
        scrollView.SetBorderType(appkit.NoBorder)
        scrollView.SetScrollerKnobStyle(appkit.ScrollerKnobStyleDefault)
        scrollView.SetScrollerStyle(appkit.ScrollerStyleOverlay)
        scrollView.SetFindBarPosition(appkit.ScrollViewFindBarPositionAboveContent)
        scrollView.SetDrawsBackground(true)
        scrollView.SetAutohidesScrollers(true)
    
        outlineView.SelectRowIndexesByExtendingSelection(foundation.NewIndexSetWithIndex(0), true)
        scrollView.SetHasVerticalScroller(true)
        scrollView.ContentView().ScrollToPoint(foundation.Point{Y: -10})
        layout.SetWidth(scrollView, 300)
        controller := appkit.NewViewController()
        controller.SetView(scrollView)
        return controller
    }

Environment Information:

  • Operating System: macOS 13.6.1 (22G313)
  • Xcode Version: Version 15.0.1 (15A507)
  • macdriver Version: v0.5.0-preview.0.20231114193140-e468a641af06

Screenshots:
image

Thank you for your time and assistance. Looking forward to resolving this matter.

This is a much more complicated scenario and Apple's APIs can already be tricky. I know it defeats the point, but it would be helpful to me to see a working Objective-C version of this program.