Rework sliders once again

This commit is contained in:
DarkPhoenix
2018-12-13 19:37:50 +03:00
parent ae23fba6b7
commit 080d94e299
2 changed files with 15 additions and 24 deletions

View File

@@ -60,20 +60,6 @@ class AttributeSlider(wx.Panel):
self.inverse = inverse
# The internal slider basically represents the percentage towards the end of the range. It has to be normalized
# in this way, otherwise when we start off with a base, if the range is skewed to one side, the base value won't
# be centered. We use a range of -100,100 so that we can depend on the SliderValue to contain the percentage
# toward one end
# Additionally, since we want the slider to be accurate to 3 decimal places, we need to blow out the two ends here
# (if we have a slider that needs to land on 66.66% towards the right, it will actually be converted to 66%. Se we need it to support 6,666)
#
# self.SliderMinValue = -100
# self.SliderMaxValue = 100
# self.SliderValue = 0
range = [self.UserMinValue, self.UserMaxValue]
def getStep(valRange):
"""
Find step for the passed range, which is based on 1, 2 or 5.
@@ -86,9 +72,14 @@ class AttributeSlider(wx.Panel):
incScale = math.floor(math.log10(baseIncAmount) - 1)
steps[baseInc] = baseInc * 10 ** incScale
chosenBase = min(steps, key=lambda base: valRange / steps[base])
return steps[chosenBase]
chosenStep = steps[chosenBase]
if inverse:
chosenStep *= -1
return chosenStep
self.ctrl = wx.SpinCtrlDouble(self, min=min(range), max=max(range), inc=getStep(max(range) - min(range)))
self.ctrl = wx.SpinCtrlDouble(
self, min=self.UserMinValue, max=self.UserMaxValue,
inc=getStep(self.UserMaxValue - self.UserMinValue))
self.ctrl.SetDigits(3)

View File

@@ -60,17 +60,17 @@ class ItemMutator(wx.Panel):
headingSizer.Add(displayName, 3, wx.ALL | wx.EXPAND, 0)
leftVal = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(displayMinRange[0]), rounding='dec')
leftText = wx.StaticText(self, wx.ID_ANY, leftVal)
leftText.SetForegroundColour(self.goodColor if displayMinRange is betterRange else self.badColor)
worseVal = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(worseRange[0]), rounding='dec')
worseText = wx.StaticText(self, wx.ID_ANY, worseVal)
worseText.SetForegroundColour(self.badColor)
rightVal = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(displayMaxRange[0]), rounding='dec')
rightText = wx.StaticText(self, wx.ID_ANY, rightVal)
rightText.SetForegroundColour(self.goodColor if displayMaxRange is betterRange else self.badColor)
betterVal = ItemParams.FormatValue(*m.attribute.unit.PreformatValue(betterRange[0]), rounding='dec')
betterText = wx.StaticText(self, wx.ID_ANY, betterVal)
betterText.SetForegroundColour(self.goodColor)
headingSizer.Add(leftText, 0, wx.ALL | wx.EXPAND, 0)
headingSizer.Add(worseText, 0, wx.ALL | wx.EXPAND, 0)
headingSizer.Add(wx.StaticText(self, wx.ID_ANY, ""), 0, wx.RIGHT | wx.LEFT | wx.EXPAND, 5)
headingSizer.Add(rightText, 0, wx.RIGHT | wx.EXPAND, 10)
headingSizer.Add(betterText, 0, wx.RIGHT | wx.EXPAND, 10)
mainSizer.Add(headingSizer, 0, wx.ALL | wx.EXPAND, 5)