In short, do we have a simple way to apply a “strikethrough” property to text?
From what I see, TextProperties only supports those features available within TextNode, and TextNode supports properties like italics (via a “slant” value), small-caps, and more–but not strikethrough.
As such, my current thought is to emulate it via a second layer of text that contains only hyphen characters–but I wanted to check whether they wasn’t some better way.
One way would be to use the underscore property and set its height higher.
Quick example:
#!/usr/bin/env python3
from direct.showbase.ShowBase import ShowBase
from panda3d.core import TextProperties, TextPropertiesManager
from direct.gui.DirectGui import DirectLabel
base = ShowBase()
tpStrike = TextProperties()
tpStrike.setUnderscore(True)
tpStrike.setUnderscoreHeight(0.22)
tpMgr = TextPropertiesManager.getGlobalPtr()
tpMgr.setProperties("strike", tpStrike)
text = DirectLabel(text="", text_scale=0.1)
text.setText("Do \1strike\1not\2 show this")
base.run()
The line is always relatively thin tough and I haven’t fond a way to make it thicker, so if you’re looking for a more customizable way, you may have to create your own implementation. You can of course take a look at the draw_underscore function of textAssembler.cxx for some inspiration how it’s done there.
Oh, interesting! I didn’t think to look for a way to shift the underscore! Thank you for pointing that out!
Hmm… I think that I probably will want something less thin, so for my current purposes at least I’ll probably stick to an overlaid DirectLabel. (Although I’m finding hyphens and em-dashes to be unreliable, so I’ll probably end up using a simple image.)
However, what you posted is just what I was asking for: a simpler means of doing the job, at the least for general purposes!
It sounds like a reasonable feature to request, and probably would mostly involve duplicating the underscore code. Asking for a way to control underscore thickness also sounds reasonable, but you could try and see if setRenderModeThickness(2.0) already does the job.
I may well give that a shot! I intend to change what I currently have anyway. (I haven’t yet implemented the image-based approach mentioned above, and the current em-dash-based approach isn’t satisfactory.) As such, I might as well try the underscore-based approach, in case “setRenderModeThickness” just works!
[edit] Just a quick note to add that “setRenderModeThickness” does indeed work with wolf’s technique to create a thicker strikethrough effect!
For my purposes I think that I may still go with a second label, so that I have a little more control over the look of the thing, but it’s good to know that this works!