NSCollectionViewMBS - not redrawing consistently

I am trying to use the NSCollectionViewMBS to display a series of containerControls including canvases and other controls. I have added a simple routine (below) to the Examples (NS CollectionView Test) to allow changes to the size of each collectionControl. However it does not seem to re-draw the containerControls consistently.

I believe the differences are categorised thus:

  1. items that are visible are re-drawn correctly.
  2. items that within the controls buffer, but not visible, are not redrawn. Scrolling the control to see these items does not refresh them.
  3. items that are outside the buffer and need to be reloaded, are drawn correctly.

An example image here, the checkboxes and item numbers should be shown on all items.

This is the routine I added to handle the changes of size. I’ve tried various combinations of Refresh or Invalidates but none seem to get there.

Private Sub on_sizeChanged()
  Dim v As NSCollectionViewFlowLayoutMBS = NSCollectionViewFlowLayoutMBS(collectionView.collectionViewLayout)
  v.itemSize = New NSSizeMBS(size, size)
  //in-view items need to be resized
  For Each item As CollectionViewItem In items
    If item.ImageContainer <> Nil Then
      item.ImageContainer.width = size
      item.ImageContainer.height = size
      Dim n As NSViewMBS = item.ImageContainer.NSViewMBS
      n.frame = New NSRectMBS(0, 0, size, size)
    End If
  Next item
  //force a reload
End Sub

I also noticed redraw issues with NSCollectionViewMBS. It may be a MBS implementation issue because I do not see this in one of my apps created in Xcode.

Try resizing the window. If that resolves the problem you could force it to resize +1 and -1

Tks. Yes I tried the +/- 1 approach but unfortunately it seems to only refresh visible items - those out of range and scrolled in later seem to remain un-redrawn.

I think Christian needs to take a look at this. If you can provide him a simple example that shows the problem … he may find a solution.

May this be solved if you put some code into willDisplayItem event?

Sub willDisplayItem(item as NSCollectionViewItemMBS, indexPath as NSIndexPathMBS) Handles willDisplayItem
  // item will show soon. Prepare for drawing soon
  System.DebugLog CurrentMethodName + " "+ Str(item.Handle)
  Dim titem As CollectionViewItem = items(indexPath.item)
  // reassign width to have Xojo layout container
  titem.ImageContainer.width = titem.ImageContainer.width
End Sub

For me it seems to help a lot.

Unfortunately not for me - though it seems like a logical place to resolve the problem.
I’ve also tried invalidate and forced-refresh refresh(0,0,w,w,true) in that event and other locations.

I’ve also tried programmatically changing the width +/- 1 of both the imageController and the window but that doesn’t seem to work consistently either.

Curiously the paint event for the imageController correctly draws the outline of that controller. But the position and size of the controls within the imageController often don’t get aligned properly.