Image in listbox is offset

Does anyone have any idea why my image is offset to the left?

The code to add the image is:

listDrives.RowImageAt(listDrives.RowCount - 1) = volCDDVD

I have tried changing column widths to no avail. The image is too far to the left, and short of adding more padding into the bitmap file (add more whitespace on the left and make the image wider) I can’t work out how to solve this!

i’ve tested this further.

the image file is 128 x 128 pixels, with my image centred in the middle of this and surrounded by a white area. as shown above.

if i shift the black part of image to the right of the overall white image, then it shows up better when drawn with Xojo

column widths make no difference.

I am coding on Linux if that is relevant, cannot test on other platforms.

Why don’t you use the PaintCellText event to do that? Add a ref to the image to your CellTagAt (row, col). Then you can use g.DrawPicture to place it precisely where you want it. My code looks similar to this:

Var  mrd As mailrowData, statPict As Picture, offset As Double

if  (column=0)  then
    
  select case me.CellTagAt(row, 0)
      
  case app.STAT_UNREAD
      statPict = msunread
      
  case app.STAT_READ
      statpict = msread
      
...

  end select

end if

offset = ((me.RowHeight - statPict.Height) / 2.0) - 0.5
g.DrawPicture (statPict, 5, offset)

Works a treat.

i was originally doing this, but the simplicity of using a single line within my function rather than the event was too compelling!

If you create a sample project and upload the zip here, I can run it on mac and see if there are differences.

Would CellAlignment help in this case?
documentation.xojo.com/api/user_interface/desktop/desktoplistbox

Same happens on mac.

No help. Still to the left even if Alignment is center (see 2 below the image).

The reason you’re having trouble is that the listbox expects the image to be a similar size to the font size, so if the text is 16pt, I’d say expect the picture needing to be 16-20 pt wide.

If you want total control, use CellBackgroundPaint.

4 Likes

Good advice. I pretty soon discovered that doing this is important.

Or use an emoji (when one is available) as: :dvd:
(I set the Font to Times to get thi emoticon in macOS TextEdit):

Hello
The image needs to be moved to the right.
Image size 100.50
Image position from 50.50
See example

listbox-Picture-set.xojo_binary_project.zip (6.0 KB)

this is all great help, thank you. i hadn’t considered an emoji either, but i’ll take a look at all the posts here as well

If you are lucky enough to get the images you want as emoji.

Question:
we cannot create - yet - our own emojis?

Nowadays one may benefit also using SF Symbols (see App Folder); in fact these symbols automatically understand light/dark appearance-settings (code available in one of Xojo Blogs). Using them myself (also) in Listboxes.

If you mean ‘emojis’ in a technical sense as Unicode emojis then you have to wait for a change in the Unicode standard to incorporate the new emojis, and for Apple, Microsoft etc. to support the new code points with appropriate glyphs.

That is what people say.

I tried tlo use it, but miss instructions howto do that. So I left it to emojis.

Be aware that emoji support varies by OS. Older MacOS and Windows versions may have a smaller emoji set than newer versions, and Windows 7 doesn’t support emojis at all.

Double check that any emojis you use are able to be displayed in your app’s minimum supported OS.

See Unicode/UTF-8-character table for a complete list of Unicode characters. Emoticons (look like emojis to me) appear almost at the bottom of the long popup menu. So for example:

U+1F602 :joy: UTF-8: f0 9f 98 82 FACE WITH TEARS OF JOY

These all appear to be four bytes long.

Also emojis may look slightly different under Windows. For a consistent appearance I would go for pictures instead.

Even the one I showed in my last post renders differently in that post compared to what’s at the website I referenced. Unclear why.