Dreikblack Posted February 9 Share Posted February 9 If i press Tab it will be registered in KeyUp, but not in KeyDown #include "UltraEngine.h" using namespace UltraEngine; class CustomWidget : public Panel { CustomWidget::CustomWidget() { cornerradius = 8; } protected: virtual bool Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) { return Widget::Initialize(text, x, y, width, height, parent, style); } void KeyUp(const KeyCode key) override { if (key == KEY_TAB) Print("TAB UP"); } bool KeyDown(const KeyCode key) override { if (key == KEY_TAB) Print("TAB DOWN"); return true; } public: static shared_ptr<CustomWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) { struct Struct : public CustomWidget { }; auto instance = std::make_shared<Struct>(); instance->Initialize(x, y, width, height, parent); return instance; } }; shared_ptr<Window> window; shared_ptr<Framebuffer> framebuffer; shared_ptr<World> menuWold; shared_ptr<Interface> ui; shared_ptr<Camera> uiCamera; shared_ptr<CustomWidget> customWidget; void initGui() { auto default_font = LoadFont("Fonts\\arial.ttf"); ui = CreateInterface(menuWold, default_font, framebuffer->GetSize()); ui->SetRenderLayers(2); ui->root->SetColor(1.0f, 1.0f, 1.0f, 1.0f); uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC); uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0); uiCamera->SetRenderLayers(2); uiCamera->SetClearMode(CLEAR_DEPTH); customWidget = CustomWidget::create(10, 10, 500, 120, ui->root); } int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window window = CreateWindow("Ultra Engine", 0, 0, 500, 300, displays[0], WINDOW_DEFAULT); //Create a world menuWold = CreateWorld(); //Create a framebuffer framebuffer = CreateFramebuffer(window); initGui(); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { const auto event = WaitEvent(); ui->ProcessEvent(event); menuWold->Update(); menuWold->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Josh Posted February 14 Share Posted February 14 The reason for this is that tab switches the focus to the next widget, but for an editable text area, I can understand why that would not be desired. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Dreikblack Posted February 14 Author Share Posted February 14 I hope it will be available for custom widgets as well Quote Link to comment Share on other sites More sharing options...
Solution Josh Posted February 24 Solution Share Posted February 24 I am adding a protected method to handle this: bool Widget::KeyFilter(const KeyCode key) { switch (key) { case KEY_ESCAPE: case KEY_ENTER: case KEY_TAB: return false; break; } return true; } You can override this to return true if KEY_TAB or KEY_ENTER are encountered. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Dreikblack Posted Saturday at 12:37 PM Author Share Posted Saturday at 12:37 PM Sorry, checked only now. Does not work for me: #include "Leadwerks.h" using namespace UltraEngine; class CustomWidget : public Panel { CustomWidget::CustomWidget() { cornerradius = 8; } protected: virtual bool Initialize(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) { return Widget::Initialize(text, x, y, width, height, parent, style); } void KeyUp(const KeyCode key) override { if (key == KEY_TAB) Print("TAB UP"); } bool KeyDown(const KeyCode key) override { if (key == KEY_TAB) Print("TAB DOWN"); return true; } bool KeyFilter(const KeyCode key) override { switch (key) { case KEY_ESCAPE: case KEY_ENTER: case KEY_TAB: return true; break; } return true; } public: static shared_ptr<CustomWidget> create(const int x, const int y, const int width, const int height, shared_ptr<Widget> parent) { struct Struct : public CustomWidget { }; auto instance = std::make_shared<Struct>(); instance->Initialize(x, y, width, height, parent); return instance; } }; shared_ptr<Window> window; shared_ptr<Framebuffer> framebuffer; shared_ptr<World> menuWold; shared_ptr<Interface> ui; shared_ptr<Camera> uiCamera; shared_ptr<CustomWidget> customWidget; void initGui() { auto default_font = LoadFont("Fonts\\arial.ttf"); uiCamera = CreateCamera(menuWold, PROJECTION_ORTHOGRAPHIC); uiCamera->SetPosition((float)framebuffer->GetSize().x * 0.5f, (float)framebuffer->GetSize().y * 0.5f, 0); uiCamera->SetRenderLayers(2); uiCamera->SetClearMode(CLEAR_DEPTH); ui = CreateInterface(uiCamera, default_font, framebuffer->GetSize()); ui->SetRenderLayers(2); ui->root->SetColor(1.0f, 1.0f, 1.0f, 1.0f); customWidget = CustomWidget::create(10, 10, 500, 120, ui->root); } int main(int argc, const char* argv[]) { //Get the displays auto displays = GetDisplays(); //Create a window window = CreateWindow("Ultra Engine", 0, 0, 500, 300, displays[0], WINDOW_DEFAULT); //Create a world menuWold = CreateWorld(); //Create a framebuffer framebuffer = CreateFramebuffer(window); initGui(); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { const auto event = WaitEvent(); ui->ProcessEvent(event); menuWold->Update(); menuWold->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Dreikblack Posted Saturday at 12:55 PM Author Share Posted Saturday at 12:55 PM Ah, wait. KeyFilter should return false to make it work. Quote Link to comment Share on other sites More sharing options...
Josh Posted Saturday at 04:23 PM Share Posted Saturday at 04:23 PM KeyFilter mus be declared as a virtual method. All your overriding method must be. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Dreikblack Posted Saturday at 04:32 PM Author Share Posted Saturday at 04:32 PM afaik override works same as virtual except it prevents mistakes if base method interface was changed or overriding method have wrong one. Anyway it was about KeyFilter return value which should false to pass key to KeyDown. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.