Hi guys,
Another way to do scrolling and editable table with multiple textEdit as columns. This can be used to synchronize lists.
var _currentCol;
app.SetOnKey( OnKey );
function OnKey(action, keyName, keyCode, mods){
getCurrentLine();
}
function OnStart()
{
var _layTop = app.CreateLayout( "linear", "vCenter, vertical,fillXY" );
var _layControl = app.CreateLayout( "linear", "horizontal" );
var txtText = app.CreateText( 'first - text, second - col, third - row', -1, -1, 'singleLine');
txtText.SetTextSize(14);
txeText = app.CreateTextEdit( 'test', 0.1, -1, 'singleLine');
txeCol = app.CreateTextEdit( '1', 0.1, -1, 'singleLine');
txeRow = app.CreateTextEdit( '1', 0.1, -1, 'singleLine');
var _txeInsert = app.CreateButton( 'Insert');
_txeInsert.SetOnTouch( insertValue );
_layControl.AddChild( txeText );
_layControl.AddChild( txeCol );
_layControl.AddChild( txeRow );
_layControl.AddChild( _txeInsert );
var _lay = app.CreateLayout( "linear", "horizontal" );
var _text = [];
txe0 = app.CreateTextEdit( _text.join( '\n' ), 0.2, -1);
txe0.SetOnChange( changeText );
txe0.SetOnTouch( touch );
txe0.col = 0;
txe1 = app.CreateTextEdit( _text.join( '\n' ), 0.2, -1);
txe1.SetOnChange( changeText );
txe1.SetOnTouch( touch );
txe1.col = 1;
_lay.AddChild( txe0 );
_lay.AddChild( txe1 );
var _scr = app.CreateScroller( 0.4, 0.2);
var _layScr = app.CreateLayout( 'linear');
_layScr.AddChild( _lay )
_scr.AddChild( _layScr );
_layTop.AddChild( txtText );
_layTop.AddChild( _layControl );
_layTop.AddChild( _scr );
setRowCount( 20 );
app.AddLayout( _layTop );
}
function setText( p_text, p_col, p_row ){
try{
if(( p_row < 0) || ( p_row > 19 )){
throw true;
}
var _rows = window[ 'txe' + p_col ].GetText().split( '\n' );
var _length = p_text.length;
var _start = 0;
for( var _r = 0; _r < p_row; _r++ ){
_start += _rows[ _r ].length + 1;
}
var _end = _start + _rows[ _r ].length;
window[ 'txe' + p_col ].ReplaceText( p_text, _start, _end );
} catch(e) {
app.ShowPopup( 'Enter col from 0 to 1 and row from 0 to 19' );
}
}
function setRowCount( p_rowCount ){
var _text = '';
for( var _row = 0; _row <= p_rowCount; _row++ ){
_text += _row + '\n' ;
}
_text = _text.slice( 0, -1);
txe0.SetText( _text );
txe1.SetText( _text );
}
function changeText(){
var _line = this.GetCursorLine();
var _spl = this.GetText().split( '\n' );
var _text = _spl[ _line ];
//app.ShowPopup( _text );//var _lengthText = _text.length;
//txe2.SetSelection( 0, 3);
}
function getCurrentLine(){
try{
var _col = _currentCol;
var _row = window[ 'txe' + _currentCol ].GetCursorLine();
txeCol.SetText( _col );
txeRow.SetText( _row );
app.ShowPopup( 'col - ' + _col + ', row - ' + _row );
}
catch(e){}
}
function insertValue(){
var _text = txeText.GetText();
var _col = txeCol.GetText();
var _row = txeRow.GetText();
setText( _text, _col, _row );
}
function touch(){
_currentCol = this.col;
getCurrentLine();
}