mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
DirectOptionMenu: Fix popup menu reset of the popup marker's pos
Also defines popupMarker_pos and raises an assertion error if #showPopupMenu() is called when no items have been specified. Fixes #636 Closes #637
This commit is contained in:
parent
16c3ca5c87
commit
4d33db2028
@ -22,10 +22,12 @@ class DirectOptionMenu(DirectButton):
|
|||||||
# List of items to display on the popup menu
|
# List of items to display on the popup menu
|
||||||
('items', [], self.setItems),
|
('items', [], self.setItems),
|
||||||
# Initial item to display on menu button
|
# Initial item to display on menu button
|
||||||
# Can be an interger index or the same string as the button
|
# Can be an integer index or the same string as the button
|
||||||
('initialitem', None, DGG.INITOPT),
|
('initialitem', None, DGG.INITOPT),
|
||||||
# Amount of padding to place around popup button indicator
|
# Amount of padding to place around popup button indicator
|
||||||
('popupMarkerBorder', (.1, .1), None),
|
('popupMarkerBorder', (.1, .1), None),
|
||||||
|
# The initial position of the popup marker
|
||||||
|
('popupMarker_pos', (0, 0, 0), None),
|
||||||
# Background color to use to highlight popup menu items
|
# Background color to use to highlight popup menu items
|
||||||
('highlightColor', (.5, .5, .5, 1), None),
|
('highlightColor', (.5, .5, .5, 1), None),
|
||||||
# Extra scale to use on highlight popup menu items
|
# Extra scale to use on highlight popup menu items
|
||||||
@ -42,6 +44,8 @@ class DirectOptionMenu(DirectButton):
|
|||||||
DirectButton.__init__(self, parent)
|
DirectButton.__init__(self, parent)
|
||||||
# Record any user specified frame size
|
# Record any user specified frame size
|
||||||
self.initFrameSize = self['frameSize']
|
self.initFrameSize = self['frameSize']
|
||||||
|
# Record any user specified popup marker position
|
||||||
|
self.initPopupMarkerPos = self['popupMarker_pos']
|
||||||
# Create a small rectangular marker to distinguish this button
|
# Create a small rectangular marker to distinguish this button
|
||||||
# as a popup menu button
|
# as a popup menu button
|
||||||
self.popupMarker = self.createcomponent(
|
self.popupMarker = self.createcomponent(
|
||||||
@ -168,8 +172,13 @@ class DirectOptionMenu(DirectButton):
|
|||||||
else:
|
else:
|
||||||
# Or base it upon largest item
|
# Or base it upon largest item
|
||||||
bounds = [self.minX, self.maxX, self.minZ, self.maxZ]
|
bounds = [self.minX, self.maxX, self.minZ, self.maxZ]
|
||||||
pm.setPos(bounds[1] + pmw/2.0, 0,
|
if self.initPopupMarkerPos:
|
||||||
bounds[2] + (bounds[3] - bounds[2])/2.0)
|
# Use specified position
|
||||||
|
pmPos = list(self.initPopupMarkerPos)
|
||||||
|
else:
|
||||||
|
# Or base the position on the frame size.
|
||||||
|
pmPos = [bounds[1] + pmw/2.0, 0, bounds[2] + (bounds[3] - bounds[2])/2.0]
|
||||||
|
pm.setPos(pmPos[0], pmPos[1], pmPos[2])
|
||||||
# Adjust popup menu button to fit all items (or use user specified
|
# Adjust popup menu button to fit all items (or use user specified
|
||||||
# frame size
|
# frame size
|
||||||
bounds[1] += pmw
|
bounds[1] += pmw
|
||||||
@ -184,6 +193,12 @@ class DirectOptionMenu(DirectButton):
|
|||||||
Adjust popup position if default position puts it outside of
|
Adjust popup position if default position puts it outside of
|
||||||
visible screen region
|
visible screen region
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Needed attributes (such as minZ) won't be set unless the user has specified
|
||||||
|
# items to display. Let's assert that we've given items to work with.
|
||||||
|
items = self['items']
|
||||||
|
assert items and len(items) > 0, 'Cannot show an empty popup menu! You must add items!'
|
||||||
|
|
||||||
# Show the menu
|
# Show the menu
|
||||||
self.popupMenu.show()
|
self.popupMenu.show()
|
||||||
# Make sure its at the right scale
|
# Make sure its at the right scale
|
||||||
|
Loading…
x
Reference in New Issue
Block a user