listbox in a floating window, you can see part of the gear icon duplicated at the top of each cell:
macos sonoma, xojo 25r2.1
listbox in a floating window, you can see part of the gear icon duplicated at the top of each cell:
macos sonoma, xojo 25r2.1
How does it get there?
Do you add a row picture, or do you draw it in the CellBackgroundPaint ?
g.DrawText(t,0,0) in PaintCellText, where t is the gear icon char
The y coordinate is the text baseline so instead of using 0, try using the graphics text ascent property.
Can you create/share a sample project?
i saved the window here:
you can easily adapt it to run in a stripped-down project
The window code isn’t enough to reproduce your problem - nowhere does it show the drawing of a gear emoji. It looks as though it might be getting that gear icon from some other part of your code which isn’t included.
It really would be useful to see how that code is doing that, as I can’t think of any reasonable situation where it could happen.
You do not have Return True in the PaintCellText event.
Meaning you are drawing the gear icon and the framework is also drawing the icon in another position.
That’s why you are seeing a duplicate gear icon:
When I draw text in the PaintCellText event, I usually position like this:
g.DrawText(t, 0, (g.Height-g.TextHeight)/2.0 + g.TextAscent)
Return True
correct, just set t = gear icon
thx for the tip Jeremy. if 2 places are drawing the gear icon, why does one of them look funny shifted up almost out of view? no matter, the tips provided solved the issue. thx all.
Because you were using zero instead of the baseline when drawing the emoji. That put the one you drew off the top of the view.
I believe the frame work provides an x and y coordinate for the drawing position for text in that event. You should use that.
g.DrawText(t,0,-g.FontAscent)
looks as if it wouldnt draw the gear in the visible area at all ..
I might have expected g.FontAscent but not -g.FontAscent
I’m willing to bet that the ‘normal text’ in cell 0 is already the gear emoji as text.
AND you are drawing in the PaintCellText in addition - the extra bit that was visible at the top.
Humour me: completely remove the line g.DrawText(t,0,-g.FontAscent)
and see what happens?
here’s what worked and what didn’t, i guess it makes sense if you understand the mechanism, which i obviously don’t:
’ this works:
g.DrawText(t,0,-g.FontAscent)
return false
’ no chars visible:
g.DrawText(t,0,-g.FontAscent)
return true
’ this works:
return false
This works because your drawing is off the canvas and then the framework draws its own that you’ve assigned to the text in the cell.
This one doesn’t because you’re still drawing off canvas but also preventing the os from drawing
This works because you’re not drawing and returning false which allows the framework to draw the text in the cell
this works:
return false
Exactly.
You had two ways of drawing: you had set the text of cell 0 to be the gear icon, so there is no need to also draw it in the Paint event.
got it. because i also wanted to set the text color depending on the character, i thought i had to paint the color AND the char myself, but evidently not: i can set g.DrawingColor = &cFF260000, return false, and then xojo draws the char in the DrawingColor i set manually. i think i get it now. thx.
And i’m sure there is a good explanation of why a small piece of the gear was drawn at the very top of the cell, now moot.
A small demo of Unicode characters in the listbox
displayed on canvas
without problems
EmojionListbox.xojo_binary_project.zip (12.3 KB)
that is very cool!
In case someone wants to know… the 0,0 point of the canvas when drawing the text is not in the top left corner of the cell. It’s positioned so that the text will appear centered vertically in the row with some padding on the left.