GWEN improvement: allow to navigate TreeControl and ComboBox using the cursor keys
This commit is contained in:
@@ -12,6 +12,7 @@ class ComboBox : public GUnit
|
||||
|
||||
{
|
||||
Gwen::Controls::ComboBox* combo = new Gwen::Controls::ComboBox( this );
|
||||
combo->SetKeyboardInputEnabled(true);
|
||||
combo->SetPos( 50, 50 );
|
||||
combo->SetWidth( 200 );
|
||||
|
||||
|
||||
@@ -214,12 +214,95 @@ sth_stash* initFont(GLPrimitiveRenderer* primRenderer)
|
||||
return stash;
|
||||
}
|
||||
|
||||
void keyCallback(int key, int value)
|
||||
{
|
||||
printf("key = %d, value = %d\n", key,value);
|
||||
//pCanvas->InputKey(key,value==1);
|
||||
|
||||
|
||||
int gwenKey = -1;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case B3G_LEFT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Left;
|
||||
break;
|
||||
}
|
||||
case B3G_RIGHT_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Right;
|
||||
break;
|
||||
}
|
||||
case B3G_UP_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Up;
|
||||
break;
|
||||
}
|
||||
case B3G_DOWN_ARROW:
|
||||
{
|
||||
gwenKey = Gwen::Key::Down;
|
||||
break;
|
||||
}
|
||||
case B3G_BACKSPACE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Backspace;
|
||||
break;
|
||||
}
|
||||
case B3G_DELETE:
|
||||
{
|
||||
gwenKey = Gwen::Key::Delete;
|
||||
break;
|
||||
}
|
||||
case B3G_HOME:
|
||||
{
|
||||
gwenKey = Gwen::Key::Home;
|
||||
break;
|
||||
}
|
||||
case B3G_END:
|
||||
{
|
||||
gwenKey = Gwen::Key::End;
|
||||
break;
|
||||
}
|
||||
case B3G_SHIFT:
|
||||
{
|
||||
gwenKey = Gwen::Key::Shift;
|
||||
break;
|
||||
}
|
||||
case B3G_CONTROL:
|
||||
{
|
||||
gwenKey = Gwen::Key::Control;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
default:
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
if (gwenKey>=0)
|
||||
{
|
||||
pCanvas->InputKey(gwenKey,value==1);
|
||||
} else
|
||||
{
|
||||
if (key<256 && value)
|
||||
{
|
||||
Gwen::UnicodeChar c = ( Gwen::UnicodeChar ) key;
|
||||
pCanvas->InputCharacter(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
float retinaScale = 1.f;
|
||||
|
||||
b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow();
|
||||
window->setKeyboardCallback(keyCallback);
|
||||
b3gWindowConstructionInfo wci;
|
||||
wci.m_width = sWidth;
|
||||
wci.m_height = sHeight;
|
||||
@@ -241,6 +324,7 @@ int main()
|
||||
gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale);
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Create a GWEN OpenGL Renderer
|
||||
//
|
||||
|
||||
@@ -15,12 +15,17 @@ class TreeControl2 : public GUnit
|
||||
{
|
||||
Gwen::Controls::TreeControl* ctrl = new Gwen::Controls::TreeControl( this );
|
||||
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->AddNode( L"Node One" );
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
pNode->SetSelected(true);
|
||||
|
||||
pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
ctrl->AddNode( L"Node Three" );
|
||||
ctrl->Focus();
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
|
||||
ctrl->SetBounds( 30, 30, 200, 200 );
|
||||
ctrl->ExpandAll();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "UnitTest.h"
|
||||
#include "Gwen/Platform.h"
|
||||
#include "Gwen/Controls/TreeControl.h"
|
||||
|
||||
using namespace Gwen;
|
||||
|
||||
@@ -29,8 +30,81 @@ GWEN_CONTROL_CONSTRUCTOR( UnitTest )
|
||||
|
||||
|
||||
//ADD_UNIT_TEST( MenuStrip );
|
||||
|
||||
Gwen::UnicodeString str1(L"testje");
|
||||
Gwen::Controls::TabButton* tab = m_TabControl->AddPage(str1);
|
||||
|
||||
Gwen::Controls::TreeControl* ctrl=0;
|
||||
|
||||
ADD_UNIT_TEST( TreeControl2 );
|
||||
{
|
||||
ctrl = new Gwen::Controls::TreeControl(tab->GetPage());
|
||||
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
ctrl->AddNode( L"Node One" );
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
|
||||
}
|
||||
{
|
||||
Gwen::Controls::TreeNode* pNode = ctrl->AddNode( L"Node Two" );
|
||||
pNode->AddNode( L"Node Two Inside" );
|
||||
pNode->AddNode( L"Eyes" );
|
||||
pNode->SetSelected(true);
|
||||
|
||||
|
||||
pNode->AddNode( L"Brown" )->AddNode( L"Node Two Inside" )->AddNode( L"Eyes" )->AddNode( L"Brown" );
|
||||
}
|
||||
ctrl->AddNode( L"Node Three" );
|
||||
ctrl->Focus();
|
||||
ctrl->SetKeyboardInputEnabled(true);
|
||||
|
||||
ctrl->SetBounds( 30, 30, 200, 200 );
|
||||
ctrl->ExpandAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
//GUnit* u = new TreeControl2(m_TabControl);..Gwen::Controls::TreeControl2( m_TabControl );
|
||||
//GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab );\
|
||||
//RegisterUnitTest_TreeControl2( m_TabControl )->SetUnitTest( this );
|
||||
|
||||
|
||||
//#define DEFINE_UNIT_TEST( name, displayname )
|
||||
//GUnit* RegisterUnitTest_TreeControl2( Gwen::Controls::TabControl* tab )
|
||||
//{
|
||||
// GUnit* u = new TreeControl2( tab );
|
||||
// tab->AddPage( displayname, u );
|
||||
// return u;
|
||||
//}
|
||||
|
||||
//ADD_UNIT_TEST( TreeControl2 );
|
||||
|
||||
ADD_UNIT_TEST( Properties2 );
|
||||
|
||||
@@ -59,6 +133,7 @@ GWEN_CONTROL_CONSTRUCTOR( UnitTest )
|
||||
ADD_UNIT_TEST( StatusBar );
|
||||
|
||||
|
||||
ctrl->Focus();
|
||||
PrintText( L"Unit Test Started.\n" );
|
||||
|
||||
m_fLastSecond = Gwen::Platform::GetTimeInSeconds();
|
||||
|
||||
Reference in New Issue
Block a user