Hi,
I’m trying to do a simple GUI, just for study, but I got a problem that I can’t solve. Suppose that I have a simple menu(DirectScrolledList) with some buttons there, but I want show this menu at right side of the window. I did that, but when I resize window I got some problems, so I tried create a update function, check the size of the window and set it to repositioning the menu to the right side of the window, following the simple rule if pos=(1.8, 0, 0) and my initial window has size x=1000 and y=750, so the new position will be = (1.8*width of the window)/1000, but simple ideas usually fails, and in this situation its not different.
Following my code
from direct.gui.DirectGui import *
from direct.showbase.ShowBase import ShowBase
from panda3d.core import WindowProperties
class Game(ShowBase):
def init(self):
ShowBase.init(self)
properties = WindowProperties()
properties.setSize(1000, 750)
self.win.requestProperties(properties)
numItemsVisible = 4
itemHeight = 0.11
self.myScrolledList = DirectScrolledList(
decButton_pos=(-0.7, 0, 0.95),
decButton_text="Up",
decButton_text_scale=0.04,
decButton_borderWidth=(0.005, 0.005),
incButton_pos=(-0.7, 0, -0.95),
incButton_text="Down",
pos=(1.8, 0, 0),
incButton_text_scale=0.04,
incButton_borderWidth=(0.005, 0.005),
numItemsVisible=numItemsVisible,
forceHeight=itemHeight,
itemFrame_pos=(-0.8, 0, 0.4),
)
for cont in range(50):
b = DirectButton(text=("Button {}".format(cont)),
text_scale=0.1, borderWidth=(0.01, 0.01),
command=self.click,
relief=4)
self.myScrolledList.addItem(b)
self.updateTask = taskMgr.add(self.update, "update")
def click(self):
self.myScrolledList.resetFrameSize()
print(self.win.properties.size)
def update(self, task):
x, y = self.win.properties.size
self.myScrolledList.setPos((x*1.8/1000), 0, 0)
return task.cont
game = Game()
game.run()
I tried to fin more information about positioning elements in window in documentation, but didn’t find it.
if some one could help me it’ll be appreciated