import class ListController extends inkLogicController
{
	public import function PushData( value : IScriptable, optional refreshImmediately : Bool );
	public import function PushDataList( value : array< IScriptable >, optional refreshImmediately : Bool );
	public import function Clear( optional refreshImmediately : Bool );
	public import function Refresh();
	public import function Next();
	public import function Prior();
	public import function FindIndex( value : IScriptable ) : Int32;
	public import function HasValidSelection() : Bool;
	public import function GetSelectedIndex() : Int32;
	public import function SetSelectedIndex( index : Int32, optional force : Bool );
	public import function GetToggledIndex() : Int32;
	public import function SetToggledIndex( index : Int32 );
	public import function SetLibraryID( id : CName );
	public import function GetItemAt( index : Int32 ) : weak< inkWidget >;
	public import function Size() : Int32;

	public function HandleInput( e : inkPointerEvent, optional gameCtrl : weak< gameuiMenuGameController > )
	{
		var widgetHStack : inkHorizontalPanel;
		widgetHStack = ( ( inkHorizontalPanel )( GetRootWidget() ) );
		if( widgetHStack )
		{
			if( e.IsAction( 'navigate_left' ) )
			{
				Prior();
				MoveCursorToSelection( gameCtrl );
				e.Handle();
			}
			else if( e.IsAction( 'navigate_right' ) )
			{
				Next();
				MoveCursorToSelection( gameCtrl );
				e.Handle();
			}
		}
		else
		{
			if( e.IsAction( 'navigate_up' ) )
			{
				Prior();
				MoveCursorToSelection( gameCtrl );
				e.Handle();
			}
			else if( e.IsAction( 'navigate_down' ) )
			{
				Next();
				MoveCursorToSelection( gameCtrl );
				e.Handle();
			}
		}
	}

	private function MoveCursorToSelection( gameCtrl : weak< gameuiMenuGameController > )
	{
		var selection : weak< inkWidget >;
		if( gameCtrl )
		{
			selection = GetItemAt( GetSelectedIndex() );
			if( selection )
			{
				gameCtrl.SetCursorOverWidget( selection, 0.0, true );
			}
		}
	}

}

