mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 10:22:45 -04:00
dgui: fix sizing after changing Slider/Scrollbar orientation
Closes #700
This commit is contained in:
parent
50d27166d8
commit
c73415b4ba
@ -88,6 +88,8 @@ class DirectScrollBar(DirectFrame):
|
|||||||
else:
|
else:
|
||||||
self.incButton['frameSize'] = (f[0], f[1], f[2]*0.05, f[3]*0.05)
|
self.incButton['frameSize'] = (f[0], f[1], f[2]*0.05, f[3]*0.05)
|
||||||
|
|
||||||
|
self._lastOrientation = self['orientation']
|
||||||
|
|
||||||
self.guiItem.setThumbButton(self.thumb.guiItem)
|
self.guiItem.setThumbButton(self.thumb.guiItem)
|
||||||
self.guiItem.setLeftButton(self.decButton.guiItem)
|
self.guiItem.setLeftButton(self.decButton.guiItem)
|
||||||
self.guiItem.setRightButton(self.incButton.guiItem)
|
self.guiItem.setRightButton(self.incButton.guiItem)
|
||||||
@ -140,13 +142,38 @@ class DirectScrollBar(DirectFrame):
|
|||||||
|
|
||||||
def setOrientation(self):
|
def setOrientation(self):
|
||||||
if self['orientation'] == DGG.HORIZONTAL:
|
if self['orientation'] == DGG.HORIZONTAL:
|
||||||
|
if self._lastOrientation in (DGG.VERTICAL, DGG.VERTICAL_INVERTED):
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
f = self.decButton['frameSize']
|
||||||
|
self.decButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
|
f = self.incButton['frameSize']
|
||||||
|
self.incButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
self.guiItem.setAxis(Vec3(1, 0, 0))
|
self.guiItem.setAxis(Vec3(1, 0, 0))
|
||||||
elif self['orientation'] == DGG.VERTICAL:
|
elif self['orientation'] == DGG.VERTICAL:
|
||||||
|
if self._lastOrientation == DGG.HORIZONTAL:
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
f = self.decButton['frameSize']
|
||||||
|
self.decButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
|
f = self.incButton['frameSize']
|
||||||
|
self.incButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
self.guiItem.setAxis(Vec3(0, 0, -1))
|
self.guiItem.setAxis(Vec3(0, 0, -1))
|
||||||
elif self['orientation'] == DGG.VERTICAL_INVERTED:
|
elif self['orientation'] == DGG.VERTICAL_INVERTED:
|
||||||
|
if self._lastOrientation == DGG.HORIZONTAL:
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
f = self.decButton['frameSize']
|
||||||
|
self.decButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
|
f = self.incButton['frameSize']
|
||||||
|
self.incButton['frameSize'] = (f[2], f[3], f[0], f[1])
|
||||||
self.guiItem.setAxis(Vec3(0, 0, 1))
|
self.guiItem.setAxis(Vec3(0, 0, 1))
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid value for orientation: %s' % (self['orientation']))
|
raise ValueError('Invalid value for orientation: %s' % (self['orientation']))
|
||||||
|
self._lastOrientation = self['orientation']
|
||||||
|
|
||||||
def setManageButtons(self):
|
def setManageButtons(self):
|
||||||
self.guiItem.setManagePieces(self['manageButtons'])
|
self.guiItem.setManagePieces(self['manageButtons'])
|
||||||
|
@ -41,7 +41,7 @@ class DirectSlider(DirectFrame):
|
|||||||
('extraArgs', [], None),
|
('extraArgs', [], None),
|
||||||
)
|
)
|
||||||
|
|
||||||
if kw.get('orientation') == DGG.VERTICAL:
|
if kw.get('orientation') in (DGG.VERTICAL, DGG.VERTICAL_INVERTED):
|
||||||
# These are the default options for a vertical layout.
|
# These are the default options for a vertical layout.
|
||||||
optiondefs += (
|
optiondefs += (
|
||||||
('frameSize', (-0.08, 0.08, -1, 1), None),
|
('frameSize', (-0.08, 0.08, -1, 1), None),
|
||||||
@ -72,6 +72,8 @@ class DirectSlider(DirectFrame):
|
|||||||
else:
|
else:
|
||||||
self.thumb['frameSize'] = (f[0], f[1], f[2]*0.05, f[3]*0.05)
|
self.thumb['frameSize'] = (f[0], f[1], f[2]*0.05, f[3]*0.05)
|
||||||
|
|
||||||
|
self._lastOrientation = self['orientation']
|
||||||
|
|
||||||
self.guiItem.setThumbButton(self.thumb.guiItem)
|
self.guiItem.setThumbButton(self.thumb.guiItem)
|
||||||
|
|
||||||
# Bind command function
|
# Bind command function
|
||||||
@ -115,11 +117,35 @@ class DirectSlider(DirectFrame):
|
|||||||
|
|
||||||
def setOrientation(self):
|
def setOrientation(self):
|
||||||
if self['orientation'] == DGG.HORIZONTAL:
|
if self['orientation'] == DGG.HORIZONTAL:
|
||||||
|
if self._lastOrientation in (DGG.VERTICAL, DGG.VERTICAL_INVERTED):
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
tf = self.thumb['frameSize']
|
||||||
|
self.thumb['frameSize'] = (tf[2], tf[3], tf[0], tf[1])
|
||||||
self.guiItem.setAxis(Vec3(1, 0, 0))
|
self.guiItem.setAxis(Vec3(1, 0, 0))
|
||||||
|
self['frameVisibleScale'] = (1, 0.25)
|
||||||
elif self['orientation'] == DGG.VERTICAL:
|
elif self['orientation'] == DGG.VERTICAL:
|
||||||
|
if self._lastOrientation == DGG.HORIZONTAL:
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
tf = self.thumb['frameSize']
|
||||||
|
self.thumb['frameSize'] = (tf[2], tf[3], tf[0], tf[1])
|
||||||
self.guiItem.setAxis(Vec3(0, 0, 1))
|
self.guiItem.setAxis(Vec3(0, 0, 1))
|
||||||
|
self['frameVisibleScale'] = (0.25, 1)
|
||||||
|
elif self['orientation'] == DGG.VERTICAL_INVERTED:
|
||||||
|
if self._lastOrientation == DGG.HORIZONTAL:
|
||||||
|
fpre = self['frameSize']
|
||||||
|
# swap frameSize width and height to keep custom frameSizes
|
||||||
|
self['frameSize'] = (fpre[2], fpre[3], fpre[0], fpre[1])
|
||||||
|
tf = self.thumb['frameSize']
|
||||||
|
self.thumb['frameSize'] = (tf[2], tf[3], tf[0], tf[1])
|
||||||
|
self.guiItem.setAxis(Vec3(0, 0, -1))
|
||||||
|
self['frameVisibleScale'] = (0.25, 1)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Invalid value for orientation: %s' % (self['orientation']))
|
raise ValueError('Invalid value for orientation: %s' % (self['orientation']))
|
||||||
|
self._lastOrientation = self['orientation']
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
if (hasattr(self, 'thumb')):
|
if (hasattr(self, 'thumb')):
|
||||||
|
29
tests/gui/test_DirectSlider.py
Normal file
29
tests/gui/test_DirectSlider.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
from direct.gui.DirectSlider import DirectSlider
|
||||||
|
from direct.gui import DirectGuiGlobals as DGG
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def test_slider_orientation():
|
||||||
|
slider = DirectSlider()
|
||||||
|
|
||||||
|
# Horizontal orientation is the default
|
||||||
|
assert slider['orientation'] == DGG.HORIZONTAL
|
||||||
|
assert slider['frameSize'] == (-1, 1, -0.08, 0.08)
|
||||||
|
assert slider['frameVisibleScale'] == (1, 0.25)
|
||||||
|
|
||||||
|
# try change to vertical orientation
|
||||||
|
slider['orientation'] = DGG.VERTICAL
|
||||||
|
assert slider['orientation'] == DGG.VERTICAL
|
||||||
|
assert slider['frameSize'] == (-0.08, 0.08, -1, 1)
|
||||||
|
assert slider['frameVisibleScale'] == (0.25, 1)
|
||||||
|
|
||||||
|
# back to horizontal
|
||||||
|
slider['orientation'] = DGG.HORIZONTAL
|
||||||
|
assert slider['orientation'] == DGG.HORIZONTAL
|
||||||
|
assert slider['frameSize'] == (-1, 1, -0.08, 0.08)
|
||||||
|
assert slider['frameVisibleScale'] == (1, 0.25)
|
||||||
|
|
||||||
|
# finally change to inverted vertical orientation
|
||||||
|
slider['orientation'] = DGG.VERTICAL_INVERTED
|
||||||
|
assert slider['orientation'] == DGG.VERTICAL_INVERTED
|
||||||
|
assert slider['frameSize'] == (-0.08, 0.08, -1, 1)
|
||||||
|
assert slider['frameVisibleScale'] == (0.25, 1)
|
Loading…
x
Reference in New Issue
Block a user