summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan C <ianc@noddybox.co.uk>2005-09-24 11:01:58 +0000
committerIan C <ianc@noddybox.co.uk>2005-09-24 11:01:58 +0000
commit1e7d24fea8ab09a893c7f62e1d88c1c9feca9125 (patch)
treea4668448fd559680f1885163af7e456f62338d56
parent911416abf7340e7470f516a38c9089c362e0913f (diff)
Added numeric checks to TText
-rw-r--r--simplegui.mod/simplegui.bmx46
1 files changed, 42 insertions, 4 deletions
diff --git a/simplegui.mod/simplegui.bmx b/simplegui.mod/simplegui.bmx
index 2b348a0..72d79f8 100644
--- a/simplegui.mod/simplegui.bmx
+++ b/simplegui.mod/simplegui.bmx
@@ -218,15 +218,38 @@ Rem
bbdoc: The text entry widget
EndRem
Type TText Extends TWidget
- Field maxlen:Int
+ Field maxlen:Int
+ Field mode:Int
+
+ Rem
+ bbdoc: The text box handles any text
+ EndRem
+ Const NORMAL:Int=0
+
+ Rem
+ bbdoc: The text box handles a number
+ EndRem
+ Const NUMERIC:Int=1
+
+ Rem
+ bbdoc: The text box handles only integer numbers
+ EndRem
+ Const INTEGER:Int=2
+
+ Rem
+ bbdoc: The text box handles only positive numbers
+ EndRem
+ Const POSITIVE:Int=4
+
Rem
bbdoc: Create a TText widget.
returns: The created widget.
about: @gui is the @TGUIHandler object managing this wiget. @x and @y are its position and @text is the initial text in the widget.
- about: @maxlen is the maximum number of characters allowed. @callback is called when RETURN is pressed in the text field.
+ about: @maxlen is the maximum number of characters allowed. @mode defines the valid characters that can be entered.
+ about: @callback is called when RETURN is pressed in the text field.
EndRem
- Function Create:TText(gui:TGUIHandler,x:Int, y:Int, text:String, maxlen:Int, callback(w:TWidget)=Null)
+ Function Create:TText(gui:TGUIHandler,x:Int, y:Int, text:String, maxlen:Int, mode:Int=0, callback(w:TWidget)=Null)
Local o:TText=New TText
o.enabled=True
o.consumes=True
@@ -237,6 +260,7 @@ Type TText Extends TWidget
o.h=TGUIFont.font.MaxHeight()+2
o.text=text
o.callback=callback
+ o.mode=mode
gui.Register(o)
Return o
End Function
@@ -256,7 +280,21 @@ Type TText Extends TWidget
owner.SetFocus(Null)
EndIf
Else If k>31 And k<127 And text.length<maxlen
- text:+Chr(k)
+ If (mode & NUMERIC)
+ If k=Asc("-") And (Not (mode & POSITIVE)) And text.length=0
+ text:+Chr(k)
+ EndIf
+
+ If k>=Asc("0") And k<=Asc("9")
+ text:+Chr(k)
+ EndIf
+
+ If k=Asc(".") And (Not (mode & INTEGER)) And text.Find(".")=-1
+ text:+Chr(k)
+ EndIf
+ Else
+ text:+Chr(k)
+ EndIf
EndIf
End Method