From 1e7d24fea8ab09a893c7f62e1d88c1c9feca9125 Mon Sep 17 00:00:00 2001 From: Ian C Date: Sat, 24 Sep 2005 11:01:58 +0000 Subject: Added numeric checks to TText --- simplegui.mod/simplegui.bmx | 46 +++++++++++++++++++++++++++++++++++++++++---- 1 file 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=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 -- cgit v1.2.3