This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:extra_keys [2014/09/21 10:19] 81.174.242.106 created |
sample_code:extra_keys [2014/12/07 04:56] (current) |
||
---|---|---|---|
Line 8: | Line 8: | ||
var gEdt; | var gEdt; | ||
//Called when application is started. | //Called when application is started. | ||
- | function OnStart(){ | + | function OnStart() |
- | //Create a layout with objects vertically centered. | + | { |
- | lay = app.CreateLayout( " | + | //Create a layout with objects vertically centered. |
+ | lay = app.CreateLayout(" | ||
- | | + | |
- | edt = app.CreateTextEdit( " | + | edt = app.CreateTextEdit(" |
- | edt.SetTextSize( 32 ); | + | edt.SetTextSize(32); |
- | lay.AddChild( edt ); | + | lay.AddChild(edt); |
- | //Create a checkbox for overstrike mode | + | //Create a checkbox for overstrike mode |
- | chkOvertype = app.CreateCheckBox(" | + | chkOvertype = app.CreateCheckBox(" |
- | lay.AddChild(chkOvertype); | + | lay.AddChild(chkOvertype); |
- | //create a horizontal layout for special characters | + | //create a horizontal layout for special characters |
- | lay_keys = app.CreateLayout(" | + | lay_keys = app.CreateLayout(" |
- | btns = [] | + | btns = [] |
- | var ks = ' | + | var ks = ' |
- | for(i=0; i< | + | for (i = 0; i < ks.length; i++) |
- | var ch = ks.charAt(i); | + | |
- | btn = app.CreateButton(ch); | + | var ch = ks.charAt(i); |
- | btn.SetOnTouch(btn_OnTouch); | + | btn = app.CreateButton(ch); |
- | lay_keys.AddChild(btn); | + | btn.SetOnTouch(btn_OnTouch); |
- | btns.push(btn); | + | lay_keys.AddChild(btn); |
- | } | + | btns.push(btn); |
- | lay.AddChild(lay_keys); | + | } |
- | + | lay.AddChild(lay_keys); | |
- | //Add layout to app. | + | |
- | app.AddLayout( lay ); | + | //Add layout to app. |
- | gEdt = edt; | + | app.AddLayout(lay); |
+ | gEdt = edt; | ||
} | } | ||
- | function btn_OnTouch(){ | + | function btn_OnTouch() |
- | var s = this.GetText(); | + | { |
- | var pos = gEdt.GetCursorPos(); | + | var s = this.GetText(); |
- | var theEnd = gEdt.GetText().length; | + | var pos = gEdt.GetCursorPos(); |
- | if(! chkOvertype.GetChecked()){ | + | var theEnd = gEdt.GetText().length; |
- | gEdt.InsertText(s, | + | if (!chkOvertype.GetChecked()) |
- | } else{ | + | |
- | gEdt.ReplaceText(s, | + | gEdt.InsertText(s, |
- | gEdt.SetCursorPos(pos + s.length); | + | } |
- | } | + | |
+ | | ||
+ | gEdt.ReplaceText(s, | ||
+ | gEdt.SetCursorPos(pos + s.length); | ||
+ | } | ||
} | } | ||
</ | </ |