User Tools

Site Tools


sample_code:extra_keys

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:extra_keys [2014/12/06 20:56]
stevegarman change curly brace style
sample_code:extra_keys [2014/12/07 04:56]
Line 1: Line 1:
-====== Extra keys ====== 
-This code snippet offers an extra line of keys to make some extra keys easier to get at. 
  
-It uses new features added in v1.09 beta, so will not work on release version 1.05 
- 
-<code javascript keys.js> 
-//keys.js 
-var gEdt; 
-//Called when application is started. 
-function OnStart() 
-{ 
-  //Create a layout with objects vertically centered. 
-  lay = app.CreateLayout("linear", "Vcenter,FillXY"); 
- 
-  //Create a text edit and add it to layout. 
-  edt = app.CreateTextEdit("Hello"); 
-  edt.SetTextSize(32); 
-  lay.AddChild(edt); 
-  //Create a checkbox for overstrike mode 
-  chkOvertype = app.CreateCheckBox("Overtype"); 
-  lay.AddChild(chkOvertype); 
-  //create a horizontal layout for special characters 
-  lay_keys = app.CreateLayout("linear", "Horizontal,FillY"); 
-  btns = [] 
-  var ks = '{}[]();#"' + "'" 
-  for (i = 0; i < ks.length; i++) 
-  { 
-    var ch = ks.charAt(i); 
-    btn = app.CreateButton(ch); 
-    btn.SetOnTouch(btn_OnTouch); 
-    lay_keys.AddChild(btn); 
-    btns.push(btn); 
-  } 
-  lay.AddChild(lay_keys); 
- 
-  //Add layout to app.     
-  app.AddLayout(lay); 
-  gEdt = edt; 
-} 
- 
-function btn_OnTouch() 
-{ 
-  var s = this.GetText(); 
-  var pos = gEdt.GetCursorPos(); 
-  var theEnd = gEdt.GetText().length; 
-  if (!chkOvertype.GetChecked()) 
-  { 
-    gEdt.InsertText(s, pos); 
-  } 
-  else 
-  { 
-    gEdt.ReplaceText(s, pos, Math.min(pos + s.length, theEnd)); 
-    gEdt.SetCursorPos(pos + s.length); 
-  } 
-} 
-</code> 
sample_code/extra_keys.txt ยท Last modified: 2014/12/07 04:56 (external edit)