dgui: allow setting DirectEntryScroll entry after the fact

Closes #702
This commit is contained in:
fireclawthefox 2019-08-14 13:23:48 +02:00 committed by rdb
parent ff188c1dca
commit 24d48d8cb0

View File

@ -29,19 +29,41 @@ class DirectEntryScroll(DirectFrame):
# frameSize = (-0.006, 3.2, -0.015, 0.036),
# if you need to scale the entry scale it's parent instead
self.entry = entry
self.canvas = NodePath(self.guiItem.getCanvasNode())
self.entry.reparentTo(self.canvas)
self.canvas.setPos(0,0,0)
self.entry.bind(DGG.CURSORMOVE,self.cursorMove)
self.entry = None
if entry is not None:
self.entry = entry
self.entry.reparentTo(self.canvas)
self.entry.bind(DGG.CURSORMOVE, self.cursorMove)
self.canvas.node().setBounds(OmniBoundingVolume())
self.canvas.node().setFinal(1)
self.resetCanvas()
def setEntry(self, entry):
"""
Sets a DirectEntry element for this scroll frame. A DirectEntryScroll
can only hold one entry at a time, so make sure to not call this
function twice or call clearEntry before to make sure no entry
is already set.
"""
assert self.entry is None, "An entry was already set for this DirectEntryScroll element"
self.entry = entry
self.entry.reparentTo(self.canvas)
self.entry.bind(DGG.CURSORMOVE, self.cursorMove)
def clearEntry(self):
"""
detaches and unbinds the entry from the scroll frame and its
events. You'll be responsible for destroying it.
"""
if self.entry is None: return
self.entry.unbind(DGG.CURSORMOVE)
self.entry.detachNode()
self.entry = None
def cursorMove(self, cursorX, cursorY):
cursorX = self.entry.guiItem.getCursorX() * self.entry['text_scale'][0]