again with DirectScrolledFrame - textnode placement

sry for bother again with these simple things.
I’m going to enrich my DSF with blocks of text and, as suggested somewhere I’d used textnodes and after playing a little more I’m closer to what I want to achieve but one thing bother me: why placing in 0,0,0 the textnode this is cutted out on top? I ain’t found any convincing and logical reason so this is why I ask you.
This is my script:

'''
A DirectScrolledFrame is created and placed in the center and a texnode is parented to the canvas and wrapped to the frame width. (actually it is clipped to the right by the scrollbar but never mind that)
'''
import direct.directbase.DirectStart
from direct.gui.DirectGui import *
import direct.gui.DirectGuiGlobals as DGG
from pandac.PandaModules import *
#-------
dsfsize=(1,1)
bgcol=(.2, .2, .2, .5)
scrollbarw=0.05
borderw=(0.01,0.01)
#-------
class textb(TextNode):
  def __init__(self, text='', parent=base.a2dTopLeft, wordwrap=0, pos=(0,0,0)):
    TextNode.__init__(self, 'textblock')
    self.NP=parent.attachNewNode(self)
    self.NP.setScale(0.05)
    self.NP.setPos(*pos)
    self.setText(text)
    self.setWordwrap(wordwrap/self.NP.getScale()[0])
    self.NP.reparentTo(parent)
    
#-------
def mkdsf(parent):
  return DirectScrolledFrame(
    parent=parent,
    frameSize=(0, dsfsize[0], -dsfsize[1], 0),
    canvasSize=(0, dsfsize[0]-borderw[0]-scrollbarw, -5., 0),
    borderWidth=borderw,
    scrollBarWidth=scrollbarw,
    scale=1,
  )
#-------
if __name__ == '__main__':
  dsf1=mkdsf(base.aspect2d)
  dsf1.setPos(-dsf1.getWidth()*.5,0,dsf1.getWidth()*.5)
  t='''1.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.
2.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.
3.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.
4.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.
5.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.
6.Lorem ipse ludorum ipse et pitindirum forte plus et ipse lorum ipse.'''
  tp=(0,0,0)
  ww=dsfsize[0]
  t1=textb(text=t, parent=dsf1.getCanvas(), pos=tp, wordwrap=ww)
  
  run()

Because of your canvasSize parameter:

canvasSize=(0, dsfsize[0]-borderw[0]-scrollbarw, -5., 0)

The last parameter, 0, specifies the Z value of the top of the frame. So when you place your text at Z = 0, you are placing it at the very top of the frame.

The origin of a text node is on the baseline of the top line, not the top-left corner of the text. This is by design; it allows you to line up text fonts of different sizes easily. Placing the text at (0, 0, 0) is placing the baseline at the very top of the frame.

david

Since v1.5.3, ScissorAttrib is applied to the canvas, instead of using 4 clip planes. While using clip planes, you can set it off at canvas’ decendants level, but not ScissorAttrib.

So, if the text isn’t supposed to scroll with the canvas, just attach it directly to the DSF, not the canvas.

thank you David and ynjh_jo.

David I had that suspect but anyway this should be managed by the DSF code, at least I supposed this. Hope to not offend anybody but I’m beginning to think that the entire direct gui needs a big check-up because of the many inconsitencies.

ynjh_jo, I’m apologise to often not getting 100% what you tellme, is not your fault or a matter of language but is your being far beyond my P3D knowledge. :slight_smile:
I supposed to need a canvas to scroll a text bigger than the hosting frame of the DSF so I really can’t get what you mean, sorry. Beyond this, I’ll need to drag around the screen the DSF (no fixed position) but I’m not sure that is on the spot on what you wrote.

No offense taken, of course. There are many who have proposed a replacement for DirectGui, and a couple (including ynjh_jo) who have provided one.

The DirectScrolledFrame is not a packer, such as you find in some other 2-D toolkits. It knows nothing about the contents you are adding to the canvas, and it requires you to tell it accurately what size and dimensions canvas you require.

David

David, I aint found the ynjh_jo stuff, unless you’re referring to something into his outstanding IDE but I’d found this from treeform that is pretty amazing and got many of the features I need. I guess I’ll re-start from that unless there already is a well defined mainstream in the community otherwise oriented.