Enhance the SpinBox control.

[GB.GUI.BASE]
* NEW: SpinBox: Alignment is a new property that allows to define the alignment of the control inner text.
* NEW: SpinBox: ShowZero is a new property that tells to pad the displayed number with zeros.
* NEW: SpinBox: Limit is a new event that is raised when the user tries to move past the maximum value, or beofre the minimum value.
* BUG: SpinBox: The value entered with the keyboard is now always taken into account by the next use of the mouse.
This commit is contained in:
gambas 2019-02-02 00:41:36 +01:00
parent c875f00a44
commit f812d81274

View File

@ -4,13 +4,14 @@ Export
Inherits UserControl Inherits UserControl
Public Const _Properties As String = "*,Action,MinValue=0,MaxValue=100,Step=1,Wrap,Value,Border=True" Public Const _Properties As String = "*,Action,MinValue=0,MaxValue=100,Step=1,Wrap,Value,Alignment{Align.Normal;Left;Center;Right}=Normal,Border=True"
Public Const _Group As String = "Form" Public Const _Group As String = "Form"
Public Const _DefaultEvent As String = "Change" Public Const _DefaultEvent As String = "Change"
Public Const _DefaultSize As String = "9,4" Public Const _DefaultSize As String = "9,4"
Public Const _Similar As String = "TextBox,Slider" Public Const _Similar As String = "TextBox,Slider"
Event Change Event Change
Event Limit
Property MinValue As Integer Property MinValue As Integer
Property MaxValue As Integer Property MaxValue As Integer
@ -20,6 +21,8 @@ Property Wrap As Boolean
Property Step As Integer Property Step As Integer
Property Text As String Property Text As String
Property Background As Integer Property Background As Integer
Property Alignment As Integer
Property ShowZero As Boolean
Private Enum ARROW_NONE, ARROW_TOP, ARROW_BOTTOM Private Enum ARROW_NONE, ARROW_TOP, ARROW_BOTTOM
@ -35,6 +38,7 @@ Private $bTimerAdd As Boolean
Private $bBorder As Boolean = True Private $bBorder As Boolean = True
Private $bWrap As Boolean Private $bWrap As Boolean
Private $iStep As Integer = 1 Private $iStep As Integer = 1
Private $bShowZero As Boolean
Public Sub _new() Public Sub _new()
@ -151,7 +155,11 @@ End
Private Sub ChangeValue(bAdd As Boolean, Optional bFocus As Boolean) Private Sub ChangeValue(bAdd As Boolean, Optional bFocus As Boolean)
Dim iValue As Integer
iValue = $iValue
SetValue($iValue + $iStep * If(bAdd, 1, -1), bFocus) SetValue($iValue + $iStep * If(bAdd, 1, -1), bFocus)
If $iValue = iValue Then Raise Limit
End End
@ -160,6 +168,7 @@ Public Sub View_MouseWheel()
If Object.CanRaise(Me, "MouseWheel") Then Return If Object.CanRaise(Me, "MouseWheel") Then Return
CheckValue
ChangeValue(Mouse.Delta > 0, True) ChangeValue(Mouse.Delta > 0, True)
Stop Event Stop Event
@ -174,13 +183,20 @@ End
Private Sub SetValue(iValue As Integer, Optional bFocus As Boolean) Private Sub SetValue(iValue As Integer, Optional bFocus As Boolean)
Dim sValue As String Dim sValue As String
Dim nZero As Integer
If iValue < $iMin Then If iValue < $iMin Then
iValue = If($bWrap, $iMax, $iMin) iValue = If($bWrap, $iMax, $iMin)
Else If iValue > $iMax Then Else If iValue > $iMax Then
iValue = If($bWrap, $iMin, $iMax) iValue = If($bWrap, $iMin, $iMax)
Endif Endif
sValue = CStr(iValue) sValue = CStr(iValue)
If $bShowZero Then
nZero = Max(Len(CStr($iMin)), Len(CStr($iMax)))
If nZero > Len(sValue) Then sValue = String$(nZero - Len(sValue), "0") & sValue
Endif
If $hTextBox.Text <> sValue Then $hTextBox.Text = sValue If $hTextBox.Text <> sValue Then $hTextBox.Text = sValue
If $iValue <> iValue Then If $iValue <> iValue Then
$iValue = iValue $iValue = iValue
@ -294,6 +310,7 @@ Public Sub View_MouseDown()
Return Return
Endif Endif
CheckValue
ChangeValue($bTimerAdd, True) ChangeValue($bTimerAdd, True)
$hTimer = New Timer(500) As "TimerMouse" $hTimer = New Timer(500) As "TimerMouse"
@ -476,3 +493,28 @@ Private Sub Background_Write(Value As Integer)
Endif Endif
End End
Private Function Alignment_Read() As Integer
Return $hTextBox.Alignment
End
Private Sub Alignment_Write(Value As Integer)
$hTextBox.Alignment = Value
End
Private Function ShowZero_Read() As Boolean
Return $bShowZero
End
Private Sub ShowZero_Write(Value As Boolean)
$bShowZero = Value
SetValue($iValue)
End